swc/crates/swc_bundler/tests/.cache/deno/3e9ec29bf7ffe6df5bbd10261cc1a3eeb15a74b1.ts
2021-11-09 20:42:49 +09:00

32 lines
713 B
TypeScript

// Loaded from https://deno.land/x/segno@v1.1.0/lib/validations/isNumeric.ts
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';
// @ts-ignore allowing typedoc to build
import { decimal } from '../helpers/alpha.ts';
/**
* @ignore
*/
const numericNoSymbols = /^[0-9]+$/;
type NumericOptions = {
noSymbols?: boolean;
locale?: any;
};
export const isNumeric = (str: string, options?: NumericOptions) => {
assertString(str);
if (options && options.noSymbols) {
return numericNoSymbols.test(str);
}
return new RegExp(
`^[+-]?([0-9]*[${
(options || {}).locale ? (decimal as any)[options?.locale] : '.'
}])?[0-9]+$`
).test(str);
};