Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 152-update-dependen…
Browse files Browse the repository at this point in the history
…cies
  • Loading branch information
ekdeveloper committed Sep 12, 2024
2 parents a16ae4e + efa47f7 commit 0de274e
Showing 1 changed file with 4 additions and 39 deletions.
43 changes: 4 additions & 39 deletions src/utils/uid.util.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,12 @@
const hash = require('object-hash');
/**
* Return a random int, used by `utils.getUid()`.
*
* @param {Number} min
* @param {Number} max
* @return {Number}
* @api private
*/
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

/**
* Validates the date(s) and return the object containing the prefix and date.
*
* Prefix may contain 'ge, le, lt, gt'.
*
* @param {*} dates
*/
let getUid = function (length) {
let uid = '';
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charsLength = chars.length;

for (let i = 0; i < length; ++i) {
uid += chars[getRandomInt(0, charsLength - 1)];
}

return uid;
};
const { randomUUID } = require('node:crypto');

/**
* Make a hash of the object for use as a UUID.
* TODO Improve this. Stuck this in just because it's more of a uniqueness guarantee than the above 'getUID' function.
* TODO If we're actually going to generate hashes, we should probably do it in a more secure manner.
* @param obj
* @returns {*|*}
* Generates a UUID (aka GUID) represented as a URI (RFC 4122 icon)
*/
const getUuid = (obj) => {
return hash(obj);
let getUuid = function () {
return randomUUID();
};

module.exports = {
getUid,
getUuid,
};

0 comments on commit 0de274e

Please sign in to comment.