simplyhexagonal / short-unique-id

Short Unique ID (UUID) generation library. Available in NPM.

Home Page:https://www.npmjs.com/package/short-unique-id

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do I generate a formatted increment ID

neozhu opened this issue · comments

like, ddd-dddd-ddd, xxxx-xxx-xxxx

Hi @neozhu , I'd say the simplest way would be using regex, like so:

// ddd-dddd-ddd
uid(10).replace(/(.{3})(.{4})(.{3})/g, '$1-$2-$3')
// xxxx-xxx-xxxx
uid(11).replace(/(.{4})(.{3})(.{4})/g, '$1-$2-$3')

Cheers 🍻

cool! thank you.