mentie 0.3.17 → 0.3.18
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/modules/validations.js +19 -0
- package/package.json +1 -1
package/modules/validations.js
CHANGED
|
@@ -30,6 +30,25 @@ export const is_ipv4 = ip => {
|
|
|
30
30
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Checks if a string is a valid IPv6 address. VERY NAIVELY
|
|
35
|
+
* @param {string} ip - The IP address to check.
|
|
36
|
+
* @returns {boolean} True if this is probably a valid IPv6 address, otherwise false.
|
|
37
|
+
*/
|
|
38
|
+
export const is_ipv6 = ip => {
|
|
39
|
+
|
|
40
|
+
// must be string
|
|
41
|
+
if( typeof ip !== 'string' ) return false
|
|
42
|
+
|
|
43
|
+
// must have only hex digits and colons
|
|
44
|
+
if( !/^[0-9a-f:]+$/.test( ip ) ) return false
|
|
45
|
+
|
|
46
|
+
// If no :: compression it must be 8 parts, otherwise it must be 7 or under
|
|
47
|
+
if( ip.includes( '::' ) ) return ip.split( ':' ).length <= 8
|
|
48
|
+
return ip.split( ':' ).length === 8
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
33
52
|
/**
|
|
34
53
|
* Sanitizes and optionally validates an IPv4 address.
|
|
35
54
|
* @param {Object} options - The options object.
|