@jackens/nnn 2024.2.26 → 2024.3.2-18
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 +6 -6
- package/nnn.js +12 -12
- package/package.json +1 -1
- package/readme.md +49 -21
package/nnn.d.ts
CHANGED
|
@@ -127,16 +127,16 @@ export declare const is: {
|
|
|
127
127
|
};
|
|
128
128
|
|
|
129
129
|
/**
|
|
130
|
-
* The type of arguments of the `
|
|
130
|
+
* The type of arguments of the `jc` helper.
|
|
131
131
|
*/
|
|
132
|
-
export type
|
|
133
|
-
[attributeOrSelector: string]: string | number |
|
|
132
|
+
export type JcNode = {
|
|
133
|
+
[attributeOrSelector: string]: string | number | JcNode | undefined;
|
|
134
134
|
};
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
|
-
* The type of arguments of the `
|
|
137
|
+
* The type of arguments of the `jc` helper.
|
|
138
138
|
*/
|
|
139
|
-
export type
|
|
139
|
+
export type JcRoot = Partial<Record<PropertyKey, JcNode>>;
|
|
140
140
|
|
|
141
141
|
/**
|
|
142
142
|
* A simple CSS-in-JS helper.
|
|
@@ -149,7 +149,7 @@ export type JcssRoot = Partial<Record<PropertyKey, JcssNode>>;
|
|
|
149
149
|
* - Commas in keys that makes a CSS rule cause it to “split” and create separate rules for each part (e.g. `{div:{margin:1,'.a,.b,.c':{margin:2}}}` → `div{margin:1}div.a,div.b,div.c{margin:2}`).
|
|
150
150
|
* - Top-level keys that begin with `@` are not concatenated with sub-object keys.
|
|
151
151
|
*/
|
|
152
|
-
export declare const
|
|
152
|
+
export declare const jc: (root: JcRoot, splitter?: string) => string;
|
|
153
153
|
|
|
154
154
|
/**
|
|
155
155
|
* `JSON.parse` with “JavaScript turned on”.
|
package/nnn.js
CHANGED
|
@@ -215,11 +215,8 @@ var eq = (x, y) => {
|
|
|
215
215
|
var escapeValues = (escapeMap, values) => values.map((value) => (escapeMap.get(value?.constructor) ?? escapeMap.get(undefined))?.(value) ?? "");
|
|
216
216
|
var escape = (escapeMap, template, ...values) => String.raw(template, ...escapeValues(escapeMap, values));
|
|
217
217
|
|
|
218
|
-
// src/nnn/has.ts
|
|
219
|
-
var has = (key, ref) => (is(String, key) || is(Number, key) || is(Symbol, key)) && Object.hasOwnProperty.call(ref ?? Object, key);
|
|
220
|
-
|
|
221
218
|
// src/nnn/fixTypography.ts
|
|
222
|
-
var TAGS_TO_SKIP =
|
|
219
|
+
var TAGS_TO_SKIP = ["IFRAME", "NOSCRIPT", "PRE", "SCRIPT", "STYLE", "TEXTAREA"];
|
|
223
220
|
var fixTypography = (node) => {
|
|
224
221
|
const queue = [node];
|
|
225
222
|
while (queue.length > 0) {
|
|
@@ -228,7 +225,7 @@ var fixTypography = (node) => {
|
|
|
228
225
|
node0.childNodes.forEach((childNode) => {
|
|
229
226
|
if (childNode instanceof Text) {
|
|
230
227
|
queue.push(childNode);
|
|
231
|
-
} else if (childNode instanceof Element && !
|
|
228
|
+
} else if (childNode instanceof Element && !TAGS_TO_SKIP.includes(childNode.tagName)) {
|
|
232
229
|
queue.push(childNode);
|
|
233
230
|
}
|
|
234
231
|
});
|
|
@@ -250,8 +247,11 @@ var fixTypography = (node) => {
|
|
|
250
247
|
}
|
|
251
248
|
};
|
|
252
249
|
|
|
253
|
-
// src/nnn/
|
|
254
|
-
var
|
|
250
|
+
// src/nnn/has.ts
|
|
251
|
+
var has = (key, ref) => (is(String, key) || is(Number, key) || is(Symbol, key)) && Object.hasOwnProperty.call(ref ?? Object, key);
|
|
252
|
+
|
|
253
|
+
// src/nnn/jc.ts
|
|
254
|
+
var _jc = (node, prefix, result, split) => {
|
|
255
255
|
const queue = [[node, prefix]];
|
|
256
256
|
while (queue.length > 0) {
|
|
257
257
|
const [style0, prefix0] = queue.shift() ?? [];
|
|
@@ -285,7 +285,7 @@ var _jcss = (node, prefix, result, split) => {
|
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
287
|
};
|
|
288
|
-
var
|
|
288
|
+
var jc = (root, splitter = "$$") => {
|
|
289
289
|
const split = (text) => text.split(splitter)[0];
|
|
290
290
|
const chunks = [];
|
|
291
291
|
for (const key in root) {
|
|
@@ -293,10 +293,10 @@ var jcss = (root, splitter = "$$") => {
|
|
|
293
293
|
if (value != null) {
|
|
294
294
|
if (key[0] === "@") {
|
|
295
295
|
chunks.push(split(key) + "{");
|
|
296
|
-
|
|
296
|
+
_jc(value, "", chunks, split);
|
|
297
297
|
chunks.push("}");
|
|
298
298
|
} else {
|
|
299
|
-
|
|
299
|
+
_jc(value, split(key), chunks, split);
|
|
300
300
|
}
|
|
301
301
|
}
|
|
302
302
|
}
|
|
@@ -340,7 +340,7 @@ var nanolight = (pattern, highlighters, code) => {
|
|
|
340
340
|
};
|
|
341
341
|
|
|
342
342
|
// src/nnn/nanolightJs.ts
|
|
343
|
-
var nanolightJs = nanolight.bind(0, /('.*?'|".*?"|`[\s\S]*?`)|(\/\/.*?\n|\/\*[\s\S]*?\*\/)|(any|bigint|break|boolean|case|catch|const|continue|debugger|default|delete|do|else|eval|export|extends|false|finally|for|from|function|goto|if|import|in|instanceof|is|keyof|let|NaN|new|number|null|package|return|string|super|switch|symbol|this|throw|true|try|type|typeof|undefined|unknown|var|void|while|with|yield)(?!\w)|([<>=.?:&|!^~*/%+-])|(0x[\dabcdef]+|0o[01234567]+|0b[01]+|\d+(?:\.[\d_]+)?(?:e[+-]?[\d_]+)?)|([$\w]+)(?=\()|([$\wąćęłńóśżźĄĆĘŁŃÓŚŻŹ]+)/, [
|
|
343
|
+
var nanolightJs = nanolight.bind(0, /('.*?'|".*?"|`[\s\S]*?`)|(\/\/.*?\n|\/\*[\s\S]*?\*\/)|(any|bigint|break|boolean|case|catch|class|const|continue|debugger|default|delete|do|else|eval|export|extends|false|finally|for|from|function|goto|if|import|in|instanceof|is|keyof|let|NaN|new|number|null|package|return|string|super|switch|symbol|this|throw|true|try|type|typeof|undefined|unknown|var|void|while|with|yield)(?!\w)|([<>=.?:&|!^~*/%+-])|(0x[\dabcdef]+|0o[01234567]+|0b[01]+|\d+(?:\.[\d_]+)?(?:e[+-]?[\d_]+)?)|([$\w]+)(?=\()|([$\wąćęłńóśżźĄĆĘŁŃÓŚŻŹ]+)/, [
|
|
344
344
|
(chunk) => chunk,
|
|
345
345
|
(chunk) => ["span", { class: "string" }, chunk],
|
|
346
346
|
(chunk) => ["span", { class: "comment" }, chunk],
|
|
@@ -408,7 +408,7 @@ export {
|
|
|
408
408
|
nanolight,
|
|
409
409
|
locale,
|
|
410
410
|
jsOnParse,
|
|
411
|
-
|
|
411
|
+
jc,
|
|
412
412
|
is,
|
|
413
413
|
has,
|
|
414
414
|
h,
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -2,7 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Jackens’ JavaScript helpers.
|
|
4
4
|
|
|
5
|
-
<sub>Version: <code class="version">2024.2
|
|
5
|
+
<sub>Version: <code class="version">2024.3.2-18</code></sub>
|
|
6
|
+
|
|
7
|
+
## Examples
|
|
8
|
+
|
|
9
|
+
- [Chartable Demo](https://jackens.github.io/nnn/chartable/)
|
|
10
|
+
- [Chessboard Demo](https://jackens.github.io/nnn/chessboard/)
|
|
11
|
+
- [Documentation](https://jackens.github.io/nnn/doc/)
|
|
12
|
+
- [Gant Chart Demo](https://jackens.github.io/nnn/gantt/)
|
|
13
|
+
- [Responsive Web Design Demo](https://jackens.github.io/nnn/rwd/)
|
|
6
14
|
|
|
7
15
|
## Installation
|
|
8
16
|
|
|
@@ -35,8 +43,8 @@ import { «something» } from './node_modules/@jackens/nnn/nnn.js'
|
|
|
35
43
|
- `EscapeMap`: The type of arguments of the `escapeValues` and `escape` helpers.
|
|
36
44
|
- `HArgs`: The type of arguments of the `h` and `s` helpers.
|
|
37
45
|
- `HArgs1`: The type of arguments of the `h` and `s` helpers.
|
|
38
|
-
- `
|
|
39
|
-
- `
|
|
46
|
+
- `JcNode`: The type of arguments of the `jc` helper.
|
|
47
|
+
- `JcRoot`: The type of arguments of the `jc` helper.
|
|
40
48
|
- `chartable`: A helper for creating a chart based on a table (conf. <https://jackens.github.io/nnn/chartable/>).
|
|
41
49
|
- `eq`: A helper that checks equality of the given arguments.
|
|
42
50
|
- `escape`: A generic helper for escaping `values` by given `escapeMap` (in *TemplateStrings* flavor).
|
|
@@ -45,7 +53,7 @@ import { «something» } from './node_modules/@jackens/nnn/nnn.js'
|
|
|
45
53
|
- `h`: A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style helper for creating and modifying `HTMLElement`s (see also `s`).
|
|
46
54
|
- `has`: A replacement for the `in` operator (not to be confused with the `for-in` loop) that works properly.
|
|
47
55
|
- `is`: A helper that checks if the given argument is of a certain type.
|
|
48
|
-
- `
|
|
56
|
+
- `jc`: A simple CSS-in-JS helper.
|
|
49
57
|
- `jsOnParse`: `JSON.parse` with “JavaScript turned on”.
|
|
50
58
|
- `locale`: Language translations helper.
|
|
51
59
|
- `nanolight`: A generic helper for syntax highlighting (see also `nanolightJs`).
|
|
@@ -82,23 +90,23 @@ type HArgs1 = Partial<Record<PropertyKey, any>> | null | undefined | Node | stri
|
|
|
82
90
|
|
|
83
91
|
The type of arguments of the `h` and `s` helpers.
|
|
84
92
|
|
|
85
|
-
###
|
|
93
|
+
### JcNode
|
|
86
94
|
|
|
87
95
|
```ts
|
|
88
|
-
type
|
|
89
|
-
[attributeOrSelector: string]: string | number |
|
|
96
|
+
type JcNode = {
|
|
97
|
+
[attributeOrSelector: string]: string | number | JcNode | undefined;
|
|
90
98
|
};
|
|
91
99
|
```
|
|
92
100
|
|
|
93
|
-
The type of arguments of the `
|
|
101
|
+
The type of arguments of the `jc` helper.
|
|
94
102
|
|
|
95
|
-
###
|
|
103
|
+
### JcRoot
|
|
96
104
|
|
|
97
105
|
```ts
|
|
98
|
-
type
|
|
106
|
+
type JcRoot = Partial<Record<PropertyKey, JcNode>>;
|
|
99
107
|
```
|
|
100
108
|
|
|
101
|
-
The type of arguments of the `
|
|
109
|
+
The type of arguments of the `jc` helper.
|
|
102
110
|
|
|
103
111
|
### chartable
|
|
104
112
|
|
|
@@ -432,10 +440,23 @@ expect(is(Object, fakeFooBar)).toBeTrue()
|
|
|
432
440
|
expect(iz(Object, fakeFooBar)).toBeFalse()
|
|
433
441
|
```
|
|
434
442
|
|
|
435
|
-
|
|
443
|
+
```js
|
|
444
|
+
const num = 42
|
|
445
|
+
const str = '42'
|
|
446
|
+
|
|
447
|
+
expect(is(Number, num)).toBeTrue()
|
|
448
|
+
|
|
449
|
+
try {
|
|
450
|
+
num.constructor = str.constructor
|
|
451
|
+
} catch { /* empty */ }
|
|
452
|
+
|
|
453
|
+
expect(is(Number, num)).toBeTrue()
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
### jc
|
|
436
457
|
|
|
437
458
|
```ts
|
|
438
|
-
const
|
|
459
|
+
const jc: (root: JcRoot, splitter?: string) => string;
|
|
439
460
|
```
|
|
440
461
|
|
|
441
462
|
A simple CSS-in-JS helper.
|
|
@@ -451,7 +472,7 @@ The `root` parameter provides a hierarchical description of CSS rules.
|
|
|
451
472
|
#### Usage Examples
|
|
452
473
|
|
|
453
474
|
```js
|
|
454
|
-
const actual =
|
|
475
|
+
const actual = jc({
|
|
455
476
|
a: {
|
|
456
477
|
color: 'red',
|
|
457
478
|
margin: 1,
|
|
@@ -477,7 +498,7 @@ expect(actual).toStrictEqual(expected)
|
|
|
477
498
|
```
|
|
478
499
|
|
|
479
500
|
```js
|
|
480
|
-
const actual =
|
|
501
|
+
const actual = jc({
|
|
481
502
|
a: {
|
|
482
503
|
'.b': {
|
|
483
504
|
color: 'red',
|
|
@@ -505,7 +526,7 @@ expect(actual).toStrictEqual(expected)
|
|
|
505
526
|
```
|
|
506
527
|
|
|
507
528
|
```js
|
|
508
|
-
const actual =
|
|
529
|
+
const actual = jc({
|
|
509
530
|
'@font-face$$1': {
|
|
510
531
|
fontFamily: 'Jackens',
|
|
511
532
|
src$$1: 'url(otf/jackens.otf)',
|
|
@@ -580,7 +601,7 @@ expect(actual).toStrictEqual(expected)
|
|
|
580
601
|
```
|
|
581
602
|
|
|
582
603
|
```js
|
|
583
|
-
const actual =
|
|
604
|
+
const actual = jc({
|
|
584
605
|
a: {
|
|
585
606
|
'.b,.c': {
|
|
586
607
|
margin: 1,
|
|
@@ -603,7 +624,7 @@ expect(actual).toStrictEqual(expected)
|
|
|
603
624
|
```
|
|
604
625
|
|
|
605
626
|
```js
|
|
606
|
-
const actual =
|
|
627
|
+
const actual = jc({
|
|
607
628
|
'.b,.c': {
|
|
608
629
|
margin: 1,
|
|
609
630
|
'.d': {
|
|
@@ -624,7 +645,7 @@ expect(actual).toStrictEqual(expected)
|
|
|
624
645
|
```
|
|
625
646
|
|
|
626
647
|
```js
|
|
627
|
-
const actual =
|
|
648
|
+
const actual = jc({
|
|
628
649
|
'.a,.b': {
|
|
629
650
|
margin: 1,
|
|
630
651
|
'.c,.d': {
|
|
@@ -762,8 +783,15 @@ A helper for highlighting JavaScript.
|
|
|
762
783
|
```js
|
|
763
784
|
const codeJs = 'const answerToLifeTheUniverseAndEverything = 42'
|
|
764
785
|
|
|
765
|
-
expect(
|
|
766
|
-
'
|
|
786
|
+
expect(nanolightJs(codeJs)).toStrictEqual([
|
|
787
|
+
['span', { class: 'keyword' }, 'const'],
|
|
788
|
+
' ',
|
|
789
|
+
['span', { class: 'literal' }, 'answerToLifeTheUniverseAndEverything'],
|
|
790
|
+
' ',
|
|
791
|
+
['span', { class: 'operator' }, '='],
|
|
792
|
+
' ',
|
|
793
|
+
['span', { class: 'number' }, '42']
|
|
794
|
+
])
|
|
767
795
|
```
|
|
768
796
|
|
|
769
797
|
### omit
|