@jackens/nnn 2024.2.19 → 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 CHANGED
@@ -1,21 +1,220 @@
1
- import { chartable } from './chartable.js';
2
- import { eq } from './eq.js';
3
- import { escape } from './escape.js';
4
- import { escapeValues } from './escape.js';
5
- import { fixTypography } from './fixTypography.js';
6
- import { h } from './h.js';
7
- import { has } from './has.js';
8
- import { is } from './is.js';
9
- import { jcss } from './jcss.js';
10
- import { jsOnParse } from './jsOnParse.js';
11
- import { locale } from './locale.js';
12
- import { nanolight } from './nanolight.js';
13
- import { nanolightJs } from './nanolightJs.js';
14
- import { omit } from './pick.js';
15
- import { pick } from './pick.js';
16
- import { plUral } from './plUral.js';
17
- import { pro } from './pro.js';
18
- import { refsInfo } from './refsInfo.js';
19
- import { s } from './h.js';
20
- import { uuid1 } from './uuid1.js';
21
- export { chartable, eq, escape, escapeValues, fixTypography, h, has, is, jcss, jsOnParse, locale, nanolight, nanolightJs, omit, pick, plUral, pro, refsInfo, s, uuid1 };
1
+ /**
2
+ * A helper for creating a chart based on a table (conf. <https://jackens.github.io/nnn/chartable/>).
3
+ *
4
+ * Options:
5
+ * - `table`: `HTMLTableElement` to extract data, data series labels and X axis labels
6
+ * - `headerColumn`: flag indicating that `table` has a header column with X axis labels
7
+ * - `xGap`: X axis spacing
8
+ * - `xLabelsMinHeight`: minimal height of X axis labels
9
+ * - `xLabelsRotate`: flag to rotate X axis labels
10
+ * - `xReverse`: flag to reverse all data series
11
+ * - `yGap`: Y axis spacing
12
+ * - `yLabelsLeftMinWidth`: minimal width of Y axis left labels
13
+ * - `yLabelsRightMinWidth`: minimal width of Y axis right labels
14
+ * - `yMax`: number of Y axis lines
15
+ * - `zLabelsMinWidth`: minimal width of data series labels
16
+ * - `zyMappings`: mappings per data series
17
+ */
18
+ export declare const chartable: ({ table, headerColumn, xGap, xLabelsMinHeight, xLabelsRotate, xReverse, yGap, yLabelsLeftMinWidth, yLabelsRightMinWidth, yMax, zLabelsMinWidth, zyMappings }: {
19
+ table: HTMLTableElement;
20
+ headerColumn?: boolean | undefined;
21
+ xGap?: number | undefined;
22
+ xLabelsMinHeight?: number | undefined;
23
+ xLabelsRotate?: boolean | undefined;
24
+ xReverse?: boolean | undefined;
25
+ yGap?: number | undefined;
26
+ yLabelsLeftMinWidth?: number | undefined;
27
+ yLabelsRightMinWidth?: number | undefined;
28
+ yMax?: number | undefined;
29
+ zLabelsMinWidth?: number | undefined;
30
+ zyMappings?: [(label: string) => number, (value: number) => string][] | undefined;
31
+ }) => SVGSVGElement;
32
+
33
+ /**
34
+ * A helper that checks equality of the given arguments.
35
+ */
36
+ export declare const eq: (x: any, y: any) => boolean;
37
+
38
+ /**
39
+ * The type of arguments of the `escapeValues` and `escape` helpers.
40
+ */
41
+ export type EscapeMap = Map<any, (value?: any) => string>;
42
+
43
+ /**
44
+ * A generic helper for escaping `values` by given `escapeMap`.
45
+ */
46
+ export declare const escapeValues: (escapeMap: EscapeMap, values: any[]) => string[];
47
+
48
+ /**
49
+ * A generic helper for escaping `values` by given `escapeMap` (in *TemplateStrings* flavor).
50
+ */
51
+ export declare const escape: (escapeMap: EscapeMap, template: TemplateStringsArray, ...values: any[]) => string;
52
+
53
+ /**
54
+ * A helper that implements typographic corrections specific to Polish typography.
55
+ */
56
+ export declare const fixTypography: (node: Node) => void;
57
+
58
+ /**
59
+ * The type of arguments of the `h` and `s` helpers.
60
+ */
61
+ export type HArgs1 = Partial<Record<PropertyKey, any>> | null | undefined | Node | string | number | HArgs;
62
+
63
+ /**
64
+ * The type of arguments of the `h` and `s` helpers.
65
+ */
66
+ export type HArgs = [string | Node, ...HArgs1[]];
67
+
68
+ /**
69
+ * A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style helper for creating and modifying `HTMLElement`s (see also `s`).
70
+ *
71
+ * - The first argument of type `string` specifies the tag of the element to be created.
72
+ * - The first argument of type `Node` specifies the element to be modified.
73
+ * - All other arguments of type `Partial<Record<PropertyKey, any>>` are mappings of attributes and properties.
74
+ * Keys starting with `$` specify *properties* (without the leading `$`) to be set on the element being created or modified.
75
+ * (Note that `$` is not a valid attribute name character.)
76
+ * All other keys specify *attributes* to be set by `setAttribute`.
77
+ * An attribute equal to `false` causes the attribute to be removed by `removeAttribute`.
78
+ * - All other arguments of type `null` or `undefined` are simply ignored.
79
+ * - All other arguments of type `Node` are appended to the element being created or modified.
80
+ * - All other arguments of type `string`/`number` are converted to `Text` nodes and appended to the element being created or modified.
81
+ * - All other arguments of type `HArgs` are passed to `h` and the results are appended to the element being created or modified.
82
+ */
83
+ export declare const h: {
84
+ <T extends keyof HTMLElementTagNameMap>(tag: T, ...args1: HArgs1[]): HTMLElementTagNameMap[T];
85
+ <N extends Node>(node: N, ...args1: HArgs1[]): N;
86
+ (tagOrNode: string | Node, ...args1: HArgs1[]): Node;
87
+ };
88
+
89
+ /**
90
+ * A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style helper for creating and modifying `SVGElement`s (see also `h`).
91
+ *
92
+ * - The first argument of type `string` specifies the tag of the element to be created.
93
+ * - The first argument of type `Node` specifies the element to be modified.
94
+ * - All other arguments of type `Partial<Record<PropertyKey, any>>` are mappings of attributes and properties.
95
+ * Keys starting with `$` specify *properties* (without the leading `$`) to be set on the element being created or modified.
96
+ * (Note that `$` is not a valid attribute name character.)
97
+ * All other keys specify *attributes* to be set by `setAttributeNS`.
98
+ * An attribute equal to `false` causes the attribute to be removed by `removeAttributeNS`.
99
+ * - All other arguments of type `null` or `undefined` are simply ignored.
100
+ * - All other arguments of type `Node` are appended to the element being created or modified.
101
+ * - All other arguments of type `string`/`number` are converted to `Text` nodes and appended to the element being created or modified.
102
+ * - All other arguments of type `HArgs` are passed to `s` and the results are appended to the element being created or modified.
103
+ */
104
+ export declare const s: {
105
+ <T extends keyof SVGElementTagNameMap>(tag: T, ...args1: HArgs1[]): SVGElementTagNameMap[T];
106
+ <N extends Node>(node: N, ...args1: HArgs1[]): N;
107
+ (tagOrNode: string | Node, ...args1: HArgs1[]): Node;
108
+ };
109
+
110
+ /**
111
+ * A replacement for the `in` operator (not to be confused with the `for-in` loop) that works properly.
112
+ */
113
+ export declare const has: (key: any, ref: any) => boolean;
114
+
115
+ /**
116
+ * A helper that checks if the given argument is of a certain type.
117
+ */
118
+ export declare function is(type: BigIntConstructor, arg: any): arg is bigint;
119
+ export declare function is(type: BooleanConstructor, arg: any): arg is boolean;
120
+ export declare function is(type: NumberConstructor, arg: any): arg is number;
121
+ export declare function is(type: ObjectConstructor, arg: any): arg is Partial<Record<PropertyKey, any>>;
122
+ export declare function is(type: StringConstructor, arg: any): arg is string;
123
+ export declare function is(type: SymbolConstructor, arg: any): arg is symbol;
124
+ export declare function is(type: undefined, arg: any): arg is undefined | null;
125
+ export declare function is<T extends abstract new (...args: any[]) => any>(type: T, arg: any): arg is InstanceType<T>;
126
+
127
+ /**
128
+ * The type of arguments of the `jcss` helper.
129
+ */
130
+ export type JcssNode = {
131
+ [attributeOrSelector: string]: string | number | JcssNode | undefined;
132
+ };
133
+
134
+ /**
135
+ * The type of arguments of the `jcss` helper.
136
+ */
137
+ export type JcssRoot = Partial<Record<PropertyKey, JcssNode>>;
138
+
139
+ /**
140
+ * A simple CSS-in-JS helper.
141
+ *
142
+ * The `root` parameter provides a hierarchical description of CSS rules.
143
+ *
144
+ * - Keys of sub-objects whose values are NOT objects are treated as CSS attribute, and values are treated as values of those CSS attributes; the concatenation of keys of all parent objects is a CSS rule.
145
+ * - All keys ignore the part starting with a splitter (default: `$$`) sign until the end of the key (e.g. `src$$1` → `src`, `@font-face$$1` → `@font-face`).
146
+ * - In keys specifying CSS attribute, all uppercase letters are replaced by lowercase letters with an additional `-` character preceding them (e.g. `fontFamily` → `font-family`).
147
+ * - 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}`).
148
+ * - Top-level keys that begin with `@` are not concatenated with sub-object keys.
149
+ */
150
+ export declare const jcss: (root: JcssRoot, splitter?: string) => string;
151
+
152
+ /**
153
+ * `JSON.parse` with “JavaScript turned on”.
154
+ *
155
+ * Objects having *exactly* one property which is present in the `handlers` map, i.e. objects of the form:
156
+ *
157
+ * ```js
158
+ * { "«handlerName»": [«params»] }
159
+ * ```
160
+ *
161
+ * are replaced by the result of call
162
+ *
163
+ * ```js
164
+ * handlers['«handlerName»'](...«params»)
165
+ * ```
166
+ */
167
+ export declare const jsOnParse: (handlers: Partial<Record<PropertyKey, Function>>, text: string) => any;
168
+
169
+ /**
170
+ * Language translations helper.
171
+ */
172
+ export declare const locale: (map: Partial<Record<PropertyKey, Partial<Record<PropertyKey, string>>>>, defaultVersion: string) => (text: string, version?: string) => string;
173
+
174
+ /**
175
+ * A generic helper for syntax highlighting (see also `nanolightJs`).
176
+ */
177
+ export declare const nanolight: (pattern: RegExp, highlighters: ((chunk: string, index: number) => HArgs1)[], code: string) => HArgs1[];
178
+
179
+ /**
180
+ * A helper for highlighting JavaScript.
181
+ */
182
+ export declare const nanolightJs: (code: string) => HArgs1[];
183
+
184
+ /**
185
+ * A helper that implements TypeScript’s `Pick` utility type.
186
+ */
187
+ export declare const pick: <T extends Partial<Record<PropertyKey, any>>, K extends (keyof T)[]>(obj: Partial<Record<PropertyKey, any>>, keys: any[]) => Pick<T, K[number]>;
188
+
189
+ /**
190
+ * A helper that implements TypeScript’s `Omit` utility type.
191
+ */
192
+ export declare const omit: <T extends Partial<Record<PropertyKey, any>>, K extends (keyof T)[]>(obj: Partial<Record<PropertyKey, any>>, keys: any[]) => Omit<T, K[number]>;
193
+
194
+ /**
195
+ * A helper for choosing the correct singular and plural.
196
+ */
197
+ export declare const plUral: (singular: string, plural2: string, plural5: string, value: number) => string;
198
+
199
+ /**
200
+ * A helper that protects calls to nested properties by a `Proxy` that initializes non-existent values with an empty object.
201
+ */
202
+ export declare const pro: (ref: any) => any;
203
+
204
+ /**
205
+ * A helper that provides information about the given `refs`.
206
+ *
207
+ * It returns an array of triples: `[«name», «prototype-name», «array-of-own-property-names»]`.
208
+ */
209
+ export declare const refsInfo: (...refs: any[]) => [string, string, string[]][];
210
+
211
+ /**
212
+ * A helper that generates a UUID v1 identifier (with a creation timestamp).
213
+ *
214
+ * - The optional `node` parameter should have the format `/^[0123456789abcdef]+$/`.
215
+ * Its value will be trimmed to last 12 characters and left padded with zeros.
216
+ */
217
+ export declare const uuid1: ({ date, node }?: {
218
+ date?: Date | undefined;
219
+ node?: string | undefined;
220
+ }) => string;