UNPKG

@grandom/shuffle

Version:

A configurable, flexible, seedable, and overall great random shuffler.

41 lines (37 loc) 1.54 kB
'use strict'; var core = require('@grandom/core'); var index = require('./RandomStringShuffle/index.js'); var index$1 = require('./RandomArrayShuffle/index.js'); var index$2 = require('./RandomObjectShuffle/index.js'); // TODO: add seed capability // TODO: check constructor arg for valid type // TODO: handle typed arrays // TODO: handle Maps and Sets class RandomShuffle extends core.RandomGenerator { constructor(engine) { super(engine); const stringShuffle = new index(engine); const arrayShuffle = new index$1(engine); const objectShuffle = new index$2(engine); const shuffle = (arg1, arg2, arg3) => { if (stringShuffle.canBeParsed(arg1)) { return stringShuffle.parse(arg1, arg2, arg3); } else if (arrayShuffle.canBeParsed(arg1)) { return arrayShuffle.parse(arg1, arg2, arg3); } else if (objectShuffle.canBeParsed(arg1)) { return objectShuffle.parse(arg1, arg2, arg3); } throw new TypeError('Must be called with a string, array, or object, got: ' + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions `${arg1} (typeof === '${typeof arg1}').`); }; shuffle.string = stringShuffle.shuffle; shuffle.array = arrayShuffle.shuffle; shuffle.object = objectShuffle.shuffle; this.shuffle = shuffle; } } module.exports = RandomShuffle; //# sourceMappingURL=index.js.map