@onesy/utils
Version:
21 lines (20 loc) • 796 B
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const is_1 = __importDefault(require("./is"));
const clamp_1 = __importDefault(require("./clamp"));
const random_1 = __importDefault(require("./random"));
const pick = (value, min = 1, max) => {
if ((0, is_1.default)('string', value)) {
let result = '';
let toPick = (0, clamp_1.default)(min, 1);
if (max > 0 && max > min)
toPick = (0, random_1.default)(min, max);
for (let i = 0; i < toPick; i++)
result += value.charAt(Math.floor(Math.random() * value.length));
return result;
}
};
exports.default = pick;
;