UNPKG

@ssts/id

Version:

Create unique random string IDs

2 lines (1 loc) 1.63 kB
"use strict";var b=Object.create;var i=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var d=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var h=(e,t)=>{for(var n in t)i(e,n,{get:t[n],enumerable:!0})},w=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of a(t))!p.call(e,r)&&r!==n&&i(e,r,{get:()=>t[r],enumerable:!(o=g(t,r))||o.enumerable});return e};var y=(e,t,n)=>(n=e!=null?b(d(e)):{},w(t||!e||!e.__esModule?i(n,"default",{value:e,enumerable:!0}):n,e)),E=e=>w(i({},"__esModule",{value:!0}),e);var I={};h(I,{default:()=>x});module.exports=E(I);var f=y(require("@ssts/int")),m=new Set,T=(e,t)=>{let n="",o=e.length-1;for(let r=0;r<t;r++)n+=e.charAt((0,f.default)(0,o));return n},l=(e=[8,4,4,4,12],t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")=>{if(Array.isArray(e)){if(e.length===0)throw new RangeError("lengthArray must not be empty");if(e.some(s=>typeof s!="number"))throw new TypeError("All lengthArray items must be numbers");if(e.some(s=>s<1))throw new RangeError("All lengthArray numbers must be greater than 0")}else throw new TypeError("lengthArray must be an array");if(typeof t!="string")throw new TypeError("characters must be a string");if(t.length===0)throw new RangeError("characters must not be empty");e=e.map(s=>Math.floor(s)),t=[...new Set(t)].join("");let n,o=0,r=e.length-1;do n="",e.forEach((s,u)=>n+=`${T(t,s)}${u===r?"":"-"}`),o++,o>=Math.pow(n.length,n.length)&&e[r]++;while(m.has(n));return m.add(n),n};typeof window<"u"&&(typeof window.ssts!="object"&&(window.ssts={}),window.ssts.seniorID=l);var x=l;