foxts 1.2.0 → 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/package.json +70 -49
- 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
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,23 @@
|
|
|
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"
|
|
52
|
+
},
|
|
53
|
+
"./async-write-to-stream": {
|
|
54
|
+
"types": "./async-write-to-stream/index.d.ts",
|
|
55
|
+
"import": {
|
|
56
|
+
"types": "./async-write-to-stream/index.d.ts",
|
|
57
|
+
"default": "./async-write-to-stream/index.mjs"
|
|
58
|
+
},
|
|
59
|
+
"require": "./async-write-to-stream/index.cjs",
|
|
60
|
+
"default": "./async-write-to-stream/index.cjs"
|
|
49
61
|
},
|
|
50
62
|
"./bitwise": {
|
|
51
63
|
"types": "./bitwise/index.d.ts",
|
|
@@ -56,15 +68,6 @@
|
|
|
56
68
|
"require": "./bitwise/index.cjs",
|
|
57
69
|
"default": "./bitwise/index.cjs"
|
|
58
70
|
},
|
|
59
|
-
"./ahocorasick": {
|
|
60
|
-
"types": "./ahocorasick/index.d.ts",
|
|
61
|
-
"import": {
|
|
62
|
-
"types": "./ahocorasick/index.d.ts",
|
|
63
|
-
"default": "./ahocorasick/index.mjs"
|
|
64
|
-
},
|
|
65
|
-
"require": "./ahocorasick/index.cjs",
|
|
66
|
-
"default": "./ahocorasick/index.cjs"
|
|
67
|
-
},
|
|
68
71
|
"./create-fixed-array": {
|
|
69
72
|
"types": "./create-fixed-array/index.d.ts",
|
|
70
73
|
"import": {
|
|
@@ -74,6 +77,15 @@
|
|
|
74
77
|
"require": "./create-fixed-array/index.cjs",
|
|
75
78
|
"default": "./create-fixed-array/index.cjs"
|
|
76
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"
|
|
88
|
+
},
|
|
77
89
|
"./escape-string-regexp": {
|
|
78
90
|
"types": "./escape-string-regexp/index.d.ts",
|
|
79
91
|
"import": {
|
|
@@ -83,15 +95,6 @@
|
|
|
83
95
|
"require": "./escape-string-regexp/index.cjs",
|
|
84
96
|
"default": "./escape-string-regexp/index.cjs"
|
|
85
97
|
},
|
|
86
|
-
"./async-write-to-stream": {
|
|
87
|
-
"types": "./async-write-to-stream/index.d.ts",
|
|
88
|
-
"import": {
|
|
89
|
-
"types": "./async-write-to-stream/index.d.ts",
|
|
90
|
-
"default": "./async-write-to-stream/index.mjs"
|
|
91
|
-
},
|
|
92
|
-
"require": "./async-write-to-stream/index.cjs",
|
|
93
|
-
"default": "./async-write-to-stream/index.cjs"
|
|
94
|
-
},
|
|
95
98
|
"./fast-string-array-join": {
|
|
96
99
|
"types": "./fast-string-array-join/index.d.ts",
|
|
97
100
|
"import": {
|
|
@@ -119,15 +122,6 @@
|
|
|
119
122
|
"require": "./fnv1a/index.cjs",
|
|
120
123
|
"default": "./fnv1a/index.cjs"
|
|
121
124
|
},
|
|
122
|
-
"./headers-to-object": {
|
|
123
|
-
"types": "./headers-to-object/index.d.ts",
|
|
124
|
-
"import": {
|
|
125
|
-
"types": "./headers-to-object/index.d.ts",
|
|
126
|
-
"default": "./headers-to-object/index.mjs"
|
|
127
|
-
},
|
|
128
|
-
"require": "./headers-to-object/index.cjs",
|
|
129
|
-
"default": "./headers-to-object/index.cjs"
|
|
130
|
-
},
|
|
131
125
|
"./guard": {
|
|
132
126
|
"types": "./guard/index.d.ts",
|
|
133
127
|
"import": {
|
|
@@ -137,6 +131,24 @@
|
|
|
137
131
|
"require": "./guard/index.cjs",
|
|
138
132
|
"default": "./guard/index.cjs"
|
|
139
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
|
+
},
|
|
143
|
+
"./headers-to-object": {
|
|
144
|
+
"types": "./headers-to-object/index.d.ts",
|
|
145
|
+
"import": {
|
|
146
|
+
"types": "./headers-to-object/index.d.ts",
|
|
147
|
+
"default": "./headers-to-object/index.mjs"
|
|
148
|
+
},
|
|
149
|
+
"require": "./headers-to-object/index.cjs",
|
|
150
|
+
"default": "./headers-to-object/index.cjs"
|
|
151
|
+
},
|
|
140
152
|
"./identity": {
|
|
141
153
|
"types": "./identity/index.d.ts",
|
|
142
154
|
"import": {
|
|
@@ -182,14 +194,23 @@
|
|
|
182
194
|
"require": "./once/index.cjs",
|
|
183
195
|
"default": "./once/index.cjs"
|
|
184
196
|
},
|
|
185
|
-
"./
|
|
186
|
-
"types": "./
|
|
197
|
+
"./pick-random": {
|
|
198
|
+
"types": "./pick-random/index.d.ts",
|
|
187
199
|
"import": {
|
|
188
|
-
"types": "./
|
|
189
|
-
"default": "./
|
|
200
|
+
"types": "./pick-random/index.d.ts",
|
|
201
|
+
"default": "./pick-random/index.mjs"
|
|
190
202
|
},
|
|
191
|
-
"require": "./
|
|
192
|
-
"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"
|
|
193
214
|
},
|
|
194
215
|
"./repool": {
|
|
195
216
|
"types": "./repool/index.d.ts",
|
|
@@ -218,15 +239,6 @@
|
|
|
218
239
|
"require": "./serialized-memo/index.cjs",
|
|
219
240
|
"default": "./serialized-memo/index.cjs"
|
|
220
241
|
},
|
|
221
|
-
"./tagged": {
|
|
222
|
-
"types": "./tagged/index.d.ts",
|
|
223
|
-
"import": {
|
|
224
|
-
"types": "./tagged/index.d.ts",
|
|
225
|
-
"default": "./tagged/index.mjs"
|
|
226
|
-
},
|
|
227
|
-
"require": "./tagged/index.cjs",
|
|
228
|
-
"default": "./tagged/index.cjs"
|
|
229
|
-
},
|
|
230
242
|
"./simple-string-hash": {
|
|
231
243
|
"types": "./simple-string-hash/index.d.ts",
|
|
232
244
|
"import": {
|
|
@@ -236,6 +248,15 @@
|
|
|
236
248
|
"require": "./simple-string-hash/index.cjs",
|
|
237
249
|
"default": "./simple-string-hash/index.cjs"
|
|
238
250
|
},
|
|
251
|
+
"./tagged": {
|
|
252
|
+
"types": "./tagged/index.d.ts",
|
|
253
|
+
"import": {
|
|
254
|
+
"types": "./tagged/index.d.ts",
|
|
255
|
+
"default": "./tagged/index.mjs"
|
|
256
|
+
},
|
|
257
|
+
"require": "./tagged/index.cjs",
|
|
258
|
+
"default": "./tagged/index.cjs"
|
|
259
|
+
},
|
|
239
260
|
"./wait": {
|
|
240
261
|
"types": "./wait/index.d.ts",
|
|
241
262
|
"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};
|