@ecomplus/utils
Version:
JS utility functions to E-Com Plus (not only) related apps
30 lines (29 loc) • 837 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
require("core-js/modules/es.object.to-string.js");
require("core-js/modules/es.regexp.to-string.js");
/**
* @method
* @memberof ecomUtils
* @name randomObjectId
* @description Generate a random object id with 24 chars hexadecimal string.
* @returns {string & { length: 24 }}
*
* @example
* ecomUtils.randomObjectId()
* // => '561025156443695764000000'
*/
var randomObjectId = function randomObjectId() {
// generate 24 chars hexadecimal string
// return unique and valid MongoDB ObjectId pattern
var objectId = Math.floor(Math.random() * 1000000).toString() + Date.now();
// pad zeros
while (objectId.length < 24) {
objectId += '0';
}
return objectId;
};
var _default = exports.default = randomObjectId;