swc/bundler/tests/.cache/deno/6d2a5c2dec57e9c2b2e08cc931287b08f6a019dd.ts
강동윤 bbaf619f63
fix(bundler): Fix bugs (#1437)
swc_bundler:
 - [x] Fix wrapped esms. (denoland/deno#9307)
 - [x] Make test secure.
2021-03-02 17:33:03 +09:00

42 lines
1.0 KiB
TypeScript

// Loaded from https://deno.land/x/segno@v1.1.0/lib/validations/isFloat.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';
type FloatOptions = {
locale?: string;
min?: number;
max?: number;
lt?: number;
gt?: number;
};
export const isFloat = (str: string, options?: FloatOptions) => {
assertString(str);
options = options || {};
const float = new RegExp(
`^(?:[-+])?(?:[0-9]+)?(?:\\${
options.locale ? (decimal as any)[options.locale] : '.'
}[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$`
);
if (str === '' || str === '.' || str === '-' || str === '+') {
return false;
}
const value = parseFloat(str.replace(',', '.'));
return (
float.test(str) &&
(!options.min || value >= options.min) &&
(!options.max || value <= options?.max) &&
(!options.lt || value < options?.lt) &&
(!options.gt || value > options?.gt)
);
};
export const decimalLocales = Object.keys(decimal);