@naturalcycles/nodejs-lib
Version:
Standard library for Node.js
28 lines • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const nanoid_1 = require("nanoid");
const async_1 = require("nanoid/async");
const non_secure_1 = require("nanoid/non-secure");
exports.ALPHABET_NUMBER = '0123456789';
exports.ALPHABET_LOWERCASE = 'abcdefghijklmnopqrstuvwxyz';
exports.ALPHABET_UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
exports.ALPHABET_ALPHANUMERIC_LOWERCASE = [exports.ALPHABET_NUMBER, exports.ALPHABET_LOWERCASE].join('');
exports.ALPHABET_ALPHANUMERIC_UPPERCASE = [exports.ALPHABET_NUMBER, exports.ALPHABET_UPPERCASE].join('');
exports.ALPHABET_ALPHANUMERIC = [exports.ALPHABET_NUMBER, exports.ALPHABET_LOWERCASE, exports.ALPHABET_UPPERCASE].join('');
/**
* Generate cryptographically-secure string id.
* Powered by `nanoid`.
*/
function stringId(length = 16, alphabet = exports.ALPHABET_ALPHANUMERIC_LOWERCASE) {
return nanoid_1.customAlphabet(alphabet, length)();
}
exports.stringId = stringId;
async function stringIdAsync(length = 16, alphabet = exports.ALPHABET_ALPHANUMERIC_LOWERCASE) {
return await async_1.customAlphabet(alphabet, length)();
}
exports.stringIdAsync = stringIdAsync;
function stringIdUnsafe(length = 16, alphabet = exports.ALPHABET_ALPHANUMERIC_LOWERCASE) {
return non_secure_1.customAlphabet(alphabet, length)();
}
exports.stringIdUnsafe = stringIdUnsafe;
//# sourceMappingURL=id.util.js.map