-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into 152-update-dependen…
…cies
- Loading branch information
Showing
1 changed file
with
4 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |