mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 22:22:34 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
32 lines
713 B
TypeScript
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);
|
|
};
|