@technobuddha/library
Version:
A large library of useful functions
17 lines (16 loc) • 510 B
JavaScript
import matches from '../matches';
/**
* Convert a string to a numeric value
*
* @param input The string to convert
* @param tests Array of tests (string value or regular expressions)
* @parm __namedParameters see {@link Options}
* @returns The index of the first test to match the input string
*/
export function toEnumeration(input, ...tests) {
for (let i = 0; i < tests.length; ++i)
if (matches(input, tests[i]))
return i;
return undefined;
}
export default toEnumeration;