@jackens/nnn 2024.2.11 → 2024.2.12
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/eq.d.ts +1 -1
- package/eq.js +26 -26
- package/escape.d.ts +1 -1
- package/escape.js +2 -2
- package/fixTypography.d.ts +1 -1
- package/fixTypography.js +2 -2
- package/h.d.ts +5 -5
- package/h.js +29 -30
- package/has.d.ts +2 -2
- package/has.js +13 -13
- package/is.d.ts +2 -2
- package/is.js +27 -27
- package/jcss.d.ts +6 -6
- package/jcss.js +12 -12
- package/jsOnParse.d.ts +1 -1
- package/jsOnParse.js +2 -3
- package/locale.d.ts +1 -1
- package/locale.js +9 -9
- package/nanolightJs.d.ts +1 -1
- package/nanolightJs.js +2 -2
- package/nnn.d.ts +3 -1
- package/nnn.js +5 -1
- package/package.json +1 -1
- package/pick.d.ts +14 -0
- package/pick.js +57 -0
- package/plUral.d.ts +1 -1
- package/plUral.js +9 -9
- package/pro.d.ts +1 -1
- package/pro.js +7 -9
- package/readme.md +164 -130
- package/refsInfo.d.ts +2 -2
- package/refsInfo.js +4 -4
- package/uuid1.d.ts +3 -3
- package/uuid1.js +13 -13
- package/tests.d.ts +0 -30
- package/tests.js +0 -35
package/readme.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Jackens’ JavaScript helpers.
|
|
4
4
|
|
|
5
|
-
<sub>Version: <code class="version">2024.2.
|
|
5
|
+
<sub>Version: <code class="version">2024.2.12</code></sub>
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -50,6 +50,8 @@ import { «something» } from './node_modules/@jackens/nnn/nnn.js'
|
|
|
50
50
|
- `locale`: Language translations helper.
|
|
51
51
|
- `nanolight`: A generic helper for syntax highlighting (see also `nanolightJs`).
|
|
52
52
|
- `nanolightJs`: A helper for highlighting JavaScript.
|
|
53
|
+
- `omit`: A helper that implements TypeScript’s `Omit` utility type.
|
|
54
|
+
- `pick`: A helper that implements TypeScript’s `Pick` utility type.
|
|
53
55
|
- `plUral`: A helper for choosing the correct singular and plural.
|
|
54
56
|
- `pro`: A helper that protects calls to nested properties by a `Proxy` that initializes non-existent values with an empty object.
|
|
55
57
|
- `refsInfo`: A helper that provides information about the given `refs`.
|
|
@@ -148,35 +150,35 @@ A helper that checks equality of the given arguments.
|
|
|
148
150
|
#### Usage Examples
|
|
149
151
|
|
|
150
152
|
```js
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
153
|
+
expect(eq(true, true)).toBe(true)
|
|
154
|
+
expect(eq(NaN, NaN)).toBe(true)
|
|
155
|
+
expect(eq(null, undefined)).toBe(false)
|
|
156
|
+
expect(eq(42, 42)).toBe(true)
|
|
157
|
+
expect(eq(42, new Number(42))).toBe(true)
|
|
158
|
+
expect(eq(42, Number(42))).toBe(true)
|
|
159
|
+
expect(eq(new Number(42), Number(42))).toBe(true)
|
|
160
|
+
expect(eq(42, '42')).toBe(false)
|
|
161
|
+
expect(eq('42', '42')).toBe(true)
|
|
162
|
+
expect(eq('42', new String('42'))).toBe(true)
|
|
163
|
+
expect(eq('42', String('42'))).toBe(true)
|
|
164
|
+
expect(eq(String('42'), new String('42'))).toBe(true)
|
|
165
|
+
expect(eq(/42/, /42/)).toBe(true)
|
|
166
|
+
expect(eq(/42/, /42/g)).toBe(false)
|
|
167
|
+
expect(eq(new Date(42), new Date(42))).toBe(true)
|
|
168
|
+
expect(eq(new Date(), new Date(42))).toBe(false)
|
|
169
|
+
expect(eq({ j: '42', c: 42 }, { c: 42, j: '42' })).toBe(true)
|
|
170
|
+
expect(eq([42, '42'], [42, '42'])).toBe(true)
|
|
171
|
+
expect(eq(new Set(['42', 42]), new Set([42, '42']))).toBe(true)
|
|
172
|
+
expect(eq(new Set(['42', 42]), new Set([42]))).toBe(false)
|
|
173
|
+
expect(eq(new Set([42, undefined]), new Set([42]))).toBe(false)
|
|
174
|
+
expect(eq(
|
|
173
175
|
new Map([[{ j: 42 }, { J: '42' }], [{ c: 42 }, { C: '42' }]]),
|
|
174
176
|
new Map([[{ c: 42 }, { C: '42' }], [{ j: 42 }, { J: '42' }]])
|
|
175
|
-
))
|
|
176
|
-
|
|
177
|
+
)).toBe(true)
|
|
178
|
+
expect(eq(
|
|
177
179
|
new Map([[{ j: 42 }, { J: '42' }], [{ c: 42 }, { C: '42' }]]),
|
|
178
180
|
new Map([[{ j: '42' }, { J: 42 }], [{ c: '42' }, { C: 42 }]])
|
|
179
|
-
))
|
|
181
|
+
)).toBe(false)
|
|
180
182
|
```
|
|
181
183
|
|
|
182
184
|
### escape
|
|
@@ -211,7 +213,7 @@ const expected = `
|
|
|
211
213
|
FROM table_name
|
|
212
214
|
WHERE column_name IN (b'1', NULL, NULL, 42, '42', '4''2', NULL, '1980-03-31 04:30:00')`
|
|
213
215
|
|
|
214
|
-
|
|
216
|
+
expect(actual).toEqual(expected)
|
|
215
217
|
```
|
|
216
218
|
|
|
217
219
|
### escapeValues
|
|
@@ -237,7 +239,7 @@ const p = h('p', 'Pchnąć w tę łódź jeża lub ośm skrzyń fig (zob. https:
|
|
|
237
239
|
|
|
238
240
|
fixTypography(p)
|
|
239
241
|
|
|
240
|
-
|
|
242
|
+
expect(p.innerHTML).toEqual(
|
|
241
243
|
'Pchnąć <span style="white-space:nowrap">w </span>tę łódź jeża lub ośm skrzyń fig ' +
|
|
242
244
|
'(zob. https://\u200Bpl.\u200Bwikipedia.\u200Borg/\u200Bwiki/\u200BPangram).')
|
|
243
245
|
```
|
|
@@ -269,67 +271,67 @@ A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style help
|
|
|
269
271
|
```js
|
|
270
272
|
const b = h('b')
|
|
271
273
|
|
|
272
|
-
|
|
274
|
+
expect(b.outerHTML).toEqual('<b></b>')
|
|
273
275
|
|
|
274
276
|
const i = h('i', 'text')
|
|
275
277
|
|
|
276
278
|
h(b, i)
|
|
277
279
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
+
expect(i.outerHTML).toEqual('<i>text</i>')
|
|
281
|
+
expect(b.outerHTML).toEqual('<b><i>text</i></b>')
|
|
280
282
|
|
|
281
283
|
h(i, { $className: 'some class' })
|
|
282
284
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
+
expect(i.outerHTML).toEqual('<i class="some class">text</i>')
|
|
286
|
+
expect(b.outerHTML).toEqual('<b><i class="some class">text</i></b>')
|
|
285
287
|
```
|
|
286
288
|
|
|
287
289
|
```js
|
|
288
|
-
|
|
289
|
-
|
|
290
|
+
expect(h('span', 'text').outerHTML).toEqual('<span>text</span>')
|
|
291
|
+
expect(h('span', { $innerText: 'text' }).outerHTML).toEqual('<span>text</span>')
|
|
290
292
|
```
|
|
291
293
|
|
|
292
294
|
```js
|
|
293
|
-
|
|
294
|
-
'<div style="margin:0;padding:0"></div>')
|
|
295
|
-
|
|
296
|
-
'<div style="margin: 0px; padding: 0px;"></div>')
|
|
297
|
-
|
|
298
|
-
'<div style="margin: 0px; padding: 0px;"></div>')
|
|
295
|
+
expect(h('div', { style: 'margin:0;padding:0' }).outerHTML)
|
|
296
|
+
.toEqual('<div style="margin:0;padding:0"></div>')
|
|
297
|
+
expect(h('div', { $style: 'margin:0;padding:0' }).outerHTML)
|
|
298
|
+
.toEqual('<div style="margin: 0px; padding: 0px;"></div>')
|
|
299
|
+
expect(h('div', { $style: { margin: 0, padding: 0 } }).outerHTML)
|
|
300
|
+
.toEqual('<div style="margin: 0px; padding: 0px;"></div>')
|
|
299
301
|
```
|
|
300
302
|
|
|
301
303
|
```js
|
|
302
304
|
const input1 = h('input', { value: 42 })
|
|
303
305
|
const input2 = h('input', { $value: '42' })
|
|
304
306
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
+
expect(input1.value).toEqual('42')
|
|
308
|
+
expect(input2.value).toEqual('42')
|
|
307
309
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
+
expect(input1.outerHTML).toEqual('<input value="42">')
|
|
311
|
+
expect(input2.outerHTML).toEqual('<input>')
|
|
310
312
|
|
|
311
313
|
const checkbox1 = h('input', { type: 'checkbox', checked: true })
|
|
312
314
|
const checkbox2 = h('input', { type: 'checkbox', $checked: true })
|
|
313
315
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
+
expect(checkbox1.checked).toBe(true)
|
|
317
|
+
expect(checkbox2.checked).toBe(true)
|
|
316
318
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
+
expect(checkbox1.outerHTML).toEqual('<input type="checkbox" checked="">')
|
|
320
|
+
expect(checkbox2.outerHTML).toEqual('<input type="checkbox">')
|
|
319
321
|
```
|
|
320
322
|
|
|
321
323
|
```js
|
|
322
324
|
const div = h('div')
|
|
323
325
|
|
|
324
|
-
|
|
326
|
+
expect(div.key).toBeUndefined()
|
|
325
327
|
|
|
326
328
|
h(div, { $key: { one: 1 } })
|
|
327
329
|
|
|
328
|
-
|
|
330
|
+
expect(div.key).toEqual({ one: 1 })
|
|
329
331
|
|
|
330
332
|
h(div, { $key: { two: 2 } })
|
|
331
333
|
|
|
332
|
-
|
|
334
|
+
expect(div.key).toEqual({ one: 1, two: 2 })
|
|
333
335
|
```
|
|
334
336
|
|
|
335
337
|
### has
|
|
@@ -345,30 +347,30 @@ A replacement for the `in` operator (not to be confused with the `for-in` loop)
|
|
|
345
347
|
```js
|
|
346
348
|
const obj = { key: 'K', null: 'N' }
|
|
347
349
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
+
expect('key' in obj).toBe(true)
|
|
351
|
+
expect(has('key', obj)).toBe(true)
|
|
350
352
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
+
expect('null' in obj).toBe(true)
|
|
354
|
+
expect(has('null', obj)).toBe(true)
|
|
353
355
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
+
expect(null in obj).toBe(true)
|
|
357
|
+
expect(has(null, obj)).toBe(false)
|
|
356
358
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
+
expect('toString' in obj).toBe(true)
|
|
360
|
+
expect(has('toString', obj)).toBe(false)
|
|
359
361
|
```
|
|
360
362
|
|
|
361
363
|
```js
|
|
362
364
|
let typeError
|
|
363
365
|
|
|
364
366
|
try {
|
|
365
|
-
|
|
367
|
+
'key' in null
|
|
366
368
|
} catch (error) {
|
|
367
369
|
typeError = error
|
|
368
370
|
}
|
|
369
371
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
+
expect(typeError instanceof TypeError) // Cannot use 'in' operator to search for 'key' in null
|
|
373
|
+
expect(has('key', null)).toBe(false)
|
|
372
374
|
```
|
|
373
375
|
|
|
374
376
|
### is
|
|
@@ -390,23 +392,23 @@ A helper that checks if the given argument is of a certain type.
|
|
|
390
392
|
#### Usage Examples
|
|
391
393
|
|
|
392
394
|
```js
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
395
|
+
expect(is(Number, 42)).toBe(true)
|
|
396
|
+
expect(is(Number, Number(42))).toBe(true)
|
|
397
|
+
expect(is(Number, new Number(42))).toBe(true)
|
|
398
|
+
expect(is(Number, NaN)).toBe(true)
|
|
399
|
+
expect(is(String, '42')).toBe(true)
|
|
400
|
+
expect(is(String, String('42'))).toBe(true)
|
|
401
|
+
expect(is(String, new String('42'))).toBe(true)
|
|
402
|
+
expect(is(Symbol, Symbol('42'))).toBe(true)
|
|
403
|
+
expect(is(Symbol, Object(Symbol('42')))).toBe(true)
|
|
404
|
+
expect(is(undefined, undefined)).toBe(true)
|
|
405
|
+
expect(is(undefined, null)).toBe(true)
|
|
406
|
+
expect(is(Object, {})).toBe(true)
|
|
407
|
+
expect(is(Array, [])).toBe(true)
|
|
408
|
+
expect(is(RegExp, /42/)).toBe(true)
|
|
409
|
+
expect(is(Date, new Date(42))).toBe(true)
|
|
410
|
+
expect(is(Set, new Set(['42', 42]))).toBe(true)
|
|
411
|
+
expect(is(Map, new Map([[{ j: 42 }, { J: '42' }], [{ c: 42 }, { C: '42' }]]))).toBe(true)
|
|
410
412
|
```
|
|
411
413
|
|
|
412
414
|
```js
|
|
@@ -414,21 +416,21 @@ const iz = (/** @type {any} */ type, /** @type {any} */ arg) => ({}).toString.ca
|
|
|
414
416
|
|
|
415
417
|
class FooBar { }
|
|
416
418
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
+
expect(is(FooBar, new FooBar())).toBe(true)
|
|
420
|
+
expect(iz(FooBar, new FooBar())).toBe(false)
|
|
419
421
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
+
expect(is(Object, new FooBar())).toBe(false)
|
|
423
|
+
expect(iz(Object, new FooBar())).toBe(true)
|
|
422
424
|
|
|
423
425
|
const fakeFooBar = {}
|
|
424
426
|
|
|
425
427
|
fakeFooBar[Symbol.toStringTag] = FooBar.name
|
|
426
428
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
+
expect(is(FooBar, fakeFooBar)).toBe(false)
|
|
430
|
+
expect(iz(FooBar, fakeFooBar)).toBe(true)
|
|
429
431
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
+
expect(is(Object, fakeFooBar)).toBe(true)
|
|
433
|
+
expect(iz(Object, fakeFooBar)).toBe(false)
|
|
432
434
|
```
|
|
433
435
|
|
|
434
436
|
### jcss
|
|
@@ -472,7 +474,7 @@ a{
|
|
|
472
474
|
padding:1
|
|
473
475
|
}`.replace(/\n\s*/g, '')
|
|
474
476
|
|
|
475
|
-
|
|
477
|
+
expect(actual).toEqual(expected)
|
|
476
478
|
```
|
|
477
479
|
|
|
478
480
|
```js
|
|
@@ -500,7 +502,7 @@ a.b{
|
|
|
500
502
|
padding:1
|
|
501
503
|
}`.replace(/\n\s*/g, '')
|
|
502
504
|
|
|
503
|
-
|
|
505
|
+
expect(actual).toEqual(expected)
|
|
504
506
|
```
|
|
505
507
|
|
|
506
508
|
```js
|
|
@@ -575,7 +577,7 @@ div.c2{
|
|
|
575
577
|
}
|
|
576
578
|
}`.replace(/\n\s*/g, '')
|
|
577
579
|
|
|
578
|
-
|
|
580
|
+
expect(actual).toEqual(expected)
|
|
579
581
|
```
|
|
580
582
|
|
|
581
583
|
```js
|
|
@@ -598,7 +600,7 @@ a.b.d,a.c.d{
|
|
|
598
600
|
margin:2
|
|
599
601
|
}`.replace(/\n\s*/g, '')
|
|
600
602
|
|
|
601
|
-
|
|
603
|
+
expect(actual).toEqual(expected)
|
|
602
604
|
```
|
|
603
605
|
|
|
604
606
|
```js
|
|
@@ -619,7 +621,7 @@ const expected = `
|
|
|
619
621
|
margin:2
|
|
620
622
|
}`.replace(/\n\s*/g, '')
|
|
621
623
|
|
|
622
|
-
|
|
624
|
+
expect(actual).toEqual(expected)
|
|
623
625
|
```
|
|
624
626
|
|
|
625
627
|
```js
|
|
@@ -640,7 +642,7 @@ const expected = `
|
|
|
640
642
|
margin:2
|
|
641
643
|
}`.replace(/\n\s*/g, '')
|
|
642
644
|
|
|
643
|
-
|
|
645
|
+
expect(actual).toEqual(expected)
|
|
644
646
|
```
|
|
645
647
|
|
|
646
648
|
### jsOnParse
|
|
@@ -705,7 +707,7 @@ const expected = [
|
|
|
705
707
|
}
|
|
706
708
|
]
|
|
707
709
|
|
|
708
|
-
|
|
710
|
+
expect(actual).toEqual(expected)
|
|
709
711
|
```
|
|
710
712
|
|
|
711
713
|
### locale
|
|
@@ -724,18 +726,18 @@ const _ = locale({
|
|
|
724
726
|
button: { Login: 'Zaloguj' }
|
|
725
727
|
}, 'default')
|
|
726
728
|
|
|
727
|
-
|
|
728
|
-
|
|
729
|
+
expect(_('Login')).toEqual('Login')
|
|
730
|
+
expect(_('Password')).toEqual('Hasło')
|
|
729
731
|
|
|
730
|
-
|
|
732
|
+
expect(_('Undefined text')).toEqual('Undefined text')
|
|
731
733
|
|
|
732
|
-
|
|
734
|
+
expect(_('Login', 'button')).toEqual('Zaloguj')
|
|
733
735
|
|
|
734
|
-
|
|
735
|
-
|
|
736
|
+
expect(_('Password', 'undefined_version')).toEqual('Hasło')
|
|
737
|
+
expect(_('Undefined text', 'undefined_version')).toEqual('Undefined text')
|
|
736
738
|
|
|
737
|
-
|
|
738
|
-
|
|
739
|
+
expect(_('toString')).toEqual('toString')
|
|
740
|
+
expect(_('toString', 'undefined_version')).toEqual('toString')
|
|
739
741
|
```
|
|
740
742
|
|
|
741
743
|
### nanolight
|
|
@@ -759,10 +761,42 @@ A helper for highlighting JavaScript.
|
|
|
759
761
|
```js
|
|
760
762
|
const codeJs = 'const answerToLifeTheUniverseAndEverything = 42'
|
|
761
763
|
|
|
762
|
-
|
|
764
|
+
expect(h('pre', ['code', ...nanolightJs(codeJs)]).outerHTML).toEqual(
|
|
763
765
|
'<pre><code><span class="keyword">const</span> <span class="literal">answerToLifeTheUniverseAndEverything</span> <span class="operator">=</span> <span class="number">42</span></code></pre>')
|
|
764
766
|
```
|
|
765
767
|
|
|
768
|
+
### omit
|
|
769
|
+
|
|
770
|
+
```ts
|
|
771
|
+
export const omit: <T extends Partial<Record<PropertyKey, any>>, K extends (keyof T)[]>(obj: T, keys: K) => Omit<T, K[number]>;
|
|
772
|
+
```
|
|
773
|
+
|
|
774
|
+
A helper that implements TypeScript’s `Omit` utility type.
|
|
775
|
+
|
|
776
|
+
#### Usage Examples
|
|
777
|
+
|
|
778
|
+
```js
|
|
779
|
+
const obj = { a: 42, b: '42', c: 17 }
|
|
780
|
+
|
|
781
|
+
expect(omit(obj, ['c'])).toEqual({ a: 42, b: '42' })
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
### pick
|
|
785
|
+
|
|
786
|
+
```ts
|
|
787
|
+
export const pick: <T extends Partial<Record<PropertyKey, any>>, K extends (keyof T)[]>(obj: T, keys: K) => Pick<T, K[number]>;
|
|
788
|
+
```
|
|
789
|
+
|
|
790
|
+
A helper that implements TypeScript’s `Pick` utility type.
|
|
791
|
+
|
|
792
|
+
#### Usage Examples
|
|
793
|
+
|
|
794
|
+
```js
|
|
795
|
+
const obj = { a: 42, b: '42', c: 17 }
|
|
796
|
+
|
|
797
|
+
expect(pick(obj, ['a', 'b'])).toEqual({ a: 42, b: '42' })
|
|
798
|
+
```
|
|
799
|
+
|
|
766
800
|
### plUral
|
|
767
801
|
|
|
768
802
|
```ts
|
|
@@ -776,17 +810,17 @@ A helper for choosing the correct singular and plural.
|
|
|
776
810
|
```js
|
|
777
811
|
const auto = plUral.bind(null, 'auto', 'auta', 'aut')
|
|
778
812
|
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
813
|
+
expect(auto(0)).toEqual('aut')
|
|
814
|
+
expect(auto(1)).toEqual('auto')
|
|
815
|
+
expect(auto(17)).toEqual('aut')
|
|
816
|
+
expect(auto(42)).toEqual('auta')
|
|
783
817
|
|
|
784
818
|
const car = plUral.bind(null, 'car', 'cars', 'cars')
|
|
785
819
|
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
820
|
+
expect(car(0)).toEqual('cars')
|
|
821
|
+
expect(car(1)).toEqual('car')
|
|
822
|
+
expect(car(17)).toEqual('cars')
|
|
823
|
+
expect(car(42)).toEqual('cars')
|
|
790
824
|
```
|
|
791
825
|
|
|
792
826
|
### pro
|
|
@@ -804,27 +838,27 @@ const ref = {}
|
|
|
804
838
|
|
|
805
839
|
pro(ref).one.two[3][4] = 1234
|
|
806
840
|
|
|
807
|
-
|
|
841
|
+
expect(ref).toEqual({ one: { two: { 3: { 4: 1234 } } } })
|
|
808
842
|
|
|
809
843
|
pro(ref).one.two.tree = 123
|
|
810
844
|
|
|
811
|
-
|
|
845
|
+
expect(ref).toEqual({ one: { two: { 3: { 4: 1234 }, tree: 123 } } })
|
|
812
846
|
|
|
813
847
|
pro(ref).one.two = undefined
|
|
814
848
|
|
|
815
|
-
|
|
849
|
+
expect(ref).toEqual({ one: { two: undefined } })
|
|
816
850
|
|
|
817
851
|
delete pro(ref).one.two
|
|
818
852
|
|
|
819
|
-
|
|
853
|
+
expect(ref).toEqual({ one: {} })
|
|
820
854
|
|
|
821
855
|
pro(ref).one.two.three.four
|
|
822
856
|
|
|
823
|
-
|
|
857
|
+
expect(ref).toEqual({ one: { two: { three: { four: {} } } } })
|
|
824
858
|
|
|
825
859
|
pro(ref).one.two.three.four = 1234
|
|
826
860
|
|
|
827
|
-
|
|
861
|
+
expect(ref).toEqual({ one: { two: { three: { four: 1234 } } } })
|
|
828
862
|
```
|
|
829
863
|
|
|
830
864
|
### refsInfo
|
|
@@ -842,8 +876,8 @@ It returns an array of triples: `[«name», «prototype-name», «array-of-own-p
|
|
|
842
876
|
```js
|
|
843
877
|
const info = refsInfo(Array, Function)
|
|
844
878
|
|
|
845
|
-
|
|
846
|
-
|
|
879
|
+
expect(info.find(([name]) => name === 'Array')?.[2]?.includes('length')).toBe(true)
|
|
880
|
+
expect(info.find(([name]) => name === 'Function')?.[2]?.includes('length')).toBe(true)
|
|
847
881
|
```
|
|
848
882
|
|
|
849
883
|
```js
|
|
@@ -912,23 +946,23 @@ A helper that generates a UUID v1 identifier (with a creation timestamp).
|
|
|
912
946
|
for (let i = 1; i <= 22136; ++i) {
|
|
913
947
|
const uuid = uuid1()
|
|
914
948
|
|
|
915
|
-
i === 1 &&
|
|
916
|
-
i === 4095 &&
|
|
917
|
-
i === 4096 &&
|
|
918
|
-
i === 9029 &&
|
|
919
|
-
i === 13398 &&
|
|
920
|
-
i === 16384 &&
|
|
921
|
-
i === 17767 &&
|
|
949
|
+
i === 1 && expect(uuid.split('-')[3]).toEqual('8001')
|
|
950
|
+
i === 4095 && expect(uuid.split('-')[3]).toEqual('8fff')
|
|
951
|
+
i === 4096 && expect(uuid.split('-')[3]).toEqual('9000')
|
|
952
|
+
i === 9029 && expect(uuid.split('-')[3]).toEqual('a345')
|
|
953
|
+
i === 13398 && expect(uuid.split('-')[3]).toEqual('b456')
|
|
954
|
+
i === 16384 && expect(uuid.split('-')[3]).toEqual('8000')
|
|
955
|
+
i === 17767 && expect(uuid.split('-')[3]).toEqual('8567')
|
|
922
956
|
}
|
|
923
957
|
```
|
|
924
958
|
|
|
925
959
|
```js
|
|
926
|
-
|
|
927
|
-
|
|
960
|
+
expect(uuid1({ node: '000123456789abc' }).split('-')[4]).toEqual('123456789abc')
|
|
961
|
+
expect(uuid1({ node: '123456789' }).split('-')[4]).toEqual('000123456789')
|
|
928
962
|
```
|
|
929
963
|
|
|
930
964
|
```js
|
|
931
|
-
|
|
965
|
+
expect(uuid1({ date: new Date(323325000000) })).toStartWith('c1399400-9a71-11bd')
|
|
932
966
|
```
|
|
933
967
|
|
|
934
968
|
## License
|
package/refsInfo.d.ts
CHANGED
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
export function refsInfo(...refs: any[]): [string, string, string[]][];
|
|
7
7
|
|
|
8
8
|
export const tests: {
|
|
9
|
-
refsInfo: () => void;
|
|
10
|
-
'refsInfo: browserFingerprint': () => void;
|
|
9
|
+
refsInfo: (expect: import('bun:test').Expect) => void;
|
|
10
|
+
'refsInfo: browserFingerprint': (expect: import('bun:test').Expect) => void;
|
|
11
11
|
};
|
package/refsInfo.js
CHANGED
|
@@ -23,14 +23,14 @@ export const refsInfo = (/** @type {any[]} */ ...refs) => {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export const tests = {
|
|
26
|
-
refsInfo: () => {
|
|
26
|
+
refsInfo: (/** @type {import('bun:test').Expect} */ expect) => {
|
|
27
27
|
const info = refsInfo(Array, Function)
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
expect(info.find(([name]) => name === 'Array')?.[2]?.includes('length')).toBe(true)
|
|
30
|
+
expect(info.find(([name]) => name === 'Function')?.[2]?.includes('length')).toBe(true)
|
|
31
31
|
},
|
|
32
32
|
|
|
33
|
-
'refsInfo: browserFingerprint': () => {
|
|
33
|
+
'refsInfo: browserFingerprint': (/** @type {import('bun:test').Expect} */ expect) => {
|
|
34
34
|
const browserFingerprint = () => {
|
|
35
35
|
// @ts-ignore
|
|
36
36
|
const refs = Object.getOwnPropertyNames(window).map(name => window[name])
|
package/uuid1.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const tests: {
|
|
2
|
-
uuid1: () => void;
|
|
3
|
-
'uuid1: node': () => void;
|
|
4
|
-
'uuid1: date': () => void;
|
|
2
|
+
uuid1: (expect: import('bun:test').Expect) => void;
|
|
3
|
+
'uuid1: node': (expect: import('bun:test').Expect) => void;
|
|
4
|
+
'uuid1: date': (expect: import('bun:test').Expect) => void;
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
/**
|
package/uuid1.js
CHANGED
|
@@ -29,26 +29,26 @@ export const uuid1 = ({
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export const tests = {
|
|
32
|
-
uuid1: () => {
|
|
32
|
+
uuid1: (/** @type {import('bun:test').Expect} */ expect) => {
|
|
33
33
|
for (let i = 1; i <= 22136; ++i) {
|
|
34
34
|
const uuid = uuid1()
|
|
35
35
|
|
|
36
|
-
i === 1 &&
|
|
37
|
-
i === 4095 &&
|
|
38
|
-
i === 4096 &&
|
|
39
|
-
i === 9029 &&
|
|
40
|
-
i === 13398 &&
|
|
41
|
-
i === 16384 &&
|
|
42
|
-
i === 17767 &&
|
|
36
|
+
i === 1 && expect(uuid.split('-')[3]).toEqual('8001')
|
|
37
|
+
i === 4095 && expect(uuid.split('-')[3]).toEqual('8fff')
|
|
38
|
+
i === 4096 && expect(uuid.split('-')[3]).toEqual('9000')
|
|
39
|
+
i === 9029 && expect(uuid.split('-')[3]).toEqual('a345')
|
|
40
|
+
i === 13398 && expect(uuid.split('-')[3]).toEqual('b456')
|
|
41
|
+
i === 16384 && expect(uuid.split('-')[3]).toEqual('8000')
|
|
42
|
+
i === 17767 && expect(uuid.split('-')[3]).toEqual('8567')
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
|
|
46
|
-
'uuid1: node': () => {
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
'uuid1: node': (/** @type {import('bun:test').Expect} */ expect) => {
|
|
47
|
+
expect(uuid1({ node: '000123456789abc' }).split('-')[4]).toEqual('123456789abc')
|
|
48
|
+
expect(uuid1({ node: '123456789' }).split('-')[4]).toEqual('000123456789')
|
|
49
49
|
},
|
|
50
50
|
|
|
51
|
-
'uuid1: date': () => {
|
|
52
|
-
|
|
51
|
+
'uuid1: date': (/** @type {import('bun:test').Expect} */ expect) => {
|
|
52
|
+
expect(uuid1({ date: new Date(323325000000) })).toStartWith('c1399400-9a71-11bd')
|
|
53
53
|
}
|
|
54
54
|
}
|
package/tests.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export const tests: {
|
|
2
|
-
uuid1: () => void;
|
|
3
|
-
'uuid1: node': () => void;
|
|
4
|
-
'uuid1: date': () => void;
|
|
5
|
-
refsInfo: () => void;
|
|
6
|
-
'refsInfo: browserFingerprint': () => void;
|
|
7
|
-
pro: () => void;
|
|
8
|
-
plUral: () => void;
|
|
9
|
-
nanolightJs: () => void;
|
|
10
|
-
locale: () => void;
|
|
11
|
-
jsOnParse: () => void;
|
|
12
|
-
'jcss: #1': () => void;
|
|
13
|
-
'jcss: #2': () => void;
|
|
14
|
-
'jcss: #3': () => void;
|
|
15
|
-
'jcss: #4': () => void;
|
|
16
|
-
'jcss: #5': () => void;
|
|
17
|
-
'jcss: #6': () => void;
|
|
18
|
-
is: () => void;
|
|
19
|
-
'is: toString.call': () => void;
|
|
20
|
-
has: () => void;
|
|
21
|
-
'has: null': () => void;
|
|
22
|
-
h: () => void;
|
|
23
|
-
'h: innerText vs items': () => void;
|
|
24
|
-
'h: style': () => void;
|
|
25
|
-
'h: attributes vs properties': () => void;
|
|
26
|
-
'h: nested properties': () => void;
|
|
27
|
-
fixTypography: () => void;
|
|
28
|
-
escape: () => void;
|
|
29
|
-
eq: () => void;
|
|
30
|
-
};
|