UNPKG

@onesy/utils

Version:
24 lines (23 loc) 1.09 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const pick_1 = __importDefault(require("./pick")); const clamp_1 = __importDefault(require("./clamp")); const shuffle_1 = __importDefault(require("./shuffle")); const randomString = (length_ = 1e1) => { const length = (0, clamp_1.default)(length_, 4); let result = ''; const lowercase = 'abcdefghijklmnopqrstuvwxyz'; const uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; const specials = '!@#$%^&*()_+{}:"<>?\|[];\',./`~'; const numbers = '0123456789'; const lowPriorityLength = Math.ceil(length * 0.1); result += (0, pick_1.default)(lowercase, (length - (lowPriorityLength * 3))); result += (0, pick_1.default)(uppercase, lowPriorityLength); result += (0, pick_1.default)(specials, lowPriorityLength); result += (0, pick_1.default)(numbers, lowPriorityLength); return (0, shuffle_1.default)(result); }; exports.default = randomString;