UNPKG

typed-id

Version:

A lightweight, type-safe TypeScript library for generating prefixed IDs with customizable options

2 lines (1 loc) 1.19 kB
"use strict";var a=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var u=(e,t)=>{for(var r in t)a(e,r,{get:t[r],enumerable:!0})},f=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of d(t))!l.call(e,n)&&n!==r&&a(e,n,{get:()=>t[n],enumerable:!(s=c(t,n))||s.enumerable});return e};var A=e=>f(a({},"__esModule",{value:!0}),e);var S={};u(S,{IdHelper:()=>o});module.exports=A(S);var i=require("nanoid"),o=class e{constructor(t,r={}){this.prefix=t;this.options=r}static DEFAULT_SEPARATOR="_";static DEFAULT_LENGTH=10;static DEFAULT_ALPHABETS="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";get optionsOrDefaults(){let{separator:t=e.DEFAULT_SEPARATOR,length:r=e.DEFAULT_LENGTH,customAlphabets:s=e.DEFAULT_ALPHABETS}=this.options;return{separator:t,length:r,customAlphabets:s}}get regex(){let{separator:t,length:r,customAlphabets:s}=this.optionsOrDefaults;return new RegExp(`^${this.prefix}${t}[${s}]{${r}}$`)}generate(){let{separator:t,length:r,customAlphabets:s}=this.optionsOrDefaults,p=(0,i.customAlphabet)(s,r)();return this.prefix+t+p}};0&&(module.exports={IdHelper});