@jackens/nnn 2024.2.9 → 2024.2.11

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/chartable.d.ts CHANGED
@@ -6,38 +6,32 @@
6
6
  * - `gapX`: X axis spacing
7
7
  * - `gapY`: Y axis spacing
8
8
  * - `headerColumn`: flag indicating that `table` has a header column (with X axis labels)
9
- * - `headerRow`: flag indicating that `table` has a header row (with data series labels)
10
9
  * - `id`: chart id
11
10
  * - `left`: left padding (for data series labels)
12
11
  * - `maxY`: number of Y axis lines
13
12
  * - `reverse`: flag to reverse all data series
14
13
  * - `right`: right padding (for data series labels)
14
+ * - `rotate`: flag to rotate X axis labels
15
15
  * - `singleScale`: flag to force single scale
16
16
  * - `table`: `HTMLTableElement` to extract data, data series labels and X axis labels
17
17
  * - `title`: chart title
18
18
  * - `top`: top padding (for the title)
19
- * - `xLabels`: X axis labels
20
- * - `zLabels`: data series labels
21
- * - `zxY`: chart data
22
19
  */
23
- export function chartable({ bottom, gapX, gapY, headerColumn, headerRow, id, left, maxY, reverse, right, singleScale, table, title, top, xLabels, zLabels, zxY }?: {
20
+ export function chartable({ bottom, gapX, gapY, headerColumn, id, left, maxY, reverse, right, rotate, singleScale, table, title, top }: {
24
21
  bottom?: number;
25
22
  gapX?: number;
26
23
  gapY?: number;
27
24
  headerColumn?: boolean;
28
- headerRow?: boolean;
29
25
  id?: string;
30
26
  left?: number;
31
27
  maxY?: number;
32
28
  reverse?: boolean;
33
29
  right?: number;
30
+ rotate?: boolean;
34
31
  singleScale?: boolean;
35
- table?: HTMLTableElement;
32
+ table: HTMLTableElement;
36
33
  title?: string;
37
34
  top?: number;
38
- xLabels?: string[];
39
- zLabels?: string[];
40
- zxY?: number[][];
41
35
  }): SVGSVGElement;
42
36
 
43
37
  export const tests: {};
package/chartable.js CHANGED
@@ -10,38 +10,32 @@ const COLORS = ['#e22', '#e73', '#fc3', '#ad4', '#4d9', '#3be', '#45d', '#c3e']
10
10
  * - `gapX`: X axis spacing
11
11
  * - `gapY`: Y axis spacing
12
12
  * - `headerColumn`: flag indicating that `table` has a header column (with X axis labels)
13
- * - `headerRow`: flag indicating that `table` has a header row (with data series labels)
14
13
  * - `id`: chart id
15
14
  * - `left`: left padding (for data series labels)
16
15
  * - `maxY`: number of Y axis lines
17
16
  * - `reverse`: flag to reverse all data series
18
17
  * - `right`: right padding (for data series labels)
18
+ * - `rotate`: flag to rotate X axis labels
19
19
  * - `singleScale`: flag to force single scale
20
20
  * - `table`: `HTMLTableElement` to extract data, data series labels and X axis labels
21
21
  * - `title`: chart title
22
22
  * - `top`: top padding (for the title)
23
- * - `xLabels`: X axis labels
24
- * - `zLabels`: data series labels
25
- * - `zxY`: chart data
26
23
  *
27
24
  * @param {{
28
25
  * bottom?: number;
29
26
  * gapX?: number;
30
27
  * gapY?: number;
31
28
  * headerColumn?: boolean;
32
- * headerRow?: boolean;
33
29
  * id?: string;
34
30
  * left?: number;
35
31
  * maxY?: number;
36
32
  * reverse?: boolean;
37
33
  * right?: number;
34
+ * rotate?: boolean;
38
35
  * singleScale?: boolean;
39
- * table?: HTMLTableElement;
36
+ * table: HTMLTableElement;
40
37
  * title?: string;
41
38
  * top?: number;
42
- * xLabels?: string[];
43
- * zLabels?: string[];
44
- * zxY?: number[][];
45
39
  * }} options
46
40
  */
47
41
  export const chartable = ({
@@ -49,42 +43,37 @@ export const chartable = ({
49
43
  gapX = 70,
50
44
  gapY = 30,
51
45
  headerColumn = false,
52
- headerRow = true,
53
46
  id,
54
47
  left = 200,
55
48
  maxY = 10,
56
49
  reverse = false,
57
50
  right = 200,
51
+ rotate = false,
58
52
  singleScale = false,
59
53
  table,
60
54
  title,
61
- top = 70,
62
- xLabels = [],
63
- zLabels = [],
64
- zxY = []
65
- } = {}) => {
66
- if (table != null) {
67
- const zxYNotPassed = !zxY.length
68
- const xLabelsNotPassed = !xLabels.length
69
- const zLabelsNotPassed = !zLabels.length
70
-
71
- table.querySelectorAll('tr').forEach((row, r) =>
72
- // @ts-ignore
73
- row.querySelectorAll('td,th').forEach((/** @type {HTMLTableCellElement} */ col, c) => {
74
- const x = r - +headerRow
75
- const z = c - +headerColumn
76
- const value = col.innerText
77
-
78
- if (x >= 0 && z >= 0 && zxYNotPassed) {
79
- zxY[z] = zxY[z] ?? []
80
- zxY[z][x] = parseFloat(value)
81
- } else if (x >= 0 && z < 0 && xLabelsNotPassed) {
82
- xLabels[x] = value
83
- } else if (x < 0 && z >= 0 && zLabelsNotPassed) {
84
- zLabels[z] = value
85
- }
86
- }))
87
- }
55
+ top = 70
56
+ }) => {
57
+ const /** @type {number[][]} */ zxY = []
58
+ const /** @type {string[]} */ xLabels = []
59
+ const /** @type {string[]} */ zLabels = []
60
+
61
+ table.querySelectorAll('tr').forEach((row, r) =>
62
+ // @ts-ignore
63
+ row.querySelectorAll('td,th').forEach((/** @type {HTMLTableCellElement} */ col, c) => {
64
+ const x = r - 1
65
+ const z = c - +headerColumn
66
+ const value = col.innerText
67
+
68
+ if (x >= 0 && z >= 0) {
69
+ zxY[z] = zxY[z] ?? []
70
+ zxY[z][x] = parseFloat(value)
71
+ } else if (x >= 0 && z < 0) {
72
+ xLabels[x] = value
73
+ } else if (x < 0 && z >= 0) {
74
+ zLabels[z] = value
75
+ }
76
+ }))
88
77
 
89
78
  if (reverse) {
90
79
  xLabels.reverse()
@@ -217,9 +206,10 @@ export const chartable = ({
217
206
  xLabels.length > 0
218
207
  ? ['g', { transform: `translate(${left} ${top + h})` },
219
208
  ['g', { class: 'chartable-x-labels', transform: 'translate(0 15)' },
220
- ...xi.map((x, i) => ['text',
221
- { x, y: 0, 'text-anchor': 'middle', 'alignment-baseline': 'hanging' },
222
- xLabels[i]])]]
209
+ ...xi.slice(0).map((x, i) => ['text', rotate
210
+ ? { x: 0, y: -x, 'text-anchor': 'start', 'alignment-baseline': 'hanging', transform: 'rotate(90)' }
211
+ : { x, y: 0, 'text-anchor': 'middle', 'alignment-baseline': 'hanging' },
212
+ xLabels[i]])]]
223
213
  : null
224
214
  )
225
215
  }
package/h.d.ts CHANGED
@@ -6,14 +6,14 @@ export type HArgs = [string | Node, ...HArgs1[]];
6
6
  /**
7
7
  * The type of arguments of the `h` and `s` helpers.
8
8
  */
9
- export type HArgs1 = Record<string, any> | null | undefined | Node | string | number | [string | Node, ...HArgs1[]];
9
+ export type HArgs1 = Partial<Record<PropertyKey, any>> | null | undefined | Node | string | number | [string | Node, ...HArgs1[]];
10
10
 
11
11
  /**
12
12
  * A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style helper for creating and modifying `HTMLElement`s (see also `s`).
13
13
  *
14
14
  * - The first argument of type `string` specifies the tag of the element to be created.
15
15
  * - The first argument of type `Node` specifies the element to be modified.
16
- * - All other arguments of type `Record<string, any>` are mappings of attributes and properties.
16
+ * - All other arguments of type `Partial<Record<PropertyKey, any>>` are mappings of attributes and properties.
17
17
  * Keys starting with `$` specify *properties* (without the leading `$`) to be set on the element being created or modified.
18
18
  * (Note that `$` is not a valid attribute name character.)
19
19
  * All other keys specify *attributes* to be set by `setAttribute`.
@@ -32,7 +32,7 @@ export function h(tagOrNode: string | Node, ...args1: HArgs1[]): Node;
32
32
  *
33
33
  * - The first argument of type `string` specifies the tag of the element to be created.
34
34
  * - The first argument of type `Node` specifies the element to be modified.
35
- * - All other arguments of type `Record<string, any>` are mappings of attributes and properties.
35
+ * - All other arguments of type `Partial<Record<PropertyKey, any>>` are mappings of attributes and properties.
36
36
  * Keys starting with `$` specify *properties* (without the leading `$`) to be set on the element being created or modified.
37
37
  * (Note that `$` is not a valid attribute name character.)
38
38
  * All other keys specify *attributes* to be set by `setAttributeNS`.
package/h.js CHANGED
@@ -4,7 +4,7 @@ import { is } from './is.js'
4
4
  /**
5
5
  * The type of arguments of the `h` and `s` helpers.
6
6
  *
7
- * @typedef {Record<string, any> | null | undefined | Node | string | number | HArgs} HArgs1
7
+ * @typedef {Partial<Record<PropertyKey, any>> | null | undefined | Node | string | number | HArgs} HArgs1
8
8
  */
9
9
 
10
10
  /**
@@ -113,7 +113,7 @@ const _h = (/** @type {string?=} */ namespaceURI) => {
113
113
  *
114
114
  * - The first argument of type `string` specifies the tag of the element to be created.
115
115
  * - The first argument of type `Node` specifies the element to be modified.
116
- * - All other arguments of type `Record<string, any>` are mappings of attributes and properties.
116
+ * - All other arguments of type `Partial<Record<PropertyKey, any>>` are mappings of attributes and properties.
117
117
  * Keys starting with `$` specify *properties* (without the leading `$`) to be set on the element being created or modified.
118
118
  * (Note that `$` is not a valid attribute name character.)
119
119
  * All other keys specify *attributes* to be set by `setAttribute`.
@@ -130,7 +130,7 @@ export const h = _h()
130
130
  *
131
131
  * - The first argument of type `string` specifies the tag of the element to be created.
132
132
  * - The first argument of type `Node` specifies the element to be modified.
133
- * - All other arguments of type `Record<string, any>` are mappings of attributes and properties.
133
+ * - All other arguments of type `Partial<Record<PropertyKey, any>>` are mappings of attributes and properties.
134
134
  * Keys starting with `$` specify *properties* (without the leading `$`) to be set on the element being created or modified.
135
135
  * (Note that `$` is not a valid attribute name character.)
136
136
  * All other keys specify *attributes* to be set by `setAttributeNS`.
package/jcss.d.ts CHANGED
@@ -8,7 +8,7 @@ export type JcssNode = {
8
8
  /**
9
9
  * The type of arguments of the `jcss` helper.
10
10
  */
11
- export type JcssRoot = Partial<Record<string, JcssNode>>;
11
+ export type JcssRoot = Partial<Record<PropertyKey, JcssNode>>;
12
12
 
13
13
  /**
14
14
  * A simple CSS-in-JS helper.
package/jcss.js CHANGED
@@ -11,7 +11,7 @@ import { is } from './is.js'
11
11
  /**
12
12
  * The type of arguments of the `jcss` helper.
13
13
  *
14
- * @typedef {Partial<Record<string, JcssNode>>} JcssRoot
14
+ * @typedef {Partial<Record<PropertyKey, JcssNode>>} JcssRoot
15
15
  */
16
16
 
17
17
  const _jcss = (
package/jsOnParse.d.ts CHANGED
@@ -13,7 +13,7 @@
13
13
  * handlers['«handlerName»'](...«params»)
14
14
  * ```
15
15
  */
16
- export function jsOnParse(handlers: Partial<Record<string, Function>>, text: string): any;
16
+ export function jsOnParse(handlers: Partial<Record<PropertyKey, Function>>, text: string): any;
17
17
 
18
18
  export namespace tests {
19
19
  function jsOnParse(): void;
package/jsOnParse.js CHANGED
@@ -18,7 +18,7 @@ import { is } from './is.js'
18
18
  * ```
19
19
  */
20
20
  export const jsOnParse = (
21
- /** @type {Partial<Record<string, Function>>} */ handlers,
21
+ /** @type {Partial<Record<PropertyKey, Function>>} */ handlers,
22
22
  /** @type {string} */ text
23
23
  ) => JSON.parse(text, (key, value) => {
24
24
  if (is(Object, value)) {
package/locale.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Language translations helper.
3
3
  */
4
- export function locale(map: Partial<Record<string, Partial<Record<string, string>>>>, defaultVersion: string): (text: string, version?: string) => string;
4
+ export function locale(map: Partial<Record<PropertyKey, Partial<Record<PropertyKey, string>>>>, defaultVersion: string): (text: string, version?: string) => string;
5
5
 
6
6
  export namespace tests {
7
7
  function locale(): void;
package/locale.js CHANGED
@@ -4,7 +4,7 @@ import { is } from './is.js'
4
4
  * Language translations helper.
5
5
  */
6
6
  export const locale = (
7
- /** @type {Partial<Record<string, Partial<Record<string, string>>>>} */ map,
7
+ /** @type {Partial<Record<PropertyKey, Partial<Record<PropertyKey, string>>>>} */ map,
8
8
  /** @type {string} */ defaultVersion
9
9
  ) => (
10
10
  /** @type {string} */ text,
package/package.json CHANGED
@@ -40,5 +40,5 @@
40
40
  "types": "nnn.d.ts",
41
41
  "name": "@jackens/nnn",
42
42
  "type": "module",
43
- "version": "2024.2.9"
43
+ "version": "2024.2.11"
44
44
  }
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.9</code></sub>
5
+ <sub>Version: <code class="version">2024.2.11</code></sub>
6
6
 
7
7
  ## Installation
8
8
 
@@ -75,7 +75,7 @@ The type of arguments of the `h` and `s` helpers.
75
75
  ### HArgs1
76
76
 
77
77
  ```ts
78
- export type HArgs1 = Record<string, any> | null | undefined | Node | string | number | [string | Node, ...HArgs1[]];
78
+ export type HArgs1 = Partial<Record<PropertyKey, any>> | null | undefined | Node | string | number | [string | Node, ...HArgs1[]];
79
79
  ```
80
80
 
81
81
  The type of arguments of the `h` and `s` helpers.
@@ -93,7 +93,7 @@ The type of arguments of the `jcss` helper.
93
93
  ### JcssRoot
94
94
 
95
95
  ```ts
96
- export type JcssRoot = Partial<Record<string, JcssNode>>;
96
+ export type JcssRoot = Partial<Record<PropertyKey, JcssNode>>;
97
97
  ```
98
98
 
99
99
  The type of arguments of the `jcss` helper.
@@ -101,24 +101,21 @@ The type of arguments of the `jcss` helper.
101
101
  ### chartable
102
102
 
103
103
  ```ts
104
- export function chartable({ bottom, gapX, gapY, headerColumn, headerRow, id, left, maxY, reverse, right, singleScale, table, title, top, xLabels, zLabels, zxY }?: {
104
+ export function chartable({ bottom, gapX, gapY, headerColumn, id, left, maxY, reverse, right, rotate, singleScale, table, title, top }: {
105
105
  bottom?: number;
106
106
  gapX?: number;
107
107
  gapY?: number;
108
108
  headerColumn?: boolean;
109
- headerRow?: boolean;
110
109
  id?: string;
111
110
  left?: number;
112
111
  maxY?: number;
113
112
  reverse?: boolean;
114
113
  right?: number;
114
+ rotate?: boolean;
115
115
  singleScale?: boolean;
116
- table?: HTMLTableElement;
116
+ table: HTMLTableElement;
117
117
  title?: string;
118
118
  top?: number;
119
- xLabels?: string[];
120
- zLabels?: string[];
121
- zxY?: number[][];
122
119
  }): SVGSVGElement;
123
120
  ```
124
121
 
@@ -129,19 +126,16 @@ Options:
129
126
  - `gapX`: X axis spacing
130
127
  - `gapY`: Y axis spacing
131
128
  - `headerColumn`: flag indicating that `table` has a header column (with X axis labels)
132
- - `headerRow`: flag indicating that `table` has a header row (with data series labels)
133
129
  - `id`: chart id
134
130
  - `left`: left padding (for data series labels)
135
131
  - `maxY`: number of Y axis lines
136
132
  - `reverse`: flag to reverse all data series
137
133
  - `right`: right padding (for data series labels)
134
+ - `rotate`: flag to rotate X axis labels
138
135
  - `singleScale`: flag to force single scale
139
136
  - `table`: `HTMLTableElement` to extract data, data series labels and X axis labels
140
137
  - `title`: chart title
141
138
  - `top`: top padding (for the title)
142
- - `xLabels`: X axis labels
143
- - `zLabels`: data series labels
144
- - `zxY`: chart data
145
139
 
146
140
  ### eq
147
141
 
@@ -260,7 +254,7 @@ A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style help
260
254
 
261
255
  - The first argument of type `string` specifies the tag of the element to be created.
262
256
  - The first argument of type `Node` specifies the element to be modified.
263
- - All other arguments of type `Record<string, any>` are mappings of attributes and properties.
257
+ - All other arguments of type `Partial<Record<PropertyKey, any>>` are mappings of attributes and properties.
264
258
  Keys starting with `$` specify *properties* (without the leading `$`) to be set on the element being created or modified.
265
259
  (Note that `$` is not a valid attribute name character.)
266
260
  All other keys specify *attributes* to be set by `setAttribute`.
@@ -652,7 +646,7 @@ console.assert(actual === expected)
652
646
  ### jsOnParse
653
647
 
654
648
  ```ts
655
- export function jsOnParse(handlers: Partial<Record<string, Function>>, text: string): any;
649
+ export function jsOnParse(handlers: Partial<Record<PropertyKey, Function>>, text: string): any;
656
650
  ```
657
651
 
658
652
  `JSON.parse` with “JavaScript turned on”.
@@ -717,7 +711,7 @@ console.assert(eq(actual, expected))
717
711
  ### locale
718
712
 
719
713
  ```ts
720
- export function locale(map: Partial<Record<string, Partial<Record<string, string>>>>, defaultVersion: string): (text: string, version?: string) => string;
714
+ export function locale(map: Partial<Record<PropertyKey, Partial<Record<PropertyKey, string>>>>, defaultVersion: string): (text: string, version?: string) => string;
721
715
  ```
722
716
 
723
717
  Language translations helper.
@@ -888,7 +882,7 @@ A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style help
888
882
 
889
883
  - The first argument of type `string` specifies the tag of the element to be created.
890
884
  - The first argument of type `Node` specifies the element to be modified.
891
- - All other arguments of type `Record<string, any>` are mappings of attributes and properties.
885
+ - All other arguments of type `Partial<Record<PropertyKey, any>>` are mappings of attributes and properties.
892
886
  Keys starting with `$` specify *properties* (without the leading `$`) to be set on the element being created or modified.
893
887
  (Note that `$` is not a valid attribute name character.)
894
888
  All other keys specify *attributes* to be set by `setAttributeNS`.