mirror of
https://github.com/swc-project/swc.git
synced 2024-12-23 05:32:09 +03:00
16 lines
403 B
TypeScript
16 lines
403 B
TypeScript
// Loaded from https://deno.land/x/validasaur/src/rules/is_ipv4.ts
|
|
|
|
|
|
import type { Validity } from "../types.ts";
|
|
import { invalid } from "../utils.ts";
|
|
|
|
export function isIPv4(value: any): Validity {
|
|
if (typeof value !== "string") {
|
|
return invalid("isIPv4", { value });
|
|
}
|
|
|
|
if (!value.match(/^(?:(?:^|\.)(?:2(?:5[0-5]|[0-4]\d)|1?\d?\d)){4}$/)) {
|
|
return invalid("isIPv4", { value });
|
|
}
|
|
}
|