swc/bundler/tests/.cache/deno/8376f4468129b626d419e1689092b6a9cd39a421.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

34 lines
746 B
TypeScript

// Loaded from https://deno.land/x/segno@v1.1.0/lib/validations/isIPRange.ts
// @ts-ignore allowing typedoc to build
import { assertString } from '../helpers/assertString.ts';
// @ts-ignore allowing typedoc to build
import { isIP } from './isIP.ts';
/**
* @ignore
*/
const subnetMaybe = /^\d{1,2}$/;
export const isIPRange = (str: string) => {
assertString(str);
const parts = str.split('/');
// parts[0] -> ip, parts[1] -> subnet
if (parts.length !== 2) {
return false;
}
if (!subnetMaybe.test(parts[1])) {
return false;
}
// Disallow preceding 0 i.e. 01, 02, ...
if (parts[1].length > 1 && parts[1].startsWith('0')) {
return false;
}
return isIP(parts[0], 4) && +parts[1] <= 32 && +parts[1] >= 0;
};