@jackens/nnn 2024.4.15 → 2024.7.9
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 +2 -2
- package/package.json +2 -4
- package/readme.md +126 -119
package/nnn.d.ts
CHANGED
|
@@ -167,12 +167,12 @@ export declare const nanolightJs: (code: string) => HArgs1[];
|
|
|
167
167
|
/**
|
|
168
168
|
* A helper that implements TypeScript’s `Pick` utility type.
|
|
169
169
|
*/
|
|
170
|
-
export declare const pick: <T extends Partial<Record<PropertyKey, unknown>>, K extends
|
|
170
|
+
export declare const pick: <T extends Partial<Record<PropertyKey, unknown>>, K extends Array<keyof T>>(obj: Partial<Record<PropertyKey, unknown>>, keys: Partial<Array<unknown>>) => Pick<T, K[number]>;
|
|
171
171
|
|
|
172
172
|
/**
|
|
173
173
|
* A helper that implements TypeScript’s `Omit` utility type.
|
|
174
174
|
*/
|
|
175
|
-
export declare const omit: <T extends Partial<Record<PropertyKey, unknown>>, K extends
|
|
175
|
+
export declare const omit: <T extends Partial<Record<PropertyKey, unknown>>, K extends Array<keyof T>>(obj: Partial<Record<PropertyKey, unknown>>, keys: Partial<Array<unknown>>) => Omit<T, K[number]>;
|
|
176
176
|
|
|
177
177
|
/**
|
|
178
178
|
* A helper for choosing the correct singular and plural.
|
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Jackens",
|
|
3
3
|
"description": "Jackens’ JavaScript helpers.",
|
|
4
|
-
"homepage": "https://jackens.github.io/nnn/
|
|
4
|
+
"homepage": "https://jackens.github.io/nnn/",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CSS-in-JS",
|
|
7
7
|
"CSV",
|
|
8
8
|
"csvParse",
|
|
9
9
|
"DOM",
|
|
10
10
|
"escape",
|
|
11
|
-
"Gantt",
|
|
12
11
|
"h",
|
|
13
12
|
"has",
|
|
14
13
|
"highlight",
|
|
@@ -25,7 +24,6 @@
|
|
|
25
24
|
"nnn",
|
|
26
25
|
"omit",
|
|
27
26
|
"pick",
|
|
28
|
-
"RWD",
|
|
29
27
|
"SVG",
|
|
30
28
|
"translation",
|
|
31
29
|
"typography",
|
|
@@ -38,5 +36,5 @@
|
|
|
38
36
|
"types": "nnn.d.ts",
|
|
39
37
|
"name": "@jackens/nnn",
|
|
40
38
|
"type": "module",
|
|
41
|
-
"version": "2024.
|
|
39
|
+
"version": "2024.7.9"
|
|
42
40
|
}
|
package/readme.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Jackens’ JavaScript helpers.
|
|
4
4
|
|
|
5
|
-
<sub>Version: <code class="version">2024.
|
|
5
|
+
<sub>Version: <code class="version">2024.7.9</code></sub>
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -18,18 +18,22 @@ npm i @jackens/nnn
|
|
|
18
18
|
|
|
19
19
|
## Usage
|
|
20
20
|
|
|
21
|
-
Bun (or Node.js):
|
|
22
|
-
|
|
23
21
|
```js
|
|
24
22
|
import { «something» } from '@jackens/nnn'
|
|
25
23
|
```
|
|
26
24
|
|
|
27
|
-
|
|
25
|
+
or:
|
|
28
26
|
|
|
29
27
|
```js
|
|
30
28
|
import { «something» } from './node_modules/@jackens/nnn/nnn.js'
|
|
31
29
|
```
|
|
32
30
|
|
|
31
|
+
or:
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import { «something» } from 'https://unpkg.com/@jackens/nnn@2024.7.9/nnn.js'
|
|
35
|
+
```
|
|
36
|
+
|
|
33
37
|
## Exports
|
|
34
38
|
|
|
35
39
|
- `EscapeMap`: The type of arguments of the `escapeValues` and `escape` helpers.
|
|
@@ -132,13 +136,13 @@ yyy",zzz
|
|
|
132
136
|
42 , "42" , 17
|
|
133
137
|
|
|
134
138
|
`
|
|
135
|
-
expect(csvParse(text, { header: false })).
|
|
139
|
+
expect(csvParse(text, { header: false })).to.deep.equal([
|
|
136
140
|
['aaa\n"aaa"\naaa', 'bbb', 'ccc,ccc'],
|
|
137
141
|
['xxx,xxx', 'yyy\nyyy', 'zzz'],
|
|
138
142
|
[' 42 ', '42', ' 17']
|
|
139
143
|
])
|
|
140
144
|
|
|
141
|
-
expect(csvParse(text)).
|
|
145
|
+
expect(csvParse(text)).to.deep.equal([{
|
|
142
146
|
'aaa\n"aaa"\naaa': 'xxx,xxx',
|
|
143
147
|
bbb: 'yyy\nyyy',
|
|
144
148
|
'ccc,ccc': 'zzz'
|
|
@@ -162,13 +166,13 @@ A generic helper for escaping `values` by given `escapeMap` (in *TemplateStrings
|
|
|
162
166
|
#### Usage Examples
|
|
163
167
|
|
|
164
168
|
```js
|
|
165
|
-
const
|
|
169
|
+
const /** @type {import('../dist/nnn.js').EscapeMap} */ escapeMap = new Map([
|
|
166
170
|
[undefined, () => 'NULL'],
|
|
167
|
-
[Array, (
|
|
168
|
-
[Boolean, (
|
|
169
|
-
[Date, (
|
|
170
|
-
[Number, (
|
|
171
|
-
[String, (
|
|
171
|
+
[Array, (/** @type {Partial<Array<unknown>>} */ values) => escapeValues(escapeMap, values).join(', ')],
|
|
172
|
+
[Boolean, (/** @type {boolean} */ value) => `b'${+value}'`],
|
|
173
|
+
[Date, (/** @type {Date} */ value) => `'${value.toISOString().replace(/^(.+)T(.+)\..*$/, '$1 $2')}'`],
|
|
174
|
+
[Number, (/** @type {number} */ value) => `${value}`],
|
|
175
|
+
[String, (/** @type {string} */ value) => `'${value.replace(/'/g, "''")}'`]
|
|
172
176
|
])
|
|
173
177
|
|
|
174
178
|
const sql = escape.bind(null, escapeMap)
|
|
@@ -183,7 +187,7 @@ const expected = `
|
|
|
183
187
|
FROM table_name
|
|
184
188
|
WHERE column_name IN (b'1', NULL, NULL, 42, '42', '4''2', NULL, '1980-03-31 04:30:00')`
|
|
185
189
|
|
|
186
|
-
expect(actual).
|
|
190
|
+
expect(actual).to.deep.equal(expected)
|
|
187
191
|
```
|
|
188
192
|
|
|
189
193
|
### escapeValues
|
|
@@ -211,7 +215,7 @@ const p = h('p', 'Pchnąć w tę łódź jeża lub ośm skrzyń fig (zob. https:
|
|
|
211
215
|
|
|
212
216
|
fixTypography(p)
|
|
213
217
|
|
|
214
|
-
expect(p.innerHTML).
|
|
218
|
+
expect(p.innerHTML).to.deep.equal(
|
|
215
219
|
'Pchnąć <span style="white-space:nowrap">w </span>tę łódź jeża lub ośm skrzyń fig ' +
|
|
216
220
|
'(zob. https://\u200Bpl.\u200Bwikipedia.\u200Borg/\u200Bwiki/\u200BPangram).')
|
|
217
221
|
```
|
|
@@ -247,67 +251,67 @@ A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style help
|
|
|
247
251
|
```js
|
|
248
252
|
const b = h('b')
|
|
249
253
|
|
|
250
|
-
expect(b.outerHTML).
|
|
254
|
+
expect(b.outerHTML).to.deep.equal('<b></b>')
|
|
251
255
|
|
|
252
256
|
const i = h('i', 'text')
|
|
253
257
|
|
|
254
258
|
h(b, i)
|
|
255
259
|
|
|
256
|
-
expect(i.outerHTML).
|
|
257
|
-
expect(b.outerHTML).
|
|
260
|
+
expect(i.outerHTML).to.deep.equal('<i>text</i>')
|
|
261
|
+
expect(b.outerHTML).to.deep.equal('<b><i>text</i></b>')
|
|
258
262
|
|
|
259
263
|
h(i, { $className: 'some class' })
|
|
260
264
|
|
|
261
|
-
expect(i.outerHTML).
|
|
262
|
-
expect(b.outerHTML).
|
|
265
|
+
expect(i.outerHTML).to.deep.equal('<i class="some class">text</i>')
|
|
266
|
+
expect(b.outerHTML).to.deep.equal('<b><i class="some class">text</i></b>')
|
|
263
267
|
```
|
|
264
268
|
|
|
265
269
|
```js
|
|
266
|
-
expect(h('span', 'text').outerHTML).
|
|
267
|
-
expect(h('span', { $innerText: 'text' }).outerHTML).
|
|
270
|
+
expect(h('span', 'text').outerHTML).to.deep.equal('<span>text</span>')
|
|
271
|
+
expect(h('span', { $innerText: 'text' }).outerHTML).to.deep.equal('<span>text</span>')
|
|
268
272
|
```
|
|
269
273
|
|
|
270
274
|
```js
|
|
271
275
|
expect(h('div', { style: 'margin:0;padding:0' }).outerHTML)
|
|
272
|
-
.
|
|
276
|
+
.to.deep.equal('<div style="margin:0;padding:0"></div>')
|
|
273
277
|
expect(h('div', { $style: 'margin:0;padding:0' }).outerHTML)
|
|
274
|
-
.
|
|
278
|
+
.to.deep.equal('<div style="margin: 0px; padding: 0px;"></div>')
|
|
275
279
|
expect(h('div', { $style: { margin: 0, padding: 0 } }).outerHTML)
|
|
276
|
-
.
|
|
280
|
+
.to.deep.equal('<div style="margin: 0px; padding: 0px;"></div>')
|
|
277
281
|
```
|
|
278
282
|
|
|
279
283
|
```js
|
|
280
284
|
const input1 = h('input', { value: 42 })
|
|
281
285
|
const input2 = h('input', { $value: '42' })
|
|
282
286
|
|
|
283
|
-
expect(input1.value).
|
|
284
|
-
expect(input2.value).
|
|
287
|
+
expect(input1.value).to.deep.equal('42')
|
|
288
|
+
expect(input2.value).to.deep.equal('42')
|
|
285
289
|
|
|
286
|
-
expect(input1.outerHTML).
|
|
287
|
-
expect(input2.outerHTML).
|
|
290
|
+
expect(input1.outerHTML).to.deep.equal('<input value="42">')
|
|
291
|
+
expect(input2.outerHTML).to.deep.equal('<input>')
|
|
288
292
|
|
|
289
293
|
const checkbox1 = h('input', { type: 'checkbox', checked: true })
|
|
290
294
|
const checkbox2 = h('input', { type: 'checkbox', $checked: true })
|
|
291
295
|
|
|
292
|
-
expect(checkbox1.checked).
|
|
293
|
-
expect(checkbox2.checked).
|
|
296
|
+
expect(checkbox1.checked).to.be.true
|
|
297
|
+
expect(checkbox2.checked).to.be.true
|
|
294
298
|
|
|
295
|
-
expect(checkbox1.outerHTML).
|
|
296
|
-
expect(checkbox2.outerHTML).
|
|
299
|
+
expect(checkbox1.outerHTML).to.deep.equal('<input type="checkbox" checked="">')
|
|
300
|
+
expect(checkbox2.outerHTML).to.deep.equal('<input type="checkbox">')
|
|
297
301
|
```
|
|
298
302
|
|
|
299
303
|
```js
|
|
300
304
|
const div = h('div')
|
|
301
305
|
|
|
302
|
-
expect(div.key).
|
|
306
|
+
expect(div.key).to.be.undefined
|
|
303
307
|
|
|
304
308
|
h(div, { $key: { one: 1 } })
|
|
305
309
|
|
|
306
|
-
expect(div.key).
|
|
310
|
+
expect(div.key).to.deep.equal({ one: 1 })
|
|
307
311
|
|
|
308
312
|
h(div, { $key: { two: 2 } })
|
|
309
313
|
|
|
310
|
-
expect(div.key).
|
|
314
|
+
expect(div.key).to.deep.equal({ one: 1, two: 2 })
|
|
311
315
|
```
|
|
312
316
|
|
|
313
317
|
### has
|
|
@@ -323,17 +327,17 @@ A replacement for the `in` operator (not to be confused with the `for-in` loop)
|
|
|
323
327
|
```js
|
|
324
328
|
const obj = { key: 'K', null: 'N' }
|
|
325
329
|
|
|
326
|
-
expect('key' in obj).
|
|
327
|
-
expect(has('key', obj)).
|
|
330
|
+
expect('key' in obj).to.be.true
|
|
331
|
+
expect(has('key', obj)).to.be.true
|
|
328
332
|
|
|
329
|
-
expect('null' in obj).
|
|
330
|
-
expect(has('null', obj)).
|
|
333
|
+
expect('null' in obj).to.be.true
|
|
334
|
+
expect(has('null', obj)).to.be.true
|
|
331
335
|
|
|
332
|
-
expect(null in obj).
|
|
333
|
-
expect(has(null, obj)).
|
|
336
|
+
expect(null in obj).to.be.true
|
|
337
|
+
expect(has(null, obj)).to.be.false
|
|
334
338
|
|
|
335
|
-
expect('toString' in obj).
|
|
336
|
-
expect(has('toString', obj)).
|
|
339
|
+
expect('toString' in obj).to.be.true
|
|
340
|
+
expect(has('toString', obj)).to.be.false
|
|
337
341
|
```
|
|
338
342
|
|
|
339
343
|
```js
|
|
@@ -346,7 +350,7 @@ try {
|
|
|
346
350
|
}
|
|
347
351
|
|
|
348
352
|
expect(typeError instanceof TypeError) // Cannot use 'in' operator to search for 'key' in null
|
|
349
|
-
expect(has('key', null)).
|
|
353
|
+
expect(has('key', null)).to.be.false
|
|
350
354
|
```
|
|
351
355
|
|
|
352
356
|
### is
|
|
@@ -372,58 +376,61 @@ A helper that checks if the given argument is of a certain type.
|
|
|
372
376
|
#### Usage Examples
|
|
373
377
|
|
|
374
378
|
```js
|
|
375
|
-
expect(is(Number, 42)).
|
|
376
|
-
expect(is(Number, Number(42))).
|
|
377
|
-
|
|
378
|
-
expect(is(Number,
|
|
379
|
-
expect(is(
|
|
380
|
-
expect(is(String,
|
|
381
|
-
expect(is(String,
|
|
382
|
-
|
|
383
|
-
expect(is(
|
|
384
|
-
expect(is(
|
|
385
|
-
expect(is(
|
|
386
|
-
expect(is(
|
|
387
|
-
expect(is(
|
|
388
|
-
expect(is(
|
|
389
|
-
expect(is(
|
|
390
|
-
expect(is(
|
|
391
|
-
expect(is(
|
|
379
|
+
expect(is(Number, 42)).to.be.true
|
|
380
|
+
expect(is(Number, Number(42))).to.be.true
|
|
381
|
+
|
|
382
|
+
expect(is(Number, new Number(42))).to.be.true
|
|
383
|
+
expect(is(Number, NaN)).to.be.true
|
|
384
|
+
expect(is(String, '42')).to.be.true
|
|
385
|
+
expect(is(String, String('42'))).to.be.true
|
|
386
|
+
|
|
387
|
+
expect(is(String, new String('42'))).to.be.true
|
|
388
|
+
expect(is(Symbol, Symbol('42'))).to.be.true
|
|
389
|
+
expect(is(Symbol, Object(Symbol('42')))).to.be.true
|
|
390
|
+
expect(is(undefined, undefined)).to.be.true
|
|
391
|
+
expect(is(undefined, null)).to.be.true
|
|
392
|
+
expect(is(Object, {})).to.be.true
|
|
393
|
+
expect(is(Array, [])).to.be.true
|
|
394
|
+
expect(is(RegExp, /42/)).to.be.true
|
|
395
|
+
expect(is(Date, new Date(42))).to.be.true
|
|
396
|
+
expect(is(Set, new Set(['42', 42]))).to.be.true
|
|
397
|
+
expect(is(Map, new Map([[{ j: 42 }, { J: '42' }], [{ c: 42 }, { C: '42' }]]))).to.be.true
|
|
392
398
|
```
|
|
393
399
|
|
|
394
400
|
```js
|
|
395
|
-
const iz = (type
|
|
401
|
+
const iz = (/** @type {unknown} */ type, /** @type {unknown} */ arg) =>
|
|
402
|
+
({}).toString.call(arg).slice(8, -1) === type?.name
|
|
396
403
|
|
|
397
404
|
class FooBar { }
|
|
398
405
|
|
|
399
|
-
expect(is(FooBar, new FooBar())).
|
|
400
|
-
expect(iz(FooBar, new FooBar())).
|
|
406
|
+
expect(is(FooBar, new FooBar())).to.be.true
|
|
407
|
+
expect(iz(FooBar, new FooBar())).to.be.false
|
|
401
408
|
|
|
402
|
-
expect(is(Object, new FooBar())).
|
|
403
|
-
expect(iz(Object, new FooBar())).
|
|
409
|
+
expect(is(Object, new FooBar())).to.be.false
|
|
410
|
+
expect(iz(Object, new FooBar())).to.be.true
|
|
404
411
|
|
|
405
412
|
const fakeFooBar = {}
|
|
406
413
|
|
|
407
414
|
fakeFooBar[Symbol.toStringTag] = FooBar.name
|
|
408
415
|
|
|
409
|
-
expect(is(FooBar, fakeFooBar)).
|
|
410
|
-
expect(iz(FooBar, fakeFooBar)).
|
|
416
|
+
expect(is(FooBar, fakeFooBar)).to.be.false
|
|
417
|
+
expect(iz(FooBar, fakeFooBar)).to.be.true
|
|
411
418
|
|
|
412
|
-
expect(is(Object, fakeFooBar)).
|
|
413
|
-
expect(iz(Object, fakeFooBar)).
|
|
419
|
+
expect(is(Object, fakeFooBar)).to.be.true
|
|
420
|
+
expect(iz(Object, fakeFooBar)).to.be.false
|
|
414
421
|
```
|
|
415
422
|
|
|
416
423
|
```js
|
|
417
424
|
const num = 42
|
|
418
425
|
const str = '42'
|
|
419
426
|
|
|
420
|
-
expect(is(Number, num)).
|
|
427
|
+
expect(is(Number, num)).to.be.true
|
|
421
428
|
|
|
422
429
|
try {
|
|
423
430
|
num.constructor = str.constructor
|
|
424
431
|
} catch { /* empty */ }
|
|
425
432
|
|
|
426
|
-
expect(is(Number, num)).
|
|
433
|
+
expect(is(Number, num)).to.be.true
|
|
427
434
|
```
|
|
428
435
|
|
|
429
436
|
### jc
|
|
@@ -467,7 +474,7 @@ a{
|
|
|
467
474
|
padding:1
|
|
468
475
|
}`.replace(/\n\s*/g, '')
|
|
469
476
|
|
|
470
|
-
expect(actual).
|
|
477
|
+
expect(actual).to.deep.equal(expected)
|
|
471
478
|
```
|
|
472
479
|
|
|
473
480
|
```js
|
|
@@ -495,7 +502,7 @@ a.b{
|
|
|
495
502
|
padding:1
|
|
496
503
|
}`.replace(/\n\s*/g, '')
|
|
497
504
|
|
|
498
|
-
expect(actual).
|
|
505
|
+
expect(actual).to.deep.equal(expected)
|
|
499
506
|
```
|
|
500
507
|
|
|
501
508
|
```js
|
|
@@ -570,7 +577,7 @@ div.c2{
|
|
|
570
577
|
}
|
|
571
578
|
}`.replace(/\n\s*/g, '')
|
|
572
579
|
|
|
573
|
-
expect(actual).
|
|
580
|
+
expect(actual).to.deep.equal(expected)
|
|
574
581
|
```
|
|
575
582
|
|
|
576
583
|
```js
|
|
@@ -593,7 +600,7 @@ a.b.d,a.c.d{
|
|
|
593
600
|
margin:2
|
|
594
601
|
}`.replace(/\n\s*/g, '')
|
|
595
602
|
|
|
596
|
-
expect(actual).
|
|
603
|
+
expect(actual).to.deep.equal(expected)
|
|
597
604
|
```
|
|
598
605
|
|
|
599
606
|
```js
|
|
@@ -614,7 +621,7 @@ const expected = `
|
|
|
614
621
|
margin:2
|
|
615
622
|
}`.replace(/\n\s*/g, '')
|
|
616
623
|
|
|
617
|
-
expect(actual).
|
|
624
|
+
expect(actual).to.deep.equal(expected)
|
|
618
625
|
```
|
|
619
626
|
|
|
620
627
|
```js
|
|
@@ -635,7 +642,7 @@ const expected = `
|
|
|
635
642
|
margin:2
|
|
636
643
|
}`.replace(/\n\s*/g, '')
|
|
637
644
|
|
|
638
|
-
expect(actual).
|
|
645
|
+
expect(actual).to.deep.equal(expected)
|
|
639
646
|
```
|
|
640
647
|
|
|
641
648
|
### jsOnParse
|
|
@@ -664,7 +671,7 @@ handlers['«handlerName»'](...«params»)
|
|
|
664
671
|
|
|
665
672
|
```js
|
|
666
673
|
const handlers = {
|
|
667
|
-
$hello: (
|
|
674
|
+
$hello: (/** @type {string} */ name) => `Hello ${name}!`,
|
|
668
675
|
$foo: () => 'bar'
|
|
669
676
|
}
|
|
670
677
|
|
|
@@ -704,7 +711,7 @@ const expected = [
|
|
|
704
711
|
}
|
|
705
712
|
]
|
|
706
713
|
|
|
707
|
-
expect(actual).
|
|
714
|
+
expect(actual).to.deep.equal(expected)
|
|
708
715
|
```
|
|
709
716
|
|
|
710
717
|
### locale
|
|
@@ -725,18 +732,18 @@ const _ = locale({
|
|
|
725
732
|
button: { Login: 'Zaloguj' }
|
|
726
733
|
}, 'default')
|
|
727
734
|
|
|
728
|
-
expect(_('Login')).
|
|
729
|
-
expect(_('Password')).
|
|
735
|
+
expect(_('Login')).to.deep.equal('Login')
|
|
736
|
+
expect(_('Password')).to.deep.equal('Hasło')
|
|
730
737
|
|
|
731
|
-
expect(_('Undefined text')).
|
|
738
|
+
expect(_('Undefined text')).to.deep.equal('Undefined text')
|
|
732
739
|
|
|
733
|
-
expect(_('Login', 'button')).
|
|
740
|
+
expect(_('Login', 'button')).to.deep.equal('Zaloguj')
|
|
734
741
|
|
|
735
|
-
expect(_('Password', 'undefined_version')).
|
|
736
|
-
expect(_('Undefined text', 'undefined_version')).
|
|
742
|
+
expect(_('Password', 'undefined_version')).to.deep.equal('Hasło')
|
|
743
|
+
expect(_('Undefined text', 'undefined_version')).to.deep.equal('Undefined text')
|
|
737
744
|
|
|
738
|
-
expect(_('toString')).
|
|
739
|
-
expect(_('toString', 'undefined_version')).
|
|
745
|
+
expect(_('toString')).to.deep.equal('toString')
|
|
746
|
+
expect(_('toString', 'undefined_version')).to.deep.equal('toString')
|
|
740
747
|
```
|
|
741
748
|
|
|
742
749
|
### nanolight
|
|
@@ -762,7 +769,7 @@ A helper for highlighting JavaScript.
|
|
|
762
769
|
```js
|
|
763
770
|
const codeJs = 'const answerToLifeTheUniverseAndEverything = 42'
|
|
764
771
|
|
|
765
|
-
expect(nanolightJs(codeJs)).
|
|
772
|
+
expect(nanolightJs(codeJs)).to.deep.equal([
|
|
766
773
|
['span', { class: 'keyword' }, 'const'],
|
|
767
774
|
' ',
|
|
768
775
|
['span', { class: 'literal' }, 'answerToLifeTheUniverseAndEverything'],
|
|
@@ -776,7 +783,7 @@ expect(nanolightJs(codeJs)).toStrictEqual([
|
|
|
776
783
|
### omit
|
|
777
784
|
|
|
778
785
|
```ts
|
|
779
|
-
const omit: <T extends Partial<Record<PropertyKey, unknown>>, K extends
|
|
786
|
+
const omit: <T extends Partial<Record<PropertyKey, unknown>>, K extends Array<keyof T>>(obj: Partial<Record<PropertyKey, unknown>>, keys: Partial<Array<unknown>>) => Omit<T, K[number]>;
|
|
780
787
|
```
|
|
781
788
|
|
|
782
789
|
> See [here](https://jackens.github.io/nnn/doc/#Why-Partial-Array-and-Partial-Record) for an explanation of why `Partial<Array>`/`Partial<Record>` instead of `Array`/`Record`.
|
|
@@ -788,13 +795,13 @@ A helper that implements TypeScript’s `Omit` utility type.
|
|
|
788
795
|
```js
|
|
789
796
|
const obj = { a: 42, b: '42', c: 17 }
|
|
790
797
|
|
|
791
|
-
expect(omit(obj, ['c'])).
|
|
798
|
+
expect(omit(obj, ['c'])).to.deep.equal({ a: 42, b: '42' })
|
|
792
799
|
```
|
|
793
800
|
|
|
794
801
|
### pick
|
|
795
802
|
|
|
796
803
|
```ts
|
|
797
|
-
const pick: <T extends Partial<Record<PropertyKey, unknown>>, K extends
|
|
804
|
+
const pick: <T extends Partial<Record<PropertyKey, unknown>>, K extends Array<keyof T>>(obj: Partial<Record<PropertyKey, unknown>>, keys: Partial<Array<unknown>>) => Pick<T, K[number]>;
|
|
798
805
|
```
|
|
799
806
|
|
|
800
807
|
> See [here](https://jackens.github.io/nnn/doc/#Why-Partial-Array-and-Partial-Record) for an explanation of why `Partial<Array>`/`Partial<Record>` instead of `Array`/`Record`.
|
|
@@ -806,7 +813,7 @@ A helper that implements TypeScript’s `Pick` utility type.
|
|
|
806
813
|
```js
|
|
807
814
|
const obj = { a: 42, b: '42', c: 17 }
|
|
808
815
|
|
|
809
|
-
expect(pick(obj, ['a', 'b'])).
|
|
816
|
+
expect(pick(obj, ['a', 'b'])).to.deep.equal({ a: 42, b: '42' })
|
|
810
817
|
```
|
|
811
818
|
|
|
812
819
|
### plUral
|
|
@@ -822,17 +829,17 @@ A helper for choosing the correct singular and plural.
|
|
|
822
829
|
```js
|
|
823
830
|
const auto = plUral.bind(null, 'auto', 'auta', 'aut')
|
|
824
831
|
|
|
825
|
-
expect(auto(0)).
|
|
826
|
-
expect(auto(1)).
|
|
827
|
-
expect(auto(17)).
|
|
828
|
-
expect(auto(42)).
|
|
832
|
+
expect(auto(0)).to.deep.equal('aut')
|
|
833
|
+
expect(auto(1)).to.deep.equal('auto')
|
|
834
|
+
expect(auto(17)).to.deep.equal('aut')
|
|
835
|
+
expect(auto(42)).to.deep.equal('auta')
|
|
829
836
|
|
|
830
837
|
const car = plUral.bind(null, 'car', 'cars', 'cars')
|
|
831
838
|
|
|
832
|
-
expect(car(0)).
|
|
833
|
-
expect(car(1)).
|
|
834
|
-
expect(car(17)).
|
|
835
|
-
expect(car(42)).
|
|
839
|
+
expect(car(0)).to.deep.equal('cars')
|
|
840
|
+
expect(car(1)).to.deep.equal('car')
|
|
841
|
+
expect(car(17)).to.deep.equal('cars')
|
|
842
|
+
expect(car(42)).to.deep.equal('cars')
|
|
836
843
|
```
|
|
837
844
|
|
|
838
845
|
### pro
|
|
@@ -850,27 +857,27 @@ const ref = {}
|
|
|
850
857
|
|
|
851
858
|
pro(ref).one.two[3][4] = 1234
|
|
852
859
|
|
|
853
|
-
expect(ref).
|
|
860
|
+
expect(ref).to.deep.equal({ one: { two: { 3: { 4: 1234 } } } })
|
|
854
861
|
|
|
855
862
|
pro(ref).one.two.tree = 123
|
|
856
863
|
|
|
857
|
-
expect(ref).
|
|
864
|
+
expect(ref).to.deep.equal({ one: { two: { 3: { 4: 1234 }, tree: 123 } } })
|
|
858
865
|
|
|
859
866
|
pro(ref).one.two = undefined
|
|
860
867
|
|
|
861
|
-
expect(ref).
|
|
868
|
+
expect(ref).to.deep.equal({ one: { two: undefined } })
|
|
862
869
|
|
|
863
870
|
delete pro(ref).one.two
|
|
864
871
|
|
|
865
|
-
expect(ref).
|
|
872
|
+
expect(ref).to.deep.equal({ one: {} })
|
|
866
873
|
|
|
867
874
|
pro(ref).one.two.three.four
|
|
868
875
|
|
|
869
|
-
expect(ref).
|
|
876
|
+
expect(ref).to.deep.equal({ one: { two: { three: { four: {} } } } })
|
|
870
877
|
|
|
871
878
|
pro(ref).one.two.three.four = 1234
|
|
872
879
|
|
|
873
|
-
expect(ref).
|
|
880
|
+
expect(ref).to.deep.equal({ one: { two: { three: { four: 1234 } } } })
|
|
874
881
|
```
|
|
875
882
|
|
|
876
883
|
### refsInfo
|
|
@@ -890,8 +897,8 @@ It returns an array of triples: `[«name», «prototype-name», «array-of-own-p
|
|
|
890
897
|
```js
|
|
891
898
|
const info = refsInfo(Array, Function)
|
|
892
899
|
|
|
893
|
-
expect(info.find(item => item?.[0] === 'Array')?.[2]?.includes('length')).
|
|
894
|
-
expect(info.find(item => item?.[0] === 'Function')?.[2]?.includes('length')).
|
|
900
|
+
expect(info.find(item => item?.[0] === 'Array')?.[2]?.includes('length')).to.be.true
|
|
901
|
+
expect(info.find(item => item?.[0] === 'Function')?.[2]?.includes('length')).to.be.true
|
|
895
902
|
```
|
|
896
903
|
|
|
897
904
|
```js
|
|
@@ -974,23 +981,23 @@ A helper that generates a UUID v1 identifier (with a creation timestamp).
|
|
|
974
981
|
for (let i = 1; i <= 22136; ++i) {
|
|
975
982
|
const uuid = uuid1()
|
|
976
983
|
|
|
977
|
-
i === 1 && expect(uuid.split('-')[3]).
|
|
978
|
-
i === 4095 && expect(uuid.split('-')[3]).
|
|
979
|
-
i === 4096 && expect(uuid.split('-')[3]).
|
|
980
|
-
i === 9029 && expect(uuid.split('-')[3]).
|
|
981
|
-
i === 13398 && expect(uuid.split('-')[3]).
|
|
982
|
-
i === 16384 && expect(uuid.split('-')[3]).
|
|
983
|
-
i === 17767 && expect(uuid.split('-')[3]).
|
|
984
|
+
i === 1 && expect(uuid.split('-')[3]).to.deep.equal('8001')
|
|
985
|
+
i === 4095 && expect(uuid.split('-')[3]).to.deep.equal('8fff')
|
|
986
|
+
i === 4096 && expect(uuid.split('-')[3]).to.deep.equal('9000')
|
|
987
|
+
i === 9029 && expect(uuid.split('-')[3]).to.deep.equal('a345')
|
|
988
|
+
i === 13398 && expect(uuid.split('-')[3]).to.deep.equal('b456')
|
|
989
|
+
i === 16384 && expect(uuid.split('-')[3]).to.deep.equal('8000')
|
|
990
|
+
i === 17767 && expect(uuid.split('-')[3]).to.deep.equal('8567')
|
|
984
991
|
}
|
|
985
992
|
```
|
|
986
993
|
|
|
987
994
|
```js
|
|
988
|
-
expect(uuid1({ node: '000123456789abc' }).split('-')[4]).
|
|
989
|
-
expect(uuid1({ node: '123456789' }).split('-')[4]).
|
|
995
|
+
expect(uuid1({ node: '000123456789abc' }).split('-')[4]).to.deep.equal('123456789abc')
|
|
996
|
+
expect(uuid1({ node: '123456789' }).split('-')[4]).to.deep.equal('000123456789')
|
|
990
997
|
```
|
|
991
998
|
|
|
992
999
|
```js
|
|
993
|
-
expect(uuid1({ date: new Date(323325000000) }).startsWith('c1399400-9a71-11bd')).
|
|
1000
|
+
expect(uuid1({ date: new Date(323325000000) }).startsWith('c1399400-9a71-11bd')).to.be.true
|
|
994
1001
|
```
|
|
995
1002
|
|
|
996
1003
|
## Why Partial\<Array\> and Partial\<Record\>
|