UNPKG

modpacksio-common

Version:

Common code for Modpacks.io services

19 lines (16 loc) 589 B
const nextId = () => Math.floor(100000000000 + Math.random() * 900000000000); const isValidId = _id => { if (!_id) return false; const id = _id.toString(); return id.length === 12 && id.match(/[0-9]*/g).length === 2; }; const nextToken = () => { let result = '', characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', len = characters.length; for (let i = 0; i < 40; i++ ) result += characters.charAt(Math.floor(Math.random() * len)); return result; }; module.exports = Object.freeze({ nextId, isValidId, nextToken });