{"version":3,"file":"ip.mjs","names":[],"sources":["../../../../../../../../@warlock.js/seal/src/rules/string/ip.ts"],"sourcesContent":["import { isIP } from \"net\";\r\nimport { invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport type { SchemaRule } from \"../../types\";\r\n\r\n/**\r\n * IP rule - validates IP address (v4 or v6)\r\n */\r\nexport const ipRule: SchemaRule = {\r\n  name: \"ip\",\r\n  defaultErrorMessage: \"The :input must be a valid IP address\",\r\n  async validate(value: any, context) {\r\n    if (isIP(value)) {\r\n      return VALID_RULE;\r\n    }\r\n    return invalidRule(this, context);\r\n  },\r\n};\r\n\r\n/**\r\n * IPv4 rule - validates IPv4 address\r\n */\r\nexport const ip4Rule: SchemaRule = {\r\n  name: \"ip4\",\r\n  defaultErrorMessage: \"The :input must be a valid IPv4 address\",\r\n  async validate(value: any, context) {\r\n    if (isIP(value) === 4) {\r\n      return VALID_RULE;\r\n    }\r\n    return invalidRule(this, context);\r\n  },\r\n};\r\n\r\n/**\r\n * IPv6 rule - validates IPv6 address\r\n */\r\nexport const ip6Rule: SchemaRule = {\r\n  name: \"ip6\",\r\n  defaultErrorMessage: \"The :input must be a valid IPv6 address\",\r\n  async validate(value: any, context) {\r\n    if (isIP(value) === 6) {\r\n      return VALID_RULE;\r\n    }\r\n    return invalidRule(this, context);\r\n  },\r\n};\r\n"],"mappings":";;;;;;;;AAOA,MAAa,SAAqB;CAChC,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,IAAI,KAAK,KAAK,GACZ,OAAO;EAET,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;AAKA,MAAa,UAAsB;CACjC,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,IAAI,KAAK,KAAK,MAAM,GAClB,OAAO;EAET,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;AAKA,MAAa,UAAsB;CACjC,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,IAAI,KAAK,KAAK,MAAM,GAClB,OAAO;EAET,OAAO,YAAY,MAAM,OAAO;CAClC;AACF"}