Skip to content

Commit

Permalink
chore: remove nanoid as dependency (#5024)
Browse files Browse the repository at this point in the history
* chore: remove nanoid

* add comment
  • Loading branch information
Uzlopak authored Nov 6, 2023
1 parent ee2b70e commit 45e97af
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
15 changes: 12 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
/**
* Module dependencies.
*/

const {nanoid} = require('nanoid/non-secure');
var path = require('path');
var util = require('util');
var he = require('he');
Expand Down Expand Up @@ -615,11 +613,22 @@ exports.constants = exports.defineConstants({
MOCHA_ID_PROP_NAME
});

const uniqueIDBase =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_';

/**
* Creates a new unique identifier
* Does not create cryptographically safe ids.
* Trivial copy of nanoid/non-secure
* @returns {string} Unique identifier
*/
exports.uniqueID = () => nanoid();
exports.uniqueID = () => {
let id = '';
for (let i = 0; i < 21; i++) {
id += uniqueIDBase[(Math.random() * 64) | 0];
}
return id;
};

exports.assignNewMochaID = obj => {
const id = exports.uniqueID();
Expand Down
17 changes: 0 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"log-symbols": "4.1.0",
"minimatch": "5.0.1",
"ms": "2.1.3",
"nanoid": "3.3.3",
"serialize-javascript": "6.0.0",
"strip-json-comments": "3.1.1",
"supports-color": "8.1.1",
Expand Down
3 changes: 3 additions & 0 deletions test/unit/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,5 +760,8 @@ describe('lib/utils', function () {
it('should return a non-empty string', function () {
expect(utils.uniqueID(), 'to be a string').and('not to be empty');
});
it('should have length of 21', function () {
expect(utils.uniqueID().length, 'to equal', 21);
});
});
});

0 comments on commit 45e97af

Please sign in to comment.