UNPKG

@grandom/shuffle

Version:

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

48 lines (45 loc) 1.64 kB
'use strict'; class ExcludeFilter { constructor(exclude) { this._filterEntries = []; if ((typeof exclude !== 'string' && typeof exclude !== 'object') || exclude === null) { throw new TypeError('Filter must be a string, RegExp, or Array<string | RegExp>, got: ' + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions `${exclude} (typeof === '${typeof exclude}').`); } const filters = Array.isArray(exclude) ? exclude : [exclude]; let i = 0; for (const filter of filters) { if (typeof filter === 'string') { this._filterEntries.push({ string: filter }); } else if (filter instanceof RegExp) { this._filterEntries.push({ regexp: filter }); } else { throw new TypeError(`Filter[${i}] must be a string, or a RegExp, got: ` + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions `${filter} (typeof === '${typeof filter}').`); } i++; } } get numFilters() { return this._filterEntries.length; } matches(value) { for (const filterEntry of this._filterEntries) { if (value === filterEntry.string) { return true; } if (filterEntry.regexp?.test(value) === true) { return true; } } return false; } } module.exports = ExcludeFilter; //# sourceMappingURL=index.js.map