@se-oss/ip-address 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -27,6 +27,7 @@ __export(index_exports, {
27
27
  bigIntToIp: () => bigIntToIp,
28
28
  fastIpVersion: () => fastIpVersion,
29
29
  ipToBigInt: () => ipToBigInt,
30
+ isValidIP: () => isValidIP,
30
31
  parseCIDR: () => parseCIDR,
31
32
  parseIP: () => parseIP
32
33
  });
@@ -237,9 +238,6 @@ var IPv6 = class _IPv6 {
237
238
  * IPv6.isValid('2001:db8::g'); // false
238
239
  */
239
240
  static isValid(address) {
240
- if (address.includes("/")) {
241
- return false;
242
- }
243
241
  return IPV6_VALIDATION_REGEX.test(address);
244
242
  }
245
243
  // --- Getters ---
@@ -498,9 +496,6 @@ var IPv4 = class _IPv4 {
498
496
  * IPv4.isValid('1.2.3.256'); // false
499
497
  */
500
498
  static isValid(address) {
501
- if (address.includes("/")) {
502
- return false;
503
- }
504
499
  return IPV4_ADDRESS_REGEX.test(address);
505
500
  }
506
501
  // --- Getters ---
@@ -880,6 +875,12 @@ function parseIP(address) {
880
875
  function parseCIDR(cidr) {
881
876
  return new CIDR(cidr);
882
877
  }
878
+ function isValidIP(maybeIP) {
879
+ if (typeof maybeIP !== "string") {
880
+ return false;
881
+ }
882
+ return IPv4.isValid(maybeIP) || IPv6.isValid(maybeIP);
883
+ }
883
884
  // Annotate the CommonJS export names for ESM import in node:
884
885
  0 && (module.exports = {
885
886
  CIDR,
@@ -889,6 +890,7 @@ function parseCIDR(cidr) {
889
890
  bigIntToIp,
890
891
  fastIpVersion,
891
892
  ipToBigInt,
893
+ isValidIP,
892
894
  parseCIDR,
893
895
  parseIP
894
896
  });
package/dist/index.d.ts CHANGED
@@ -496,5 +496,18 @@ declare function parseIP(address: string): IP;
496
496
  * @throws {InvalidIPAddressError} if the cidr is not a valid v4 or v6 cidr.
497
497
  */
498
498
  declare function parseCIDR(cidr: string): CIDR<IP>;
499
+ /**
500
+ * Safely checks if a value is a string representing a valid IPv4 or IPv6 address.
501
+ *
502
+ * @param maybeIP The value to check.
503
+ * @returns {boolean} True if the value is a valid IP address string.
504
+ *
505
+ * @example
506
+ * isValidIP('192.168.1.1'); // true
507
+ * isValidIP('2001:db8::1'); // true
508
+ * isValidIP('not an ip'); // false
509
+ * isValidIP(null); // false
510
+ */
511
+ declare function isValidIP(maybeIP: unknown): boolean;
499
512
 
500
- export { CIDR, type IP, type IPVersion, IPv4, IPv6, InvalidIPAddressError, bigIntToIp, fastIpVersion, ipToBigInt, parseCIDR, parseIP };
513
+ export { CIDR, type IP, type IPVersion, IPv4, IPv6, InvalidIPAddressError, bigIntToIp, fastIpVersion, ipToBigInt, isValidIP, parseCIDR, parseIP };
package/dist/index.js CHANGED
@@ -203,9 +203,6 @@ var IPv6 = class _IPv6 {
203
203
  * IPv6.isValid('2001:db8::g'); // false
204
204
  */
205
205
  static isValid(address) {
206
- if (address.includes("/")) {
207
- return false;
208
- }
209
206
  return IPV6_VALIDATION_REGEX.test(address);
210
207
  }
211
208
  // --- Getters ---
@@ -464,9 +461,6 @@ var IPv4 = class _IPv4 {
464
461
  * IPv4.isValid('1.2.3.256'); // false
465
462
  */
466
463
  static isValid(address) {
467
- if (address.includes("/")) {
468
- return false;
469
- }
470
464
  return IPV4_ADDRESS_REGEX.test(address);
471
465
  }
472
466
  // --- Getters ---
@@ -846,6 +840,12 @@ function parseIP(address) {
846
840
  function parseCIDR(cidr) {
847
841
  return new CIDR(cidr);
848
842
  }
843
+ function isValidIP(maybeIP) {
844
+ if (typeof maybeIP !== "string") {
845
+ return false;
846
+ }
847
+ return IPv4.isValid(maybeIP) || IPv6.isValid(maybeIP);
848
+ }
849
849
  export {
850
850
  CIDR,
851
851
  IPv4,
@@ -854,6 +854,7 @@ export {
854
854
  bigIntToIp,
855
855
  fastIpVersion,
856
856
  ipToBigInt,
857
+ isValidIP,
857
858
  parseCIDR,
858
859
  parseIP
859
860
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@se-oss/ip-address",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "A modern, immutable, and zero-dependency library for working with IPv4 and IPv6 addresses in JavaScript and TypeScript.",
5
5
  "keywords": [
6
6
  "ip",