generate-ip 2.0.3 → 2.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.
Files changed (2) hide show
  1. package/README.md +101 -15
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -3,9 +3,9 @@
3
3
  ### Randomly generate IPv4 and IPv6 addresses.
4
4
 
5
5
  <a href="#%EF%B8%8F-mit-license"><img height=31 src="https://img.shields.io/badge/License-MIT-orange.svg?logo=internetarchive&logoColor=white&labelColor=464646&style=for-the-badge"></a>
6
- <a href="https://github.com/adamlui/js-utils/releases/tag/generate-ip-2.0.3"><img height=31 src="https://img.shields.io/badge/Latest_Build-2.0.3-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
6
+ <a href="https://github.com/adamlui/js-utils/releases/tag/generate-ip-2.1.0"><img height=31 src="https://img.shields.io/badge/Latest_Build-2.1.0-44cc11.svg?logo=icinga&logoColor=white&labelColor=464646&style=for-the-badge"></a>
7
7
  <a href="https://www.npmjs.com/package/generate-ip?activeTab=code"><img height=31 src="https://img.shields.io/npm/unpacked-size/generate-ip?style=for-the-badge&logo=ebox&logoColor=white&labelColor=464646&color=blue"></a>
8
- <a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:generate-ip/generate-ip.js"><img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_js-utils%3Agenerate-ip%2Fgenerate-ip.js%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=Vulnerabilities&color=gold"></a>
8
+ <a href="https://sonarcloud.io/component_measures?metric=new_vulnerabilities&id=adamlui_js-utils:generate-ip/generate-ip.js"><img height=31 src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fsonarcloud.io%2Fapi%2Fmeasures%2Fcomponent%3Fcomponent%3Dadamlui_js-utils%3Agenerate-ip%2Fsrc%2Fgenerate-ip.js%26metricKeys%3Dvulnerabilities&query=%24.component.measures.0.value&style=for-the-badge&logo=sonarcloud&logoColor=white&labelColor=464646&label=Vulnerabilities&color=gold"></a>
9
9
 
10
10
  <br>
11
11
 
@@ -35,9 +35,9 @@ $ npm install generate-ip
35
35
 
36
36
  <img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
37
37
 
38
- ## 🔌 API usage
38
+ ## 🔌 Importing the APIs
39
39
 
40
- **generate-ip** provides the [**`ipv4`**](#ipv4-methods) and [**`ipv6`**](#ipv6-methods) APIs that can be imported into your app as ECMAScript modules or CommonJS modules.
40
+ ### <img height=18 src="https://i.imgur.com/JIeAdsr.png"> Node.js
41
41
 
42
42
  #### ESM:
43
43
 
@@ -51,7 +51,54 @@ import { ipv4, ipv6 } from 'generate-ip';
51
51
  const { ipv4, ipv6 } = require('generate-ip');
52
52
  ```
53
53
 
54
- #
54
+ ### <picture><source media="(prefers-color-scheme: dark)" srcset="https://i.imgur.com/JSEb19A.png"><img width=16 src="https://i.imgur.com/5VPxf9y.png"></picture> Web
55
+
56
+ #### HTML script tag:
57
+
58
+ ```html
59
+ <script src="https://cdn.jsdelivr.net/npm/generate-ip@2.1.0/dist/generate-ip.min.js"></script>
60
+ ```
61
+
62
+ #### ES6:
63
+
64
+ ```js
65
+ (async () => {
66
+ await import('https://cdn.jsdelivr.net/npm/generate-ip@2.1.0/dist/generate-ip.min.js');
67
+ // Your code here...
68
+ })();
69
+ ```
70
+
71
+ #### ES5:
72
+
73
+ ```js
74
+ var xhr = new XMLHttpRequest();
75
+ xhr.open('GET', 'https://cdn.jsdelivr.net/npm/generate-ip@2.1.0/dist/generate-ip.min.js');
76
+ xhr.onload = function() {
77
+ if (xhr.status === 200) {
78
+ var generateIP = document.createElement('script');
79
+ generateIP.textContent = xhr.responseText;
80
+ document.head.append(generateIP);
81
+ // Your code here...
82
+ }
83
+ };
84
+ xhr.send();
85
+ ```
86
+
87
+ ### <img height=17 src="https://raw.githubusercontent.com/KudoAI/chatgpt.js/main/starters/media/images/icons/tampermonkey-icon28.png"><img height=17.5 src="https://raw.githubusercontent.com/KudoAI/chatgpt.js/main/starters/media/images/icons/violentmonkey-icon100.png"> Greasemonkey
88
+
89
+ ```js
90
+ ...
91
+ // @require https://cdn.jsdelivr.net/npm/generate-ip@2.1.0/dist/generate-ip.min.js
92
+ // ==/UserScript==
93
+
94
+ // Your code here...
95
+ ```
96
+
97
+ <br>
98
+
99
+ <img height=6px width="100%" src="https://raw.githubusercontent.com/adamlui/js-utils/main/docs/images/aqua-separator.png">
100
+
101
+ ## 📋 API usage
55
102
 
56
103
  ### `ipv4` methods
57
104
 
@@ -61,7 +108,7 @@ Use the `ipv4` methods to [**generate**](#ipv4generateoptions) and [**validate**
61
108
 
62
109
  #### `ipv4.generate([options])`
63
110
 
64
- Generates **one** IPv4 address:
111
+ Generates **one** IPv4 address if `qty` option is not given, returning a string:
65
112
 
66
113
  ```js
67
114
  const ip = ipv4.generate();
@@ -72,15 +119,31 @@ console.log(ip);
72
119
  ipv4.generate() » Generating IPv4 address...
73
120
  ipv4.generate() » IPv4 address generated!
74
121
  ipv4.generate() » Check returned string.
75
- 36.42.224.208
122
+ '36.42.224.208'
76
123
  */
77
124
  ```
78
125
 
79
- Available options (passed as object properties):
126
+ ...or **multiple** IPv4 addresses if `qty` option is given, returning an array of strings:
80
127
 
81
- Name | Type | Description | Default Value
82
- ------------|---------|-----------------------------------|---------------
83
- `verbose` | Boolean | Show logging in console/terminal. | `true`
128
+ ```js
129
+ const ips = ipv4.generate({ qty: 3 });
130
+ console.log(ips);
131
+
132
+ /* sample output:
133
+
134
+ ipv4.generate() » Generating IPv4 addresses...
135
+ ipv4.generate() » IPv4 addresses generated!
136
+ ipv4.generate() » Check returned array.
137
+ [ '194.84.176.172', '192.186.53.120', '50.191.111.87' ]
138
+ */
139
+ ```
140
+
141
+ Available options:
142
+
143
+ Name | Type | Description | Default Value
144
+ ------------|---------|-------------------------------------|---------------
145
+ `verbose` | Boolean | Show logging in console/terminal. | `true`
146
+ `qty` | Integer | Number of IP addresses to generate. | `1`
84
147
 
85
148
  #
86
149
 
@@ -116,7 +179,7 @@ Use the `ipv6` methods to [**generate**](#ipv6generateoptions), [**format**](#ip
116
179
 
117
180
  #### `ipv6.generate([options])`
118
181
 
119
- Generates **one** IPv6 address, returned as a string:
182
+ Generates **one** IPv6 address if `qty` option is not given, returning a string:
120
183
 
121
184
  ```js
122
185
  const ip = ipv6.generate();
@@ -127,15 +190,37 @@ console.log(ip);
127
190
  ipv6.generate() » Generating IPv6 address...
128
191
  ipv6.generate() » IPv6 address generated!
129
192
  ipv6.generate() » Check returned string.
130
- 1379:6748:810c:5e16:b6c9:ae2:939f:8f2a
193
+ '1379:6748:810c:5e16:b6c9:ae2:939f:8f2a'
131
194
  */
132
195
  ```
133
196
 
134
- Available options (passed as object properties):
197
+ ...or **multiple** IPv6 addresses if `qty` option is given, returning an array of strings:
198
+
199
+ ```js
200
+ const ips = ipv4.generate({ qty: 5 });
201
+ console.log(ips);
202
+
203
+ /* sample output:
204
+
205
+ ipv6.generate() » Generating IPv6 addresses...
206
+ ipv6.generate() » IPv6 addresses generated!
207
+ ipv6.generate() » Check returned array.
208
+ [
209
+ '8218:19b9:7709:4282:65e1:7ee:319e:32ef',
210
+ 'e940:754d:ae46:ae18:94dd:b43c:583:68c2',
211
+ 'b570:b4f8:68f:62e2:99cb:ad0f:6237:9d51',
212
+ '98a7:f4e5:2f4e:8a2d:56bb:dc28:f94a:46a8',
213
+ 'ca59:590a:9b6c:ea25:94fa:37d6:9bac:7ff6'
214
+ ]
215
+ */
216
+ ```
217
+
218
+ Available options:
135
219
 
136
220
  Name | Type | Description | Default Value
137
221
  ---------------|---------|--------------------------------------|---------------
138
222
  `verbose` | Boolean | Show logging in console/terminal. | `true`
223
+ `qty` | Integer | Number of IP addresses to generate. | `1`
139
224
  `leadingZeros` | Boolean | Include leading zeros in hex pieces. | `false`
140
225
  `doubleColon` | Boolean | Replace series of zeros w/ `::` | `true`
141
226
 
@@ -157,7 +242,8 @@ console.log(formattedAddress);
157
242
  ipv6.format() » Expanding '::' into zero series...
158
243
  ipv6.format() » Adding leading zeros...
159
244
  ipv6.format() » IP formatted successfully!
160
- 000d:0000:0000:0000:0000:0000:ffff:192.1.56.10/96
245
+ ipv6.format() » Check returned string.
246
+ '000d:0000:0000:0000:0000:0000:ffff:192.1.56.10/96'
161
247
  */
162
248
  ```
163
249
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generate-ip",
3
- "version": "2.0.3",
3
+ "version": "2.1.0",
4
4
  "description": "Randomly generate IPv4 and IPv6 addresses.",
5
5
  "author": {
6
6
  "name": "Adam Lui",
@@ -15,12 +15,12 @@
15
15
  "docs"
16
16
  ],
17
17
  "bin": {
18
- "generateip": "dist/generate-ip.min.js",
19
- "generate-ip": "dist/generate-ip.min.js"
18
+ "generateip": "dist/cli.min.js",
19
+ "generate-ip": "dist/cli.min.js"
20
20
  },
21
21
  "scripts": {
22
22
  "test": "echo \"Error: no test specified\" && exit 1",
23
- "build": "minify-js generate-ip.js dist",
23
+ "build": "minify-js src dist",
24
24
  "bump:patch": "bash utils/bump.sh patch",
25
25
  "bump:minor": "bash utils/bump.sh minor",
26
26
  "bump:major": "bash utils/bump.sh major",