@jackens/nnn 2025.2.2 → 2025.2.4
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/nnn.d.ts +1 -10
- package/nnn.js +1 -23
- package/package.json +1 -1
- package/readme.md +6 -53
package/nnn.d.ts
CHANGED
|
@@ -163,18 +163,9 @@ export declare const plUral: (singular: string, plural2: string, plural5: string
|
|
|
163
163
|
* object.
|
|
164
164
|
*/
|
|
165
165
|
export declare const pro: (ref: unknown) => any;
|
|
166
|
-
/**
|
|
167
|
-
* A helper that provides information about the given `refs`.
|
|
168
|
-
*
|
|
169
|
-
* It returns an array of triples: `[«name», «prototype-name», «array-of-own-property-names»]`.
|
|
170
|
-
*/
|
|
171
|
-
export declare const refsInfo: (...refs: Partial<Array<unknown>>) => Partial<Array<[string, string, Partial<Array<string>>]>>;
|
|
172
166
|
/**
|
|
173
167
|
* A helper that generates a UUID v1 identifier (with a creation timestamp).
|
|
174
168
|
*
|
|
175
169
|
* - The optional `node` parameter should have the format `/^[0123456789abcdef]+$/`. Its value will be trimmed to last 12 characters and left padded with zeros.
|
|
176
170
|
*/
|
|
177
|
-
export declare const uuid1: (
|
|
178
|
-
date?: Date | undefined;
|
|
179
|
-
node?: string | undefined;
|
|
180
|
-
}) => string;
|
|
171
|
+
export declare const uuid1: (date?: Date, node?: string) => string;
|
package/nnn.js
CHANGED
|
@@ -229,31 +229,10 @@ var pro = (ref) => new Proxy(ref, {
|
|
|
229
229
|
return pro(target[key] = target[key] ?? {});
|
|
230
230
|
}
|
|
231
231
|
});
|
|
232
|
-
// src/nnn/refsInfo.ts
|
|
233
|
-
var refsInfo = (...refs) => {
|
|
234
|
-
const fns = new Set;
|
|
235
|
-
refs.forEach((ref) => {
|
|
236
|
-
try {
|
|
237
|
-
while (ref instanceof Function && !fns.has(ref) && `${ref}`.match(/function\s+\w+[\s\S]+\[native code\]/)) {
|
|
238
|
-
fns.add(ref);
|
|
239
|
-
ref = Object.getPrototypeOf(ref);
|
|
240
|
-
}
|
|
241
|
-
} catch {
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
return Array.from(fns.values()).map((fn) => [
|
|
245
|
-
fn.name,
|
|
246
|
-
Object.getPrototypeOf(fn)?.name ?? "",
|
|
247
|
-
Object.getOwnPropertyNames(fn.prototype ?? Object.create(null)).sort()
|
|
248
|
-
]).sort((a, b) => -(a[0] < b[0]));
|
|
249
|
-
};
|
|
250
232
|
// src/nnn/uuid1.ts
|
|
251
233
|
var ZEROS = "0".repeat(16);
|
|
252
234
|
var counter = 0;
|
|
253
|
-
var uuid1 = ({
|
|
254
|
-
date = new Date,
|
|
255
|
-
node = Math.random().toString(16).slice(2)
|
|
256
|
-
} = {}) => {
|
|
235
|
+
var uuid1 = (date = new Date, node = Math.random().toString(16).slice(2)) => {
|
|
257
236
|
const time = ZEROS + (1e4 * (+date + 12219292800000)).toString(16);
|
|
258
237
|
counter = counter + 1 & 16383;
|
|
259
238
|
return time.slice(-8).concat("-", time.slice(-12, -8), -1, time.slice(-15, -12), "-", (8 | counter >> 12).toString(16), (ZEROS + (counter & 4095).toString(16)).slice(-3), "-", (ZEROS + node).slice(-12));
|
|
@@ -262,7 +241,6 @@ export {
|
|
|
262
241
|
uuid1,
|
|
263
242
|
svgUse,
|
|
264
243
|
s,
|
|
265
|
-
refsInfo,
|
|
266
244
|
pro,
|
|
267
245
|
plUral,
|
|
268
246
|
pick,
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Jackens’ JavaScript helpers.
|
|
4
4
|
|
|
5
|
-
<sub>Version: <code class="version">2025.2.
|
|
5
|
+
<sub>Version: <code class="version">2025.2.4</code></sub>
|
|
6
6
|
|
|
7
7
|
* [Documentation](https://jackens.github.io/nnn/doc/)
|
|
8
8
|
* [Tests](https://jackens.github.io/nnn/test/)
|
|
@@ -37,7 +37,7 @@ import { «something» } from './node_modules/@jackens/nnn/nnn.js'
|
|
|
37
37
|
or
|
|
38
38
|
|
|
39
39
|
```js
|
|
40
|
-
import { «something» } from 'https://unpkg.com/@jackens/nnn@2025.2.
|
|
40
|
+
import { «something» } from 'https://unpkg.com/@jackens/nnn@2025.2.4/nnn.js'
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
## Exports
|
|
@@ -63,7 +63,6 @@ import { «something» } from 'https://unpkg.com/@jackens/nnn@2025.2.2/nnn.js'
|
|
|
63
63
|
- `pick`: A helper that implements TypeScript’s `Pick` utility type (see also `omit`).
|
|
64
64
|
- `plUral`: A helper for choosing the correct singular and plural.
|
|
65
65
|
- `pro`: A helper that protects calls to nested properties by a `Proxy` that initializes non-existent values with an empty
|
|
66
|
-
- `refsInfo`: A helper that provides information about the given `refs`.
|
|
67
66
|
- `s`: A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style helper for creating and modifying `SVGElement`s (see also `h`).
|
|
68
67
|
- `svgUse`: A convenient shortcut for `s('svg', ['use', { 'xlink:href': '#' + id }], ...args)`.
|
|
69
68
|
- `uuid1`: A helper that generates a UUID v1 identifier (with a creation timestamp).
|
|
@@ -872,49 +871,6 @@ pro(ref).one.two.three.four = 1234
|
|
|
872
871
|
expect(ref).to.deep.equal({ one: { two: { three: { four: 1234 } } } })
|
|
873
872
|
```
|
|
874
873
|
|
|
875
|
-
### refsInfo
|
|
876
|
-
|
|
877
|
-
```ts
|
|
878
|
-
const refsInfo: (...refs: Partial<Array<unknown>>) => Partial<Array<[string, string, Partial<Array<string>>]>>;
|
|
879
|
-
```
|
|
880
|
-
|
|
881
|
-
A helper that provides information about the given `refs`.
|
|
882
|
-
|
|
883
|
-
It returns an array of triples: `[«name», «prototype-name», «array-of-own-property-names»]`.
|
|
884
|
-
|
|
885
|
-
#### Usage Examples
|
|
886
|
-
|
|
887
|
-
```js
|
|
888
|
-
const info = refsInfo(Array, Function)
|
|
889
|
-
|
|
890
|
-
expect(info.find(item => item?.[0] === 'Array')?.[2]?.includes('length')).to.be.true
|
|
891
|
-
expect(info.find(item => item?.[0] === 'Function')?.[2]?.includes('length')).to.be.true
|
|
892
|
-
```
|
|
893
|
-
|
|
894
|
-
```js
|
|
895
|
-
const browserFingerprint = () => {
|
|
896
|
-
const refs = Object.getOwnPropertyNames(window).map(name => window[name])
|
|
897
|
-
const info = refsInfo(...refs)
|
|
898
|
-
const json = JSON.stringify(info)
|
|
899
|
-
const hash = Array(32).fill(0)
|
|
900
|
-
let j = 0
|
|
901
|
-
|
|
902
|
-
for (let i = 0; i < json.length; i++) {
|
|
903
|
-
let charCode = json.charCodeAt(i)
|
|
904
|
-
|
|
905
|
-
while (charCode > 0) {
|
|
906
|
-
hash[j] = hash[j] ^ (charCode & 15)
|
|
907
|
-
charCode >>= 4
|
|
908
|
-
j = (j + 1) & 31
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
return hash.map(x => x.toString(16)).join('')
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
console.log(browserFingerprint())
|
|
916
|
-
```
|
|
917
|
-
|
|
918
874
|
### s
|
|
919
875
|
|
|
920
876
|
```ts
|
|
@@ -946,10 +902,7 @@ A convenient shortcut for `s('svg', ['use', { 'xlink:href': '#' + id }], ...args
|
|
|
946
902
|
### uuid1
|
|
947
903
|
|
|
948
904
|
```ts
|
|
949
|
-
const uuid1: (
|
|
950
|
-
date?: Date | undefined;
|
|
951
|
-
node?: string | undefined;
|
|
952
|
-
}) => string;
|
|
905
|
+
const uuid1: (date?: Date, node?: string) => string;
|
|
953
906
|
```
|
|
954
907
|
|
|
955
908
|
A helper that generates a UUID v1 identifier (with a creation timestamp).
|
|
@@ -973,12 +926,12 @@ for (let i = 1; i <= 22136; ++i) {
|
|
|
973
926
|
```
|
|
974
927
|
|
|
975
928
|
```js
|
|
976
|
-
expect(uuid1(
|
|
977
|
-
expect(uuid1(
|
|
929
|
+
expect(uuid1(new Date(), '000123456789abc').split('-')[4]).to.deep.equal('123456789abc')
|
|
930
|
+
expect(uuid1(new Date(), '123456789').split('-')[4]).to.deep.equal('000123456789')
|
|
978
931
|
```
|
|
979
932
|
|
|
980
933
|
```js
|
|
981
|
-
expect(uuid1(
|
|
934
|
+
expect(uuid1(new Date(323325000000)).startsWith('c1399400-9a71-11bd')).to.be.true
|
|
982
935
|
```
|
|
983
936
|
|
|
984
937
|
## Why Partial\<Array\> and Partial\<Record\>
|