@naturalcycles/nodejs-lib
Version:
Standard library for Node.js
29 lines (28 loc) • 1.63 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringIdUnsafe = exports.stringIdAsync = exports.stringId = exports.ALPHABET_ALPHANUMERIC = exports.ALPHABET_ALPHANUMERIC_UPPERCASE = exports.ALPHABET_ALPHANUMERIC_LOWERCASE = exports.ALPHABET_UPPERCASE = exports.ALPHABET_LOWERCASE = exports.ALPHABET_NUMBER = void 0;
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 (0, nanoid_1.customAlphabet)(alphabet, length)();
}
exports.stringId = stringId;
async function stringIdAsync(length = 16, alphabet = exports.ALPHABET_ALPHANUMERIC_LOWERCASE) {
return await (0, async_1.customAlphabet)(alphabet, length)();
}
exports.stringIdAsync = stringIdAsync;
function stringIdUnsafe(length = 16, alphabet = exports.ALPHABET_ALPHANUMERIC_LOWERCASE) {
return (0, non_secure_1.customAlphabet)(alphabet, length)();
}
exports.stringIdUnsafe = stringIdUnsafe;
;