hide-ip 1.0.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/index.js +32 -0
- package/package.json +24 -0
- package/readme.md +55 -0
package/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {String} ip ipv4 or ipv6
|
|
6
|
+
* @param {Object} options defalut {level = 2, maskChar = "*"}
|
|
7
|
+
* @returns {string}
|
|
8
|
+
*/
|
|
9
|
+
function hideIp(ip, options = {}) {
|
|
10
|
+
if (typeof ip != "string") return ip
|
|
11
|
+
|
|
12
|
+
const {level = 2, maskChar = "*"} = options
|
|
13
|
+
if (level <= 0) return ip
|
|
14
|
+
|
|
15
|
+
if (ip.includes(".")) {
|
|
16
|
+
const parts = ip.split(".")
|
|
17
|
+
return parts
|
|
18
|
+
.map((part, i) => (i >= parts.length - level ? maskChar.repeat(part.length) : part))
|
|
19
|
+
.join(".")
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (ip.includes(":")) {
|
|
23
|
+
const parts = ip.split(":")
|
|
24
|
+
return parts
|
|
25
|
+
.map((part, i) => (i >= parts.length - level ? maskChar.repeat(Math.max(part.length, 1)) : part))
|
|
26
|
+
.join(":")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return ip
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = hideIp
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "hide-ip",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Mask IPv4 and IPv6 addresses with custom masking levels and characters.",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"author": "_redgold__",
|
|
7
|
+
"type": "commonjs",
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"homepage": "https://github.com/IMJNMHTODRLA/hide-ip",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "http://github.com/IMJNMHTODRLA/hide-ip.git"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"ip",
|
|
16
|
+
"addresses",
|
|
17
|
+
"mask",
|
|
18
|
+
"ipv4",
|
|
19
|
+
"ipv6",
|
|
20
|
+
"privacy",
|
|
21
|
+
"security",
|
|
22
|
+
"anonymize"
|
|
23
|
+
]
|
|
24
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# hide-ip [](https://www.npmjs.com/package/hide-ip)
|
|
2
|
+
|
|
3
|
+
Mask IPv4 and IPv6 addresses with custom masking levels and characters. Simple, lightweight, and zero-dependency.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
### npm
|
|
8
|
+
```shell
|
|
9
|
+
npm install hide-ip
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
Mask sensitive IP addresses for logs, UI, or security purposes. Support for both IPv4 and IPv6.
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
const hideIp = require("hide-ip")
|
|
17
|
+
|
|
18
|
+
//Basic usage (Default: level 2, maskChar "*")
|
|
19
|
+
hideIp("192.0.2.255")
|
|
20
|
+
//-> 192.0.*.***
|
|
21
|
+
|
|
22
|
+
hideIp("2001:db8:85a3:0000:0000:8a2e:0370:7334")
|
|
23
|
+
//-> 2001:db8:85a3:0000:0000:8a2e:***:****
|
|
24
|
+
|
|
25
|
+
//Custom masking level (How many segments to mask from the end)
|
|
26
|
+
hideIp("192.0.2.255", {level: 1})
|
|
27
|
+
//-> 192.0.2.***
|
|
28
|
+
|
|
29
|
+
//Custom masking character
|
|
30
|
+
hideIp("192.0.2.255", { maskChar: "#" })
|
|
31
|
+
//-> 192.168.#.###
|
|
32
|
+
|
|
33
|
+
//Handling edge cases
|
|
34
|
+
hideIp("::1", { level: 1 }) //IPv6 loopback
|
|
35
|
+
//-> "::*"
|
|
36
|
+
|
|
37
|
+
hideIp(null) //Returns original input if not a string
|
|
38
|
+
//-> null
|
|
39
|
+
|
|
40
|
+
hideIp(1234)
|
|
41
|
+
//-> 1234
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## API
|
|
45
|
+
|
|
46
|
+
### hideIp(ip, [options])
|
|
47
|
+
|
|
48
|
+
- `ip` (String): The IPv4 or IPv6 address to mask.
|
|
49
|
+
- `options` (Object):
|
|
50
|
+
- `level` (Number): Number of segments to mask starting from the end. **Default: 2**.
|
|
51
|
+
- `maskChar` (String): Character used for masking. **Default: "*"**.
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
This software is licensed under the ISC License.
|
|
55
|
+
Copyright _redgold__, 2025.
|