UNPKG

cuid

Version:

Collision-resistant ids optimized for horizontal scaling and performance. For node and browsers.

1 lines 2.02 kB
!function(n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).cuid=n()}(function(){return function i(r,o,u){function f(e,n){if(!o[e]){if(!r[e]){var t="function"==typeof require&&require;if(!n&&t)return t(e,!0);if(s)return s(e,!0);throw(n=new Error("Cannot find module '"+e+"'")).code="MODULE_NOT_FOUND",n}t=o[e]={exports:{}},r[e][0].call(t.exports,function(n){return f(r[e][1][n]||n)},t,t.exports,i,r,o,u)}return o[e].exports}for(var s="function"==typeof require&&require,n=0;n<u.length;n++)f(u[n]);return f}({1:[function(n,e,t){var r=n("./lib/fingerprint.js"),i=n("./lib/pad.js"),o=n("./lib/getRandomValue.js"),u=0,f=4,s=36,d=Math.pow(s,f);function a(){return i((o()*d<<0).toString(s),f)}function p(){return u=u<d?u:0,++u-1}function c(){return"c"+(new Date).getTime().toString(s)+i(p().toString(s),f)+r()+(a()+a())}c.slug=function(){var n=(new Date).getTime().toString(36),e=p().toString(36).slice(-4),t=r().slice(0,1)+r().slice(-1),i=a().slice(-2);return n.slice(-2)+e+t+i},c.isCuid=function(n){return"string"==typeof n&&!!n.startsWith("c")},c.isSlug=function(n){return"string"==typeof n&&7<=(n=n.length)&&n<=10},c.fingerprint=r,e.exports=c},{"./lib/fingerprint.js":2,"./lib/getRandomValue.js":3,"./lib/pad.js":4}],2:[function(n,e,t){var n=n("./pad.js"),i="object"==typeof window?window:self,i=Object.keys(i).length,r=n(((navigator.mimeTypes?navigator.mimeTypes.length:0)+navigator.userAgent.length).toString(36)+i.toString(36),4);e.exports=function(){return r}},{"./pad.js":4}],3:[function(n,e,t){var i,r,o="undefined"!=typeof window&&(window.crypto||window.msCrypto)||"undefined"!=typeof self&&self.crypto;r=o?(i=Math.pow(2,32)-1,function(){return Math.abs(o.getRandomValues(new Uint32Array(1))[0]/i)}):Math.random,e.exports=r},{}],4:[function(n,e,t){e.exports=function(n,e){n="000000000"+n;return n.substr(n.length-e)}},{}]},{},[1])(1)});