foxts 1.1.7 → 1.3.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/create-fixed-array/index.cjs +1 -0
- package/create-fixed-array/index.d.ts +5 -0
- package/create-fixed-array/index.mjs +1 -0
- package/is-probably-ip/index.cjs +1 -1
- package/is-probably-ip/index.mjs +1 -1
- package/package.json +76 -46
- package/pick-random/index.cjs +1 -0
- package/pick-random/index.d.ts +10 -0
- package/pick-random/index.mjs +1 -0
- package/random-int/index.cjs +1 -0
- package/random-int/index.d.ts +8 -0
- package/random-int/index.mjs +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=new Map;function t(e){return Array.from(Array(e).keys())}function r(r){if(e.has(r))return e.get(r);const n=t(r);return e.set(r,n),n}const n=new Map;function a(e){let r,a;return n.has(e)&&(a=(r=n.get(e)).deref()),a||(r=new WeakRef(a=t(e)),n.set(e,r)),a}const o="function"==typeof WeakRef?a:r;exports.createFixedArray=o,exports.createFixedArrayWithGC=a,exports.createFixedArrayWithoutGC=r;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare function createFixedArrayWithoutGC(length: number): readonly number[];
|
|
2
|
+
declare function createFixedArrayWithGC(length: number): readonly number[];
|
|
3
|
+
declare const createFixedArray: typeof createFixedArrayWithGC;
|
|
4
|
+
|
|
5
|
+
export { createFixedArray, createFixedArrayWithGC, createFixedArrayWithoutGC };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=new Map;function t(e){return Array.from(Array(e).keys())}function r(r){if(e.has(r))return e.get(r);const n=t(r);return e.set(r,n),n}const n=new Map;function a(e){let r,a;return n.has(e)&&(a=(r=n.get(e)).deref()),a||(r=new WeakRef(a=t(e)),n.set(e,r)),a}const o="function"==typeof WeakRef?a:r;export{o as createFixedArray,a as createFixedArrayWithGC,r as createFixedArrayWithoutGC};
|
package/is-probably-ip/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";exports.isProbablyIpv4=function(t){if(t.length<7||t.length>15)return!1;let e=0;for(let r=0;r<t.length;r+=1){const n=t.charCodeAt(r);if(46===n)e+=1;else if(n<48||n>57)return!1}return 3===e&&46!==t.charCodeAt(0)&&46!==t.charCodeAt(t.length-1)},exports.isProbablyIpv6=function(t){if(t.length<3)return!1;let e
|
|
1
|
+
"use strict";exports.isProbablyIpv4=function(t){if(t.length<7||t.length>15)return!1;let e=0;for(let r=0;r<t.length;r+=1){const n=t.charCodeAt(r);if(46===n)e+=1;else if(n<48||n>57)return!1}return 3===e&&46!==t.charCodeAt(0)&&46!==t.charCodeAt(t.length-1)},exports.isProbablyIpv6=function(t){if(t.length<3)return!1;let e=+("["===t[0]),r=t.length;if("]"===t[r-1]&&(r-=1),r-e>39)return!1;let n=!1;for(;e<r;e+=1){const r=t.charCodeAt(e);if(58===r)n=!0;else if(!(r>=48&&r<=57||r>=97&&r<=102||r>=65&&r<=90))return!1}return n};
|
package/is-probably-ip/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e){if(e.length<7||e.length>15)return!1;let t=0;for(let r=0;r<e.length;r+=1){const n=e.charCodeAt(r);if(46===n)t+=1;else if(n<48||n>57)return!1}return 3===t&&46!==e.charCodeAt(0)&&46!==e.charCodeAt(e.length-1)}function t(e){if(e.length<3)return!1;let t
|
|
1
|
+
function e(e){if(e.length<7||e.length>15)return!1;let t=0;for(let r=0;r<e.length;r+=1){const n=e.charCodeAt(r);if(46===n)t+=1;else if(n<48||n>57)return!1}return 3===t&&46!==e.charCodeAt(0)&&46!==e.charCodeAt(e.length-1)}function t(e){if(e.length<3)return!1;let t=+("["===e[0]),r=e.length;if("]"===e[r-1]&&(r-=1),r-t>39)return!1;let n=!1;for(;t<r;t+=1){const r=e.charCodeAt(t);if(58===r)n=!0;else if(!(r>=48&&r<=57||r>=97&&r<=102||r>=65&&r<=90))return!1}return n}export{e as isProbablyIpv4,t as isProbablyIpv6};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foxts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Opinionated collection of common TypeScript utils by @SukkaW",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "https://github.com/SukkaW/foxts"
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
],
|
|
15
15
|
"author": "SukkaW <https://skk.moe>",
|
|
16
16
|
"license": "MIT",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"uncrypto": "^0.1.3"
|
|
19
|
+
},
|
|
17
20
|
"typeVersions": {
|
|
18
21
|
">=4.8": {
|
|
19
22
|
"*": [
|
|
@@ -38,14 +41,14 @@
|
|
|
38
41
|
"require": "./add-array-elements-to-set/index.cjs",
|
|
39
42
|
"default": "./add-array-elements-to-set/index.cjs"
|
|
40
43
|
},
|
|
41
|
-
"./
|
|
42
|
-
"types": "./
|
|
44
|
+
"./ahocorasick": {
|
|
45
|
+
"types": "./ahocorasick/index.d.ts",
|
|
43
46
|
"import": {
|
|
44
|
-
"types": "./
|
|
45
|
-
"default": "./
|
|
47
|
+
"types": "./ahocorasick/index.d.ts",
|
|
48
|
+
"default": "./ahocorasick/index.mjs"
|
|
46
49
|
},
|
|
47
|
-
"require": "./
|
|
48
|
-
"default": "./
|
|
50
|
+
"require": "./ahocorasick/index.cjs",
|
|
51
|
+
"default": "./ahocorasick/index.cjs"
|
|
49
52
|
},
|
|
50
53
|
"./async-write-to-stream": {
|
|
51
54
|
"types": "./async-write-to-stream/index.d.ts",
|
|
@@ -65,14 +68,23 @@
|
|
|
65
68
|
"require": "./bitwise/index.cjs",
|
|
66
69
|
"default": "./bitwise/index.cjs"
|
|
67
70
|
},
|
|
68
|
-
"./
|
|
69
|
-
"types": "./
|
|
71
|
+
"./create-fixed-array": {
|
|
72
|
+
"types": "./create-fixed-array/index.d.ts",
|
|
70
73
|
"import": {
|
|
71
|
-
"types": "./
|
|
72
|
-
"default": "./
|
|
74
|
+
"types": "./create-fixed-array/index.d.ts",
|
|
75
|
+
"default": "./create-fixed-array/index.mjs"
|
|
73
76
|
},
|
|
74
|
-
"require": "./
|
|
75
|
-
"default": "./
|
|
77
|
+
"require": "./create-fixed-array/index.cjs",
|
|
78
|
+
"default": "./create-fixed-array/index.cjs"
|
|
79
|
+
},
|
|
80
|
+
"./append-set-elements-to-array": {
|
|
81
|
+
"types": "./append-set-elements-to-array/index.d.ts",
|
|
82
|
+
"import": {
|
|
83
|
+
"types": "./append-set-elements-to-array/index.d.ts",
|
|
84
|
+
"default": "./append-set-elements-to-array/index.mjs"
|
|
85
|
+
},
|
|
86
|
+
"require": "./append-set-elements-to-array/index.cjs",
|
|
87
|
+
"default": "./append-set-elements-to-array/index.cjs"
|
|
76
88
|
},
|
|
77
89
|
"./escape-string-regexp": {
|
|
78
90
|
"types": "./escape-string-regexp/index.d.ts",
|
|
@@ -110,15 +122,6 @@
|
|
|
110
122
|
"require": "./fnv1a/index.cjs",
|
|
111
123
|
"default": "./fnv1a/index.cjs"
|
|
112
124
|
},
|
|
113
|
-
"./fnv1a52": {
|
|
114
|
-
"types": "./fnv1a52/index.d.ts",
|
|
115
|
-
"import": {
|
|
116
|
-
"types": "./fnv1a52/index.d.ts",
|
|
117
|
-
"default": "./fnv1a52/index.mjs"
|
|
118
|
-
},
|
|
119
|
-
"require": "./fnv1a52/index.cjs",
|
|
120
|
-
"default": "./fnv1a52/index.cjs"
|
|
121
|
-
},
|
|
122
125
|
"./guard": {
|
|
123
126
|
"types": "./guard/index.d.ts",
|
|
124
127
|
"import": {
|
|
@@ -128,6 +131,15 @@
|
|
|
128
131
|
"require": "./guard/index.cjs",
|
|
129
132
|
"default": "./guard/index.cjs"
|
|
130
133
|
},
|
|
134
|
+
"./fnv1a52": {
|
|
135
|
+
"types": "./fnv1a52/index.d.ts",
|
|
136
|
+
"import": {
|
|
137
|
+
"types": "./fnv1a52/index.d.ts",
|
|
138
|
+
"default": "./fnv1a52/index.mjs"
|
|
139
|
+
},
|
|
140
|
+
"require": "./fnv1a52/index.cjs",
|
|
141
|
+
"default": "./fnv1a52/index.cjs"
|
|
142
|
+
},
|
|
131
143
|
"./headers-to-object": {
|
|
132
144
|
"types": "./headers-to-object/index.d.ts",
|
|
133
145
|
"import": {
|
|
@@ -137,15 +149,6 @@
|
|
|
137
149
|
"require": "./headers-to-object/index.cjs",
|
|
138
150
|
"default": "./headers-to-object/index.cjs"
|
|
139
151
|
},
|
|
140
|
-
"./is-probably-ip": {
|
|
141
|
-
"types": "./is-probably-ip/index.d.ts",
|
|
142
|
-
"import": {
|
|
143
|
-
"types": "./is-probably-ip/index.d.ts",
|
|
144
|
-
"default": "./is-probably-ip/index.mjs"
|
|
145
|
-
},
|
|
146
|
-
"require": "./is-probably-ip/index.cjs",
|
|
147
|
-
"default": "./is-probably-ip/index.cjs"
|
|
148
|
-
},
|
|
149
152
|
"./identity": {
|
|
150
153
|
"types": "./identity/index.d.ts",
|
|
151
154
|
"import": {
|
|
@@ -155,6 +158,15 @@
|
|
|
155
158
|
"require": "./identity/index.cjs",
|
|
156
159
|
"default": "./identity/index.cjs"
|
|
157
160
|
},
|
|
161
|
+
"./is-probably-ip": {
|
|
162
|
+
"types": "./is-probably-ip/index.d.ts",
|
|
163
|
+
"import": {
|
|
164
|
+
"types": "./is-probably-ip/index.d.ts",
|
|
165
|
+
"default": "./is-probably-ip/index.mjs"
|
|
166
|
+
},
|
|
167
|
+
"require": "./is-probably-ip/index.cjs",
|
|
168
|
+
"default": "./is-probably-ip/index.cjs"
|
|
169
|
+
},
|
|
158
170
|
"./merge-headers": {
|
|
159
171
|
"types": "./merge-headers/index.d.ts",
|
|
160
172
|
"import": {
|
|
@@ -173,15 +185,6 @@
|
|
|
173
185
|
"require": "./noop/index.cjs",
|
|
174
186
|
"default": "./noop/index.cjs"
|
|
175
187
|
},
|
|
176
|
-
"./repool": {
|
|
177
|
-
"types": "./repool/index.d.ts",
|
|
178
|
-
"import": {
|
|
179
|
-
"types": "./repool/index.d.ts",
|
|
180
|
-
"default": "./repool/index.mjs"
|
|
181
|
-
},
|
|
182
|
-
"require": "./repool/index.cjs",
|
|
183
|
-
"default": "./repool/index.cjs"
|
|
184
|
-
},
|
|
185
188
|
"./once": {
|
|
186
189
|
"types": "./once/index.d.ts",
|
|
187
190
|
"import": {
|
|
@@ -191,14 +194,32 @@
|
|
|
191
194
|
"require": "./once/index.cjs",
|
|
192
195
|
"default": "./once/index.cjs"
|
|
193
196
|
},
|
|
194
|
-
"./
|
|
195
|
-
"types": "./
|
|
197
|
+
"./pick-random": {
|
|
198
|
+
"types": "./pick-random/index.d.ts",
|
|
196
199
|
"import": {
|
|
197
|
-
"types": "./
|
|
198
|
-
"default": "./
|
|
200
|
+
"types": "./pick-random/index.d.ts",
|
|
201
|
+
"default": "./pick-random/index.mjs"
|
|
199
202
|
},
|
|
200
|
-
"require": "./
|
|
201
|
-
"default": "./
|
|
203
|
+
"require": "./pick-random/index.cjs",
|
|
204
|
+
"default": "./pick-random/index.cjs"
|
|
205
|
+
},
|
|
206
|
+
"./random-int": {
|
|
207
|
+
"types": "./random-int/index.d.ts",
|
|
208
|
+
"import": {
|
|
209
|
+
"types": "./random-int/index.d.ts",
|
|
210
|
+
"default": "./random-int/index.mjs"
|
|
211
|
+
},
|
|
212
|
+
"require": "./random-int/index.cjs",
|
|
213
|
+
"default": "./random-int/index.cjs"
|
|
214
|
+
},
|
|
215
|
+
"./repool": {
|
|
216
|
+
"types": "./repool/index.d.ts",
|
|
217
|
+
"import": {
|
|
218
|
+
"types": "./repool/index.d.ts",
|
|
219
|
+
"default": "./repool/index.mjs"
|
|
220
|
+
},
|
|
221
|
+
"require": "./repool/index.cjs",
|
|
222
|
+
"default": "./repool/index.cjs"
|
|
202
223
|
},
|
|
203
224
|
"./retrie": {
|
|
204
225
|
"types": "./retrie/index.d.ts",
|
|
@@ -209,6 +230,15 @@
|
|
|
209
230
|
"require": "./retrie/index.cjs",
|
|
210
231
|
"default": "./retrie/index.cjs"
|
|
211
232
|
},
|
|
233
|
+
"./serialized-memo": {
|
|
234
|
+
"types": "./serialized-memo/index.d.ts",
|
|
235
|
+
"import": {
|
|
236
|
+
"types": "./serialized-memo/index.d.ts",
|
|
237
|
+
"default": "./serialized-memo/index.mjs"
|
|
238
|
+
},
|
|
239
|
+
"require": "./serialized-memo/index.cjs",
|
|
240
|
+
"default": "./serialized-memo/index.cjs"
|
|
241
|
+
},
|
|
212
242
|
"./simple-string-hash": {
|
|
213
243
|
"types": "./simple-string-hash/index.d.ts",
|
|
214
244
|
"import": {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("node:crypto"),r=require("../random-int/index.cjs");function n(e){return function(r,n=1){if(n>r.length)throw TypeError("Count must be lower or the same as the number of picks");const t=r.slice(),o=[];for(;n--;)1===t.length?o.push(t[0]):o.push(t.splice(e(0,t.length-1),1)[0]);return o}}require("uncrypto");const t=n(e.randomInt),o=n(r.randomIntSecure);function c(e){return function(r){return 1===r.length?r[0]:r[e(0,r.length-1)]}}const u=c(e.randomInt);exports.createPickOne=c,exports.createPickRandom=n,exports.pickOne=u,exports.pickRandom=t,exports.pickRandomSecure=o;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param randomInt - a random generate function that accepts two arguments `min` and `max` and returns a random number between `min` and `max`
|
|
3
|
+
*/
|
|
4
|
+
declare function createPickRandom(randomInt: (min: number, max: number) => number): <T>(data: T[] | readonly T[], count?: number) => T[];
|
|
5
|
+
declare const pickRandom: <T>(data: T[] | readonly T[], count?: number) => T[];
|
|
6
|
+
declare const pickRandomSecure: <T>(data: T[] | readonly T[], count?: number) => T[];
|
|
7
|
+
declare function createPickOne(randomInt: (min: number, max: number) => number): <T>(data: T[] | readonly T[]) => T;
|
|
8
|
+
declare const pickOne: <T>(data: T[] | readonly T[]) => T;
|
|
9
|
+
|
|
10
|
+
export { createPickOne, createPickRandom, pickOne, pickRandom, pickRandomSecure };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{randomInt as n}from"node:crypto";import{randomIntSecure as t}from"../random-int/index.mjs";import"uncrypto";function e(n){return function(t,e=1){if(e>t.length)throw TypeError("Count must be lower or the same as the number of picks");const r=t.slice(),o=[];for(;e--;)1===r.length?o.push(r[0]):o.push(r.splice(n(0,r.length-1),1)[0]);return o}}const r=e(n),o=e(t);function c(n){return function(t){return 1===t.length?t[0]:t[n(0,t.length-1)]}}const i=c(n);export{c as createPickOne,e as createPickRandom,i as pickOne,r as pickRandom,o as pickRandomSecure};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var r=require("uncrypto");function t(r){return(t,n)=>Math.floor(r()*(n-t+1))+t}const n=t(Math.random),e=t(function(){const t=new Uint32Array(1);return r.getRandomValues(t),t[0]/0x100000000});exports.createRandomInt=t,exports.randomInt=n,exports.randomIntSecure=e;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param random - a random generate function that returns a number between 0 and 1
|
|
3
|
+
*/
|
|
4
|
+
declare function createRandomInt(random: () => number): (min: number, max: number) => number;
|
|
5
|
+
declare const randomInt: (min: number, max: number) => number;
|
|
6
|
+
declare const randomIntSecure: (min: number, max: number) => number;
|
|
7
|
+
|
|
8
|
+
export { createRandomInt, randomInt, randomIntSecure };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getRandomValues as n}from"uncrypto";function r(n){return(r,t)=>Math.floor(n()*(t-r+1))+r}const t=r(Math.random),o=r(function(){const r=new Uint32Array(1);return n(r),r[0]/0x100000000});export{r as createRandomInt,t as randomInt,o as randomIntSecure};
|