@jackens/nnn 2024.2.20 → 2024.2.24
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 +220 -21
- package/nnn.js +419 -37
- package/package.json +1 -1
- package/readme.md +177 -172
- package/chartable.d.ts +0 -33
- package/chartable.js +0 -195
- package/eq.d.ts +0 -8
- package/eq.js +0 -83
- package/escape.d.ts +0 -18
- package/escape.js +0 -51
- package/fixTypography.d.ts +0 -8
- package/fixTypography.js +0 -61
- package/h.d.ts +0 -55
- package/h.js +0 -213
- package/has.d.ts +0 -9
- package/has.js +0 -40
- package/is.d.ts +0 -17
- package/is.js +0 -65
- package/jcss.d.ts +0 -33
- package/jcss.js +0 -293
- package/jsOnParse.d.ts +0 -20
- package/jsOnParse.js +0 -85
- package/locale.d.ts +0 -8
- package/locale.js +0 -39
- package/nanolight.d.ts +0 -6
- package/nanolight.js +0 -21
- package/nanolightJs.d.ts +0 -8
- package/nanolightJs.js +0 -29
- package/pick.d.ts +0 -14
- package/pick.js +0 -31
- package/plUral.d.ts +0 -8
- package/plUral.js +0 -39
- package/pro.d.ts +0 -8
- package/pro.js +0 -39
- package/refsInfo.d.ts +0 -11
- package/refsInfo.js +0 -57
- package/uuid1.d.ts +0 -16
- package/uuid1.js +0 -54
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.24</code></sub>
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -61,7 +61,7 @@ import { «something» } from './node_modules/@jackens/nnn/nnn.js'
|
|
|
61
61
|
### EscapeMap
|
|
62
62
|
|
|
63
63
|
```ts
|
|
64
|
-
|
|
64
|
+
type EscapeMap = Map<any, (value?: any) => string>;
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
The type of arguments of the `escapeValues` and `escape` helpers.
|
|
@@ -69,7 +69,7 @@ The type of arguments of the `escapeValues` and `escape` helpers.
|
|
|
69
69
|
### HArgs
|
|
70
70
|
|
|
71
71
|
```ts
|
|
72
|
-
|
|
72
|
+
type HArgs = [string | Node, ...HArgs1[]];
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
The type of arguments of the `h` and `s` helpers.
|
|
@@ -77,7 +77,7 @@ The type of arguments of the `h` and `s` helpers.
|
|
|
77
77
|
### HArgs1
|
|
78
78
|
|
|
79
79
|
```ts
|
|
80
|
-
|
|
80
|
+
type HArgs1 = Partial<Record<PropertyKey, any>> | null | undefined | Node | string | number | HArgs;
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
The type of arguments of the `h` and `s` helpers.
|
|
@@ -85,7 +85,7 @@ The type of arguments of the `h` and `s` helpers.
|
|
|
85
85
|
### JcssNode
|
|
86
86
|
|
|
87
87
|
```ts
|
|
88
|
-
|
|
88
|
+
type JcssNode = {
|
|
89
89
|
[attributeOrSelector: string]: string | number | JcssNode | undefined;
|
|
90
90
|
};
|
|
91
91
|
```
|
|
@@ -95,7 +95,7 @@ The type of arguments of the `jcss` helper.
|
|
|
95
95
|
### JcssRoot
|
|
96
96
|
|
|
97
97
|
```ts
|
|
98
|
-
|
|
98
|
+
type JcssRoot = Partial<Record<PropertyKey, JcssNode>>;
|
|
99
99
|
```
|
|
100
100
|
|
|
101
101
|
The type of arguments of the `jcss` helper.
|
|
@@ -103,7 +103,7 @@ The type of arguments of the `jcss` helper.
|
|
|
103
103
|
### chartable
|
|
104
104
|
|
|
105
105
|
```ts
|
|
106
|
-
|
|
106
|
+
const chartable: ({ table, headerColumn, xGap, xLabelsMinHeight, xLabelsRotate, xReverse, yGap, yLabelsLeftMinWidth, yLabelsRightMinWidth, yMax, zLabelsMinWidth, zyMappings }: {
|
|
107
107
|
table: HTMLTableElement;
|
|
108
108
|
headerColumn?: boolean | undefined;
|
|
109
109
|
xGap?: number | undefined;
|
|
@@ -116,7 +116,7 @@ export function chartable({ table, headerColumn, xGap, xLabelsMinHeight, xLabels
|
|
|
116
116
|
yMax?: number | undefined;
|
|
117
117
|
zLabelsMinWidth?: number | undefined;
|
|
118
118
|
zyMappings?: [(label: string) => number, (value: number) => string][] | undefined;
|
|
119
|
-
})
|
|
119
|
+
}) => SVGSVGElement;
|
|
120
120
|
```
|
|
121
121
|
|
|
122
122
|
A helper for creating a chart based on a table (conf. <https://jackens.github.io/nnn/chartable/>).
|
|
@@ -138,7 +138,7 @@ Options:
|
|
|
138
138
|
### eq
|
|
139
139
|
|
|
140
140
|
```ts
|
|
141
|
-
|
|
141
|
+
const eq: (x: any, y: any) => boolean;
|
|
142
142
|
```
|
|
143
143
|
|
|
144
144
|
A helper that checks equality of the given arguments.
|
|
@@ -146,41 +146,41 @@ A helper that checks equality of the given arguments.
|
|
|
146
146
|
#### Usage Examples
|
|
147
147
|
|
|
148
148
|
```js
|
|
149
|
-
expect(eq(true, true)).
|
|
150
|
-
expect(eq(NaN, NaN)).
|
|
151
|
-
expect(eq(null, undefined)).
|
|
152
|
-
expect(eq(42, 42)).
|
|
153
|
-
expect(eq(42, new Number(42))).
|
|
154
|
-
expect(eq(42, Number(42))).
|
|
155
|
-
expect(eq(new Number(42), Number(42))).
|
|
156
|
-
expect(eq(42, '42')).
|
|
157
|
-
expect(eq('42', '42')).
|
|
158
|
-
expect(eq('42', new String('42'))).
|
|
159
|
-
expect(eq('42', String('42'))).
|
|
160
|
-
expect(eq(String('42'), new String('42'))).
|
|
161
|
-
expect(eq(/42/, /42/)).
|
|
162
|
-
expect(eq(/42/, /42/g)).
|
|
163
|
-
expect(eq(new Date(42), new Date(42))).
|
|
164
|
-
expect(eq(new Date(), new Date(42))).
|
|
165
|
-
expect(eq({ j: '42', c: 42 }, { c: 42, j: '42' })).
|
|
166
|
-
expect(eq([42, '42'], [42, '42'])).
|
|
167
|
-
expect(eq(new Set(['42', 42]), new Set([42, '42']))).
|
|
168
|
-
expect(eq(new Set(['42', 42]), new Set([42]))).
|
|
169
|
-
expect(eq(new Set([42, undefined]), new Set([42]))).
|
|
149
|
+
expect(eq(true, true)).toBeTrue()
|
|
150
|
+
expect(eq(NaN, NaN)).toBeTrue()
|
|
151
|
+
expect(eq(null, undefined)).toBeFalse()
|
|
152
|
+
expect(eq(42, 42)).toBeTrue()
|
|
153
|
+
expect(eq(42, new Number(42))).toBeTrue()
|
|
154
|
+
expect(eq(42, Number(42))).toBeTrue()
|
|
155
|
+
expect(eq(new Number(42), Number(42))).toBeTrue()
|
|
156
|
+
expect(eq(42, '42')).toBeFalse()
|
|
157
|
+
expect(eq('42', '42')).toBeTrue()
|
|
158
|
+
expect(eq('42', new String('42'))).toBeTrue()
|
|
159
|
+
expect(eq('42', String('42'))).toBeTrue()
|
|
160
|
+
expect(eq(String('42'), new String('42'))).toBeTrue()
|
|
161
|
+
expect(eq(/42/, /42/)).toBeTrue()
|
|
162
|
+
expect(eq(/42/, /42/g)).toBeFalse()
|
|
163
|
+
expect(eq(new Date(42), new Date(42))).toBeTrue()
|
|
164
|
+
expect(eq(new Date(), new Date(42))).toBeFalse()
|
|
165
|
+
expect(eq({ j: '42', c: 42 }, { c: 42, j: '42' })).toBeTrue()
|
|
166
|
+
expect(eq([42, '42'], [42, '42'])).toBeTrue()
|
|
167
|
+
expect(eq(new Set(['42', 42]), new Set([42, '42']))).toBeTrue()
|
|
168
|
+
expect(eq(new Set(['42', 42]), new Set([42]))).toBeFalse()
|
|
169
|
+
expect(eq(new Set([42, undefined]), new Set([42]))).toBeFalse()
|
|
170
170
|
expect(eq(
|
|
171
171
|
new Map([[{ j: 42 }, { J: '42' }], [{ c: 42 }, { C: '42' }]]),
|
|
172
172
|
new Map([[{ c: 42 }, { C: '42' }], [{ j: 42 }, { J: '42' }]])
|
|
173
|
-
)).
|
|
173
|
+
)).toBeTrue()
|
|
174
174
|
expect(eq(
|
|
175
175
|
new Map([[{ j: 42 }, { J: '42' }], [{ c: 42 }, { C: '42' }]]),
|
|
176
176
|
new Map([[{ j: '42' }, { J: 42 }], [{ c: '42' }, { C: 42 }]])
|
|
177
|
-
)).
|
|
177
|
+
)).toBeFalse()
|
|
178
178
|
```
|
|
179
179
|
|
|
180
180
|
### escape
|
|
181
181
|
|
|
182
182
|
```ts
|
|
183
|
-
|
|
183
|
+
const escape: (escapeMap: EscapeMap, template: TemplateStringsArray, ...values: any[]) => string;
|
|
184
184
|
```
|
|
185
185
|
|
|
186
186
|
A generic helper for escaping `values` by given `escapeMap` (in *TemplateStrings* flavor).
|
|
@@ -188,13 +188,13 @@ A generic helper for escaping `values` by given `escapeMap` (in *TemplateStrings
|
|
|
188
188
|
#### Usage Examples
|
|
189
189
|
|
|
190
190
|
```js
|
|
191
|
-
const
|
|
191
|
+
const escapeMap: EscapeMap = new Map([
|
|
192
192
|
[undefined, () => 'NULL'],
|
|
193
|
-
[Array, (
|
|
194
|
-
[Boolean, (
|
|
195
|
-
[Date, (
|
|
196
|
-
[Number, (
|
|
197
|
-
[String, (
|
|
193
|
+
[Array, (values: any[]) => escapeValues(escapeMap, values).join(', ')],
|
|
194
|
+
[Boolean, (value: boolean) => `b'${+value}'`],
|
|
195
|
+
[Date, (value: Date) => `'${value.toISOString().replace(/^(.+)T(.+)\..*$/, '$1 $2')}'`],
|
|
196
|
+
[Number, (value: number) => `${value}`],
|
|
197
|
+
[String, (value: string) => `'${value.replace(/'/g, "''")}'`]
|
|
198
198
|
])
|
|
199
199
|
|
|
200
200
|
const sql = escape.bind(null, escapeMap)
|
|
@@ -209,13 +209,13 @@ const expected = `
|
|
|
209
209
|
FROM table_name
|
|
210
210
|
WHERE column_name IN (b'1', NULL, NULL, 42, '42', '4''2', NULL, '1980-03-31 04:30:00')`
|
|
211
211
|
|
|
212
|
-
expect(actual).
|
|
212
|
+
expect(actual).toStrictEqual(expected)
|
|
213
213
|
```
|
|
214
214
|
|
|
215
215
|
### escapeValues
|
|
216
216
|
|
|
217
217
|
```ts
|
|
218
|
-
|
|
218
|
+
const escapeValues: (escapeMap: EscapeMap, values: any[]) => string[];
|
|
219
219
|
```
|
|
220
220
|
|
|
221
221
|
A generic helper for escaping `values` by given `escapeMap`.
|
|
@@ -223,7 +223,7 @@ A generic helper for escaping `values` by given `escapeMap`.
|
|
|
223
223
|
### fixTypography
|
|
224
224
|
|
|
225
225
|
```ts
|
|
226
|
-
|
|
226
|
+
const fixTypography: (node: Node) => void;
|
|
227
227
|
```
|
|
228
228
|
|
|
229
229
|
A helper that implements typographic corrections specific to Polish typography.
|
|
@@ -235,7 +235,7 @@ const p = h('p', 'Pchnąć w tę łódź jeża lub ośm skrzyń fig (zob. https:
|
|
|
235
235
|
|
|
236
236
|
fixTypography(p)
|
|
237
237
|
|
|
238
|
-
expect(p.innerHTML).
|
|
238
|
+
expect(p.innerHTML).toStrictEqual(
|
|
239
239
|
'Pchnąć <span style="white-space:nowrap">w </span>tę łódź jeża lub ośm skrzyń fig ' +
|
|
240
240
|
'(zob. https://\u200Bpl.\u200Bwikipedia.\u200Borg/\u200Bwiki/\u200BPangram).')
|
|
241
241
|
```
|
|
@@ -243,9 +243,11 @@ expect(p.innerHTML).to.deep.equal(
|
|
|
243
243
|
### h
|
|
244
244
|
|
|
245
245
|
```ts
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
246
|
+
const h: {
|
|
247
|
+
<T extends keyof HTMLElementTagNameMap>(tag: T, ...args1: HArgs1[]): HTMLElementTagNameMap[T];
|
|
248
|
+
<N extends Node>(node: N, ...args1: HArgs1[]): N;
|
|
249
|
+
(tagOrNode: string | Node, ...args1: HArgs1[]): Node;
|
|
250
|
+
};
|
|
249
251
|
```
|
|
250
252
|
|
|
251
253
|
A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style helper for creating and modifying `HTMLElement`s (see also `s`).
|
|
@@ -267,73 +269,73 @@ A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style help
|
|
|
267
269
|
```js
|
|
268
270
|
const b = h('b')
|
|
269
271
|
|
|
270
|
-
expect(b.outerHTML).
|
|
272
|
+
expect(b.outerHTML).toStrictEqual('<b></b>')
|
|
271
273
|
|
|
272
274
|
const i = h('i', 'text')
|
|
273
275
|
|
|
274
276
|
h(b, i)
|
|
275
277
|
|
|
276
|
-
expect(i.outerHTML).
|
|
277
|
-
expect(b.outerHTML).
|
|
278
|
+
expect(i.outerHTML).toStrictEqual('<i>text</i>')
|
|
279
|
+
expect(b.outerHTML).toStrictEqual('<b><i>text</i></b>')
|
|
278
280
|
|
|
279
281
|
h(i, { $className: 'some class' })
|
|
280
282
|
|
|
281
|
-
expect(i.outerHTML).
|
|
282
|
-
expect(b.outerHTML).
|
|
283
|
+
expect(i.outerHTML).toStrictEqual('<i class="some class">text</i>')
|
|
284
|
+
expect(b.outerHTML).toStrictEqual('<b><i class="some class">text</i></b>')
|
|
283
285
|
```
|
|
284
286
|
|
|
285
287
|
```js
|
|
286
|
-
expect(h('span', 'text').outerHTML).
|
|
287
|
-
expect(h('span', { $innerText: 'text' }).outerHTML).
|
|
288
|
+
expect(h('span', 'text').outerHTML).toStrictEqual('<span>text</span>')
|
|
289
|
+
expect(h('span', { $innerText: 'text' }).outerHTML).toStrictEqual('<span>text</span>')
|
|
288
290
|
```
|
|
289
291
|
|
|
290
292
|
```js
|
|
291
293
|
expect(h('div', { style: 'margin:0;padding:0' }).outerHTML)
|
|
292
|
-
.
|
|
294
|
+
.toStrictEqual('<div style="margin:0;padding:0"></div>')
|
|
293
295
|
expect(h('div', { $style: 'margin:0;padding:0' }).outerHTML)
|
|
294
|
-
.
|
|
296
|
+
.toStrictEqual('<div style="margin: 0px; padding: 0px;"></div>')
|
|
295
297
|
expect(h('div', { $style: { margin: 0, padding: 0 } }).outerHTML)
|
|
296
|
-
.
|
|
298
|
+
.toStrictEqual('<div style="margin: 0px; padding: 0px;"></div>')
|
|
297
299
|
```
|
|
298
300
|
|
|
299
301
|
```js
|
|
300
302
|
const input1 = h('input', { value: 42 })
|
|
301
303
|
const input2 = h('input', { $value: '42' })
|
|
302
304
|
|
|
303
|
-
expect(input1.value).
|
|
304
|
-
expect(input2.value).
|
|
305
|
+
expect(input1.value).toStrictEqual('42')
|
|
306
|
+
expect(input2.value).toStrictEqual('42')
|
|
305
307
|
|
|
306
|
-
expect(input1.outerHTML).
|
|
307
|
-
expect(input2.outerHTML).
|
|
308
|
+
expect(input1.outerHTML).toStrictEqual('<input value="42">')
|
|
309
|
+
expect(input2.outerHTML).toStrictEqual('<input>')
|
|
308
310
|
|
|
309
311
|
const checkbox1 = h('input', { type: 'checkbox', checked: true })
|
|
310
312
|
const checkbox2 = h('input', { type: 'checkbox', $checked: true })
|
|
311
313
|
|
|
312
|
-
expect(checkbox1.checked).
|
|
313
|
-
expect(checkbox2.checked).
|
|
314
|
+
expect(checkbox1.checked).toBeTrue()
|
|
315
|
+
expect(checkbox2.checked).toBeTrue()
|
|
314
316
|
|
|
315
|
-
expect(checkbox1.outerHTML).
|
|
316
|
-
expect(checkbox2.outerHTML).
|
|
317
|
+
expect(checkbox1.outerHTML).toStrictEqual('<input type="checkbox" checked="">')
|
|
318
|
+
expect(checkbox2.outerHTML).toStrictEqual('<input type="checkbox">')
|
|
317
319
|
```
|
|
318
320
|
|
|
319
321
|
```js
|
|
320
322
|
const div = h('div')
|
|
321
323
|
|
|
322
|
-
expect(div.key).
|
|
324
|
+
expect(div.key).toBeUndefined()
|
|
323
325
|
|
|
324
326
|
h(div, { $key: { one: 1 } })
|
|
325
327
|
|
|
326
|
-
expect(div.key).
|
|
328
|
+
expect(div.key).toStrictEqual({ one: 1 })
|
|
327
329
|
|
|
328
330
|
h(div, { $key: { two: 2 } })
|
|
329
331
|
|
|
330
|
-
expect(div.key).
|
|
332
|
+
expect(div.key).toStrictEqual({ one: 1, two: 2 })
|
|
331
333
|
```
|
|
332
334
|
|
|
333
335
|
### has
|
|
334
336
|
|
|
335
337
|
```ts
|
|
336
|
-
|
|
338
|
+
const has: (key: any, ref: any) => boolean;
|
|
337
339
|
```
|
|
338
340
|
|
|
339
341
|
A replacement for the `in` operator (not to be confused with the `for-in` loop) that works properly.
|
|
@@ -343,17 +345,17 @@ A replacement for the `in` operator (not to be confused with the `for-in` loop)
|
|
|
343
345
|
```js
|
|
344
346
|
const obj = { key: 'K', null: 'N' }
|
|
345
347
|
|
|
346
|
-
expect('key' in obj).
|
|
347
|
-
expect(has('key', obj)).
|
|
348
|
+
expect('key' in obj).toBeTrue()
|
|
349
|
+
expect(has('key', obj)).toBeTrue()
|
|
348
350
|
|
|
349
|
-
expect('null' in obj).
|
|
350
|
-
expect(has('null', obj)).
|
|
351
|
+
expect('null' in obj).toBeTrue()
|
|
352
|
+
expect(has('null', obj)).toBeTrue()
|
|
351
353
|
|
|
352
|
-
expect(null in obj).
|
|
353
|
-
expect(has(null, obj)).
|
|
354
|
+
expect(null in obj).toBeTrue()
|
|
355
|
+
expect(has(null, obj)).toBeFalse()
|
|
354
356
|
|
|
355
|
-
expect('toString' in obj).
|
|
356
|
-
expect(has('toString', obj)).
|
|
357
|
+
expect('toString' in obj).toBeTrue()
|
|
358
|
+
expect(has('toString', obj)).toBeFalse()
|
|
357
359
|
```
|
|
358
360
|
|
|
359
361
|
```js
|
|
@@ -366,21 +368,20 @@ try {
|
|
|
366
368
|
}
|
|
367
369
|
|
|
368
370
|
expect(typeError instanceof TypeError) // Cannot use 'in' operator to search for 'key' in null
|
|
369
|
-
expect(has('key', null)).
|
|
371
|
+
expect(has('key', null)).toBeFalse()
|
|
370
372
|
```
|
|
371
373
|
|
|
372
374
|
### is
|
|
373
375
|
|
|
374
376
|
```ts
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
};
|
|
377
|
+
function is(type: BigIntConstructor, arg: any): arg is bigint;
|
|
378
|
+
function is(type: BooleanConstructor, arg: any): arg is boolean;
|
|
379
|
+
function is(type: NumberConstructor, arg: any): arg is number;
|
|
380
|
+
function is(type: ObjectConstructor, arg: any): arg is Partial<Record<PropertyKey, any>>;
|
|
381
|
+
function is(type: StringConstructor, arg: any): arg is string;
|
|
382
|
+
function is(type: SymbolConstructor, arg: any): arg is symbol;
|
|
383
|
+
function is(type: undefined, arg: any): arg is undefined | null;
|
|
384
|
+
function is<T extends abstract new (...args: any[]) => any>(type: T, arg: any): arg is InstanceType<T>;
|
|
384
385
|
```
|
|
385
386
|
|
|
386
387
|
A helper that checks if the given argument is of a certain type.
|
|
@@ -388,51 +389,51 @@ A helper that checks if the given argument is of a certain type.
|
|
|
388
389
|
#### Usage Examples
|
|
389
390
|
|
|
390
391
|
```js
|
|
391
|
-
expect(is(Number, 42)).
|
|
392
|
-
expect(is(Number, Number(42))).
|
|
393
|
-
expect(is(Number, new Number(42))).
|
|
394
|
-
expect(is(Number, NaN)).
|
|
395
|
-
expect(is(String, '42')).
|
|
396
|
-
expect(is(String, String('42'))).
|
|
397
|
-
expect(is(String, new String('42'))).
|
|
398
|
-
expect(is(Symbol, Symbol('42'))).
|
|
399
|
-
expect(is(Symbol, Object(Symbol('42')))).
|
|
400
|
-
expect(is(undefined, undefined)).
|
|
401
|
-
expect(is(undefined, null)).
|
|
402
|
-
expect(is(Object, {})).
|
|
403
|
-
expect(is(Array, [])).
|
|
404
|
-
expect(is(RegExp, /42/)).
|
|
405
|
-
expect(is(Date, new Date(42))).
|
|
406
|
-
expect(is(Set, new Set(['42', 42]))).
|
|
407
|
-
expect(is(Map, new Map([[{ j: 42 }, { J: '42' }], [{ c: 42 }, { C: '42' }]]))).
|
|
392
|
+
expect(is(Number, 42)).toBeTrue()
|
|
393
|
+
expect(is(Number, Number(42))).toBeTrue()
|
|
394
|
+
expect(is(Number, new Number(42))).toBeTrue()
|
|
395
|
+
expect(is(Number, NaN)).toBeTrue()
|
|
396
|
+
expect(is(String, '42')).toBeTrue()
|
|
397
|
+
expect(is(String, String('42'))).toBeTrue()
|
|
398
|
+
expect(is(String, new String('42'))).toBeTrue()
|
|
399
|
+
expect(is(Symbol, Symbol('42'))).toBeTrue()
|
|
400
|
+
expect(is(Symbol, Object(Symbol('42')))).toBeTrue()
|
|
401
|
+
expect(is(undefined, undefined)).toBeTrue()
|
|
402
|
+
expect(is(undefined, null)).toBeTrue()
|
|
403
|
+
expect(is(Object, {})).toBeTrue()
|
|
404
|
+
expect(is(Array, [])).toBeTrue()
|
|
405
|
+
expect(is(RegExp, /42/)).toBeTrue()
|
|
406
|
+
expect(is(Date, new Date(42))).toBeTrue()
|
|
407
|
+
expect(is(Set, new Set(['42', 42]))).toBeTrue()
|
|
408
|
+
expect(is(Map, new Map([[{ j: 42 }, { J: '42' }], [{ c: 42 }, { C: '42' }]]))).toBeTrue()
|
|
408
409
|
```
|
|
409
410
|
|
|
410
411
|
```js
|
|
411
|
-
const iz = (
|
|
412
|
+
const iz = (type: any, arg: any) => ({}).toString.call(arg).slice(8, -1) === type?.name
|
|
412
413
|
|
|
413
414
|
class FooBar { }
|
|
414
415
|
|
|
415
|
-
expect(is(FooBar, new FooBar())).
|
|
416
|
-
expect(iz(FooBar, new FooBar())).
|
|
416
|
+
expect(is(FooBar, new FooBar())).toBeTrue()
|
|
417
|
+
expect(iz(FooBar, new FooBar())).toBeFalse()
|
|
417
418
|
|
|
418
|
-
expect(is(Object, new FooBar())).
|
|
419
|
-
expect(iz(Object, new FooBar())).
|
|
419
|
+
expect(is(Object, new FooBar())).toBeFalse()
|
|
420
|
+
expect(iz(Object, new FooBar())).toBeTrue()
|
|
420
421
|
|
|
421
422
|
const fakeFooBar = {}
|
|
422
423
|
|
|
423
424
|
fakeFooBar[Symbol.toStringTag] = FooBar.name
|
|
424
425
|
|
|
425
|
-
expect(is(FooBar, fakeFooBar)).
|
|
426
|
-
expect(iz(FooBar, fakeFooBar)).
|
|
426
|
+
expect(is(FooBar, fakeFooBar)).toBeFalse()
|
|
427
|
+
expect(iz(FooBar, fakeFooBar)).toBeTrue()
|
|
427
428
|
|
|
428
|
-
expect(is(Object, fakeFooBar)).
|
|
429
|
-
expect(iz(Object, fakeFooBar)).
|
|
429
|
+
expect(is(Object, fakeFooBar)).toBeTrue()
|
|
430
|
+
expect(iz(Object, fakeFooBar)).toBeFalse()
|
|
430
431
|
```
|
|
431
432
|
|
|
432
433
|
### jcss
|
|
433
434
|
|
|
434
435
|
```ts
|
|
435
|
-
|
|
436
|
+
const jcss: (root: JcssRoot, splitter?: string) => string;
|
|
436
437
|
```
|
|
437
438
|
|
|
438
439
|
A simple CSS-in-JS helper.
|
|
@@ -470,7 +471,7 @@ a{
|
|
|
470
471
|
padding:1
|
|
471
472
|
}`.replace(/\n\s*/g, '')
|
|
472
473
|
|
|
473
|
-
expect(actual).
|
|
474
|
+
expect(actual).toStrictEqual(expected)
|
|
474
475
|
```
|
|
475
476
|
|
|
476
477
|
```js
|
|
@@ -498,7 +499,7 @@ a.b{
|
|
|
498
499
|
padding:1
|
|
499
500
|
}`.replace(/\n\s*/g, '')
|
|
500
501
|
|
|
501
|
-
expect(actual).
|
|
502
|
+
expect(actual).toStrictEqual(expected)
|
|
502
503
|
```
|
|
503
504
|
|
|
504
505
|
```js
|
|
@@ -573,7 +574,7 @@ div.c2{
|
|
|
573
574
|
}
|
|
574
575
|
}`.replace(/\n\s*/g, '')
|
|
575
576
|
|
|
576
|
-
expect(actual).
|
|
577
|
+
expect(actual).toStrictEqual(expected)
|
|
577
578
|
```
|
|
578
579
|
|
|
579
580
|
```js
|
|
@@ -596,7 +597,7 @@ a.b.d,a.c.d{
|
|
|
596
597
|
margin:2
|
|
597
598
|
}`.replace(/\n\s*/g, '')
|
|
598
599
|
|
|
599
|
-
expect(actual).
|
|
600
|
+
expect(actual).toStrictEqual(expected)
|
|
600
601
|
```
|
|
601
602
|
|
|
602
603
|
```js
|
|
@@ -617,7 +618,7 @@ const expected = `
|
|
|
617
618
|
margin:2
|
|
618
619
|
}`.replace(/\n\s*/g, '')
|
|
619
620
|
|
|
620
|
-
expect(actual).
|
|
621
|
+
expect(actual).toStrictEqual(expected)
|
|
621
622
|
```
|
|
622
623
|
|
|
623
624
|
```js
|
|
@@ -638,13 +639,13 @@ const expected = `
|
|
|
638
639
|
margin:2
|
|
639
640
|
}`.replace(/\n\s*/g, '')
|
|
640
641
|
|
|
641
|
-
expect(actual).
|
|
642
|
+
expect(actual).toStrictEqual(expected)
|
|
642
643
|
```
|
|
643
644
|
|
|
644
645
|
### jsOnParse
|
|
645
646
|
|
|
646
647
|
```ts
|
|
647
|
-
|
|
648
|
+
const jsOnParse: (handlers: Partial<Record<PropertyKey, Function>>, text: string) => any;
|
|
648
649
|
```
|
|
649
650
|
|
|
650
651
|
`JSON.parse` with “JavaScript turned on”.
|
|
@@ -665,9 +666,10 @@ handlers['«handlerName»'](...«params»)
|
|
|
665
666
|
|
|
666
667
|
```js
|
|
667
668
|
const handlers = {
|
|
668
|
-
$hello: (
|
|
669
|
+
$hello: (name: string) => `Hello ${name}!`,
|
|
669
670
|
$foo: () => 'bar'
|
|
670
671
|
}
|
|
672
|
+
|
|
671
673
|
const actual = jsOnParse(handlers, `[
|
|
672
674
|
{
|
|
673
675
|
"$hello": ["World"]
|
|
@@ -688,6 +690,7 @@ const actual = jsOnParse(handlers, `[
|
|
|
688
690
|
"two": 2
|
|
689
691
|
}
|
|
690
692
|
]`)
|
|
693
|
+
|
|
691
694
|
const expected = [
|
|
692
695
|
'Hello World!',
|
|
693
696
|
{
|
|
@@ -703,13 +706,13 @@ const expected = [
|
|
|
703
706
|
}
|
|
704
707
|
]
|
|
705
708
|
|
|
706
|
-
expect(actual).
|
|
709
|
+
expect(actual).toStrictEqual(expected)
|
|
707
710
|
```
|
|
708
711
|
|
|
709
712
|
### locale
|
|
710
713
|
|
|
711
714
|
```ts
|
|
712
|
-
|
|
715
|
+
const locale: (map: Partial<Record<PropertyKey, Partial<Record<PropertyKey, string>>>>, defaultVersion: string) => (text: string, version?: string) => string;
|
|
713
716
|
```
|
|
714
717
|
|
|
715
718
|
Language translations helper.
|
|
@@ -722,24 +725,24 @@ const _ = locale({
|
|
|
722
725
|
button: { Login: 'Zaloguj' }
|
|
723
726
|
}, 'default')
|
|
724
727
|
|
|
725
|
-
expect(_('Login')).
|
|
726
|
-
expect(_('Password')).
|
|
728
|
+
expect(_('Login')).toStrictEqual('Login')
|
|
729
|
+
expect(_('Password')).toStrictEqual('Hasło')
|
|
727
730
|
|
|
728
|
-
expect(_('Undefined text')).
|
|
731
|
+
expect(_('Undefined text')).toStrictEqual('Undefined text')
|
|
729
732
|
|
|
730
|
-
expect(_('Login', 'button')).
|
|
733
|
+
expect(_('Login', 'button')).toStrictEqual('Zaloguj')
|
|
731
734
|
|
|
732
|
-
expect(_('Password', 'undefined_version')).
|
|
733
|
-
expect(_('Undefined text', 'undefined_version')).
|
|
735
|
+
expect(_('Password', 'undefined_version')).toStrictEqual('Hasło')
|
|
736
|
+
expect(_('Undefined text', 'undefined_version')).toStrictEqual('Undefined text')
|
|
734
737
|
|
|
735
|
-
expect(_('toString')).
|
|
736
|
-
expect(_('toString', 'undefined_version')).
|
|
738
|
+
expect(_('toString')).toStrictEqual('toString')
|
|
739
|
+
expect(_('toString', 'undefined_version')).toStrictEqual('toString')
|
|
737
740
|
```
|
|
738
741
|
|
|
739
742
|
### nanolight
|
|
740
743
|
|
|
741
744
|
```ts
|
|
742
|
-
|
|
745
|
+
const nanolight: (pattern: RegExp, highlighters: ((chunk: string, index: number) => HArgs1)[], code: string) => HArgs1[];
|
|
743
746
|
```
|
|
744
747
|
|
|
745
748
|
A generic helper for syntax highlighting (see also `nanolightJs`).
|
|
@@ -747,7 +750,7 @@ A generic helper for syntax highlighting (see also `nanolightJs`).
|
|
|
747
750
|
### nanolightJs
|
|
748
751
|
|
|
749
752
|
```ts
|
|
750
|
-
|
|
753
|
+
const nanolightJs: (code: string) => HArgs1[];
|
|
751
754
|
```
|
|
752
755
|
|
|
753
756
|
A helper for highlighting JavaScript.
|
|
@@ -757,14 +760,14 @@ A helper for highlighting JavaScript.
|
|
|
757
760
|
```js
|
|
758
761
|
const codeJs = 'const answerToLifeTheUniverseAndEverything = 42'
|
|
759
762
|
|
|
760
|
-
expect(h('pre', ['code', ...nanolightJs(codeJs)]).outerHTML).
|
|
763
|
+
expect(h('pre', ['code', ...nanolightJs(codeJs)]).outerHTML).toStrictEqual(
|
|
761
764
|
'<pre><code><span class="keyword">const</span> <span class="literal">answerToLifeTheUniverseAndEverything</span> <span class="operator">=</span> <span class="number">42</span></code></pre>')
|
|
762
765
|
```
|
|
763
766
|
|
|
764
767
|
### omit
|
|
765
768
|
|
|
766
769
|
```ts
|
|
767
|
-
|
|
770
|
+
const omit: <T extends Partial<Record<PropertyKey, any>>, K extends (keyof T)[]>(obj: Partial<Record<PropertyKey, any>>, keys: any[]) => Omit<T, K[number]>;
|
|
768
771
|
```
|
|
769
772
|
|
|
770
773
|
A helper that implements TypeScript’s `Omit` utility type.
|
|
@@ -774,13 +777,13 @@ A helper that implements TypeScript’s `Omit` utility type.
|
|
|
774
777
|
```js
|
|
775
778
|
const obj = { a: 42, b: '42', c: 17 }
|
|
776
779
|
|
|
777
|
-
expect(omit(obj, ['c'])).
|
|
780
|
+
expect(omit(obj, ['c'])).toStrictEqual({ a: 42, b: '42' })
|
|
778
781
|
```
|
|
779
782
|
|
|
780
783
|
### pick
|
|
781
784
|
|
|
782
785
|
```ts
|
|
783
|
-
|
|
786
|
+
const pick: <T extends Partial<Record<PropertyKey, any>>, K extends (keyof T)[]>(obj: Partial<Record<PropertyKey, any>>, keys: any[]) => Pick<T, K[number]>;
|
|
784
787
|
```
|
|
785
788
|
|
|
786
789
|
A helper that implements TypeScript’s `Pick` utility type.
|
|
@@ -790,13 +793,13 @@ A helper that implements TypeScript’s `Pick` utility type.
|
|
|
790
793
|
```js
|
|
791
794
|
const obj = { a: 42, b: '42', c: 17 }
|
|
792
795
|
|
|
793
|
-
expect(pick(obj, ['a', 'b'])).
|
|
796
|
+
expect(pick(obj, ['a', 'b'])).toStrictEqual({ a: 42, b: '42' })
|
|
794
797
|
```
|
|
795
798
|
|
|
796
799
|
### plUral
|
|
797
800
|
|
|
798
801
|
```ts
|
|
799
|
-
|
|
802
|
+
const plUral: (singular: string, plural2: string, plural5: string, value: number) => string;
|
|
800
803
|
```
|
|
801
804
|
|
|
802
805
|
A helper for choosing the correct singular and plural.
|
|
@@ -806,23 +809,23 @@ A helper for choosing the correct singular and plural.
|
|
|
806
809
|
```js
|
|
807
810
|
const auto = plUral.bind(null, 'auto', 'auta', 'aut')
|
|
808
811
|
|
|
809
|
-
expect(auto(0)).
|
|
810
|
-
expect(auto(1)).
|
|
811
|
-
expect(auto(17)).
|
|
812
|
-
expect(auto(42)).
|
|
812
|
+
expect(auto(0)).toStrictEqual('aut')
|
|
813
|
+
expect(auto(1)).toStrictEqual('auto')
|
|
814
|
+
expect(auto(17)).toStrictEqual('aut')
|
|
815
|
+
expect(auto(42)).toStrictEqual('auta')
|
|
813
816
|
|
|
814
817
|
const car = plUral.bind(null, 'car', 'cars', 'cars')
|
|
815
818
|
|
|
816
|
-
expect(car(0)).
|
|
817
|
-
expect(car(1)).
|
|
818
|
-
expect(car(17)).
|
|
819
|
-
expect(car(42)).
|
|
819
|
+
expect(car(0)).toStrictEqual('cars')
|
|
820
|
+
expect(car(1)).toStrictEqual('car')
|
|
821
|
+
expect(car(17)).toStrictEqual('cars')
|
|
822
|
+
expect(car(42)).toStrictEqual('cars')
|
|
820
823
|
```
|
|
821
824
|
|
|
822
825
|
### pro
|
|
823
826
|
|
|
824
827
|
```ts
|
|
825
|
-
|
|
828
|
+
const pro: (ref: any) => any;
|
|
826
829
|
```
|
|
827
830
|
|
|
828
831
|
A helper that protects calls to nested properties by a `Proxy` that initializes non-existent values with an empty object.
|
|
@@ -834,33 +837,33 @@ const ref = {}
|
|
|
834
837
|
|
|
835
838
|
pro(ref).one.two[3][4] = 1234
|
|
836
839
|
|
|
837
|
-
expect(ref).
|
|
840
|
+
expect(ref).toStrictEqual({ one: { two: { 3: { 4: 1234 } } } })
|
|
838
841
|
|
|
839
842
|
pro(ref).one.two.tree = 123
|
|
840
843
|
|
|
841
|
-
expect(ref).
|
|
844
|
+
expect(ref).toStrictEqual({ one: { two: { 3: { 4: 1234 }, tree: 123 } } })
|
|
842
845
|
|
|
843
846
|
pro(ref).one.two = undefined
|
|
844
847
|
|
|
845
|
-
expect(ref).
|
|
848
|
+
expect(ref).toStrictEqual({ one: { two: undefined } })
|
|
846
849
|
|
|
847
850
|
delete pro(ref).one.two
|
|
848
851
|
|
|
849
|
-
expect(ref).
|
|
852
|
+
expect(ref).toStrictEqual({ one: {} })
|
|
850
853
|
|
|
851
854
|
pro(ref).one.two.three.four
|
|
852
855
|
|
|
853
|
-
expect(ref).
|
|
856
|
+
expect(ref).toStrictEqual({ one: { two: { three: { four: {} } } } })
|
|
854
857
|
|
|
855
858
|
pro(ref).one.two.three.four = 1234
|
|
856
859
|
|
|
857
|
-
expect(ref).
|
|
860
|
+
expect(ref).toStrictEqual({ one: { two: { three: { four: 1234 } } } })
|
|
858
861
|
```
|
|
859
862
|
|
|
860
863
|
### refsInfo
|
|
861
864
|
|
|
862
865
|
```ts
|
|
863
|
-
|
|
866
|
+
const refsInfo: (...refs: any[]) => [string, string, string[]][];
|
|
864
867
|
```
|
|
865
868
|
|
|
866
869
|
A helper that provides information about the given `refs`.
|
|
@@ -872,8 +875,8 @@ It returns an array of triples: `[«name», «prototype-name», «array-of-own-p
|
|
|
872
875
|
```js
|
|
873
876
|
const info = refsInfo(Array, Function)
|
|
874
877
|
|
|
875
|
-
expect(info.find(([name]) => name === 'Array')?.[2]?.includes('length')).
|
|
876
|
-
expect(info.find(([name]) => name === 'Function')?.[2]?.includes('length')).
|
|
878
|
+
expect(info.find(([name]) => name === 'Array')?.[2]?.includes('length')).toBeTrue()
|
|
879
|
+
expect(info.find(([name]) => name === 'Function')?.[2]?.includes('length')).toBeTrue()
|
|
877
880
|
```
|
|
878
881
|
|
|
879
882
|
```js
|
|
@@ -903,9 +906,11 @@ console.log(browserFingerprint())
|
|
|
903
906
|
### s
|
|
904
907
|
|
|
905
908
|
```ts
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
+
const s: {
|
|
910
|
+
<T extends keyof SVGElementTagNameMap>(tag: T, ...args1: HArgs1[]): SVGElementTagNameMap[T];
|
|
911
|
+
<N extends Node>(node: N, ...args1: HArgs1[]): N;
|
|
912
|
+
(tagOrNode: string | Node, ...args1: HArgs1[]): Node;
|
|
913
|
+
};
|
|
909
914
|
```
|
|
910
915
|
|
|
911
916
|
A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style helper for creating and modifying `SVGElement`s (see also `h`).
|
|
@@ -925,10 +930,10 @@ A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style help
|
|
|
925
930
|
### uuid1
|
|
926
931
|
|
|
927
932
|
```ts
|
|
928
|
-
|
|
933
|
+
const uuid1: ({ date, node }?: {
|
|
929
934
|
date?: Date | undefined;
|
|
930
935
|
node?: string | undefined;
|
|
931
|
-
})
|
|
936
|
+
}) => string;
|
|
932
937
|
```
|
|
933
938
|
|
|
934
939
|
A helper that generates a UUID v1 identifier (with a creation timestamp).
|
|
@@ -942,23 +947,23 @@ A helper that generates a UUID v1 identifier (with a creation timestamp).
|
|
|
942
947
|
for (let i = 1; i <= 22136; ++i) {
|
|
943
948
|
const uuid = uuid1()
|
|
944
949
|
|
|
945
|
-
i === 1 && expect(uuid.split('-')[3]).
|
|
946
|
-
i === 4095 && expect(uuid.split('-')[3]).
|
|
947
|
-
i === 4096 && expect(uuid.split('-')[3]).
|
|
948
|
-
i === 9029 && expect(uuid.split('-')[3]).
|
|
949
|
-
i === 13398 && expect(uuid.split('-')[3]).
|
|
950
|
-
i === 16384 && expect(uuid.split('-')[3]).
|
|
951
|
-
i === 17767 && expect(uuid.split('-')[3]).
|
|
950
|
+
i === 1 && expect(uuid.split('-')[3]).toStrictEqual('8001')
|
|
951
|
+
i === 4095 && expect(uuid.split('-')[3]).toStrictEqual('8fff')
|
|
952
|
+
i === 4096 && expect(uuid.split('-')[3]).toStrictEqual('9000')
|
|
953
|
+
i === 9029 && expect(uuid.split('-')[3]).toStrictEqual('a345')
|
|
954
|
+
i === 13398 && expect(uuid.split('-')[3]).toStrictEqual('b456')
|
|
955
|
+
i === 16384 && expect(uuid.split('-')[3]).toStrictEqual('8000')
|
|
956
|
+
i === 17767 && expect(uuid.split('-')[3]).toStrictEqual('8567')
|
|
952
957
|
}
|
|
953
958
|
```
|
|
954
959
|
|
|
955
960
|
```js
|
|
956
|
-
expect(uuid1({ node: '000123456789abc' }).split('-')[4]).
|
|
957
|
-
expect(uuid1({ node: '123456789' }).split('-')[4]).
|
|
961
|
+
expect(uuid1({ node: '000123456789abc' }).split('-')[4]).toStrictEqual('123456789abc')
|
|
962
|
+
expect(uuid1({ node: '123456789' }).split('-')[4]).toStrictEqual('000123456789')
|
|
958
963
|
```
|
|
959
964
|
|
|
960
965
|
```js
|
|
961
|
-
expect(uuid1({ date: new Date(323325000000) }).startsWith('c1399400-9a71-11bd')).
|
|
966
|
+
expect(uuid1({ date: new Date(323325000000) }).startsWith('c1399400-9a71-11bd')).toBeTrue()
|
|
962
967
|
```
|
|
963
968
|
|
|
964
969
|
## License
|