@jackens/nnn 2023.11.3 → 2023.11.4

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.
Files changed (2) hide show
  1. package/nnn.js +1 -128
  2. package/package.json +1 -1
package/nnn.js CHANGED
@@ -1,26 +1,6 @@
1
1
  const _COLORS = ['#e22', '#e73', '#fc3', '#ad4', '#4d9', '#3be', '#45d', '#c3e']
2
2
 
3
3
  /**
4
- * A helper for creating a chart based on a table (conf. <https://jackens.github.io/nnn/chartable/>).
5
- *
6
- * Options:
7
- * - `bottom`: bottom padding (for X axis labels)
8
- * - `gapX`: X axis spacing
9
- * - `gapY`: Y axis spacing
10
- * - `headerColumn`: flag indicating that `table` has a header column (with X axis labels)
11
- * - `headerRow`: flag indicating that `table` has a header row (with data series labels)
12
- * - `id`: chart id
13
- * - `left`: left padding (for data series labels)
14
- * - `maxY`: number of Y axis lines
15
- * - `right`: right padding (for data series labels)
16
- * - `singleScale`: flag to force single scale
17
- * - `table`: `HTMLTableElement` to extract data, data series labels and X axis labels
18
- * - `title`: chart title
19
- * - `top`: top padding (for the title)
20
- * - `xLabels`: X axis labels
21
- * - `zLabels`: data series labels
22
- * - `zxY`: chart data
23
- *
24
4
  * @param {{
25
5
  * bottom?: number;
26
6
  * gapX?: number;
@@ -209,9 +189,6 @@ export const chartable = ({
209
189
  )
210
190
  }
211
191
 
212
- /**
213
- * A helper that checks equality of the given arguments.
214
- */
215
192
  export const eq = /** @return {boolean} */ (/** @type {any} */ x, /** @type {any} */ y) => {
216
193
  if (x === y) {
217
194
  return true
@@ -256,21 +233,13 @@ export const eq = /** @return {boolean} */ (/** @type {any} */ x, /** @type {any
256
233
 
257
234
  /**
258
235
  * @typedef {Map<any, (value?: any) => string>} EscapeMap
259
- *
260
- * The type of arguments of the `escapeValues` and `escape` helpers.
261
236
  */
262
237
 
263
- /**
264
- * A generic helper for escaping `values` by given `escapeMap`.
265
- */
266
238
  export const escapeValues = (
267
239
  /** @type {EscapeMap} */ escapeMap,
268
240
  /** @type {any[]} */ values
269
241
  ) => values.map(value => (escapeMap.get(value?.constructor) ?? escapeMap.get(undefined))?.(value) ?? '')
270
242
 
271
- /**
272
- * A generic helper for escaping `values` by given `escapeMap` (in *TemplateStrings* flavor).
273
- */
274
243
  export const escape = (
275
244
  /** @type {EscapeMap} */ escapeMap,
276
245
  /** @type {TemplateStringsArray} */ template,
@@ -279,9 +248,6 @@ export const escape = (
279
248
 
280
249
  const _TAGS_TO_SKIP = { IFRAME: 1, NOSCRIPT: 1, PRE: 1, SCRIPT: 1, STYLE: 1, TEXTAREA: 1 }
281
250
 
282
- /**
283
- * A helper that implements typographic corrections specific to Polish typography.
284
- */
285
251
  export const fixTypography = (/** @type {Node} */ node) => {
286
252
  const /** @type {Node[]} */ queue = [node]
287
253
 
@@ -327,8 +293,6 @@ export const fixTypography = (/** @type {Node} */ node) => {
327
293
  * string | Node,
328
294
  * ...(Record<string, any> | null | undefined | Node | string | number | HArgs)[]
329
295
  * ]} HArgs
330
- *
331
- * The type of arguments of the `h` and `s` helpers.
332
296
  */
333
297
 
334
298
  const /** @type {Record<string, string>} */ _NS = {
@@ -425,48 +389,13 @@ const _h = (/** @type {string?=} */ namespaceURI) => {
425
389
  return h
426
390
  }
427
391
 
428
- /**
429
- * A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style helper for creating and modifying `HTMLElement`s (see also `s`).
430
- *
431
- * - The first argument of type `string` specifies the tag of the element to be created.
432
- * - The first argument of type `Node` specifies the element to be modified.
433
- * - All other arguments of type `Record<string, any>` are mappings of attributes and properties.
434
- * Keys starting with `$` specify *properties* (without the leading `$`) to be set on the element being created or modified.
435
- * (Note that `$` is not a valid attribute name character.)
436
- * All other keys specify *attributes* to be set by `setAttribute`.
437
- * An attribute equal to `false` causes the attribute to be removed by `removeAttribute`.
438
- * - All other arguments of type `null` or `undefined` are simply ignored.
439
- * - All other arguments of type `Node` are appended to the element being created or modified.
440
- * - All other arguments of type `string`/`number` are converted to `Text` nodes and appended to the element being created or modified.
441
- * - All other arguments of type `HArgs` are passed to `h` and the results are appended to the element being created or modified.
442
- */
443
392
  export const h = _h()
444
393
 
445
- /**
446
- * A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style helper for creating and modifying `SVGElement`s (see also `h`).
447
- *
448
- * - The first argument of type `string` specifies the tag of the element to be created.
449
- * - The first argument of type `Node` specifies the element to be modified.
450
- * - All other arguments of type `Record<string, any>` are mappings of attributes and properties.
451
- * Keys starting with `$` specify *properties* (without the leading `$`) to be set on the element being created or modified.
452
- * (Note that `$` is not a valid attribute name character.)
453
- * All other keys specify *attributes* to be set by `setAttributeNS`.
454
- * An attribute equal to `false` causes the attribute to be removed by `removeAttributeNS`.
455
- * - All other arguments of type `null` or `undefined` are simply ignored.
456
- * - All other arguments of type `Node` are appended to the element being created or modified.
457
- * - All other arguments of type `string`/`number` are converted to `Text` nodes and appended to the element being created or modified.
458
- * - All other arguments of type `HArgs` are passed to `s` and the results are appended to the element being created or modified.
459
- */
460
394
  export const s = _h('http://www.w3.org/2000/svg')
461
395
 
462
- /**
463
- * A replacement for the `in` operator (not to be confused with the `for-in` loop) that works properly.
464
- */
465
396
  export const has = (/** @type {any} */ key, /** @type {any} */ ref) => (is(String, key) || is(Number, key) || is(Symbol, key)) && Object.hasOwnProperty.call(ref ?? Object, key)
466
397
 
467
398
  /**
468
- * A helper that checks if the given argument is of a certain type.
469
- *
470
399
  * @template {abstract new (...args: any[]) => any} T
471
400
  *
472
401
  * @type {{
@@ -487,14 +416,10 @@ export const is = (/** @type {T} */ type, /** @type {any} */ arg) => arg?.constr
487
416
  * @typedef {{
488
417
  * [attributeOrSelector: string]: string | number | JcssNode;
489
418
  * }} JcssNode
490
- *
491
- * The type of arguments of the `jcss` helper.
492
419
  */
493
420
 
494
421
  /**
495
422
  * @typedef {Record<string, JcssNode>} JcssRoot
496
- *
497
- * The type of arguments of the `jcss` helper.
498
423
  */
499
424
 
500
425
  const _jcss = (
@@ -551,17 +476,6 @@ const _jcss = (
551
476
  }
552
477
  }
553
478
 
554
- /**
555
- * A simple CSS-in-JS helper.
556
- *
557
- * The `root` parameter provides a hierarchical description of CSS rules.
558
- *
559
- * - 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.
560
- * - 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`).
561
- * - In keys specifying CSS attribute, all uppercase letters are replaced by lowercase letters with an additional `-` character preceding them (e.g. `fontFamily` → `font-family`).
562
- * - 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}`).
563
- * - Top-level keys that begin with `@` are not concatenated with sub-object keys.
564
- */
565
479
  export const jcss = (/** @type {JcssRoot} */ root, splitter = '$$') => {
566
480
  const split = (/** @type {string} */ text) => text.split(splitter)[0]
567
481
  const /** @type {string[]} */ result = []
@@ -581,21 +495,6 @@ export const jcss = (/** @type {JcssRoot} */ root, splitter = '$$') => {
581
495
  return result.join('')
582
496
  }
583
497
 
584
- /**
585
- * `JSON.parse` with “JavaScript turned on”.
586
- *
587
- * Objects having *exactly* one property which is present in the `handlers` map, i.e. objects of the form:
588
- *
589
- * ```js
590
- * { "«handlerName»": [«params»] }
591
- * ```
592
- *
593
- * are replaced by the result of call
594
- *
595
- * ```js
596
- * handlers['«handlerName»'](...«params»)
597
- * ```
598
- */
599
498
  export const jsOnParse = (
600
499
  /** @type {Record<string, Function>} */ handlers,
601
500
  /** @type {string} */ text
@@ -636,9 +535,6 @@ const _locale = (
636
535
  return is(String, t) ? t : text
637
536
  }
638
537
 
639
- /**
640
- * Language translations helper.
641
- */
642
538
  export const locale = (
643
539
  /** @type {Record<string, Record<string, string | Record<string, string>>>} */ locales,
644
540
  /** @type {string} */ defaultLanguage,
@@ -655,9 +551,6 @@ export const locale = (
655
551
  return _locale.bind(0, locales, defaultLanguage)
656
552
  }
657
553
 
658
- /**
659
- * A generic helper for syntax highlighting (see also `nanolightJs`).
660
- */
661
554
  export const nanolight = (
662
555
  /** @type {RegExp} */ pattern,
663
556
  /** @type {((chunk: string, index: number) => import('./h.js').HArgs[1])[]} */ highlighters,
@@ -675,9 +568,6 @@ export const nanolight = (
675
568
  return result
676
569
  }
677
570
 
678
- /**
679
- * A helper for highlighting JavaScript.
680
- */
681
571
  // @ts-expect-error
682
572
  export const nanolightJs = nanolight.bind(0,
683
573
  /('.*?'|".*?"|`[\s\S]*?`)|(\/\/.*?\n|\/\*[\s\S]*?\*\/)|(break|case|catch|const|continue|debugger|default|delete|do|else|eval|export\s+type|export|extends|false|finally|for|from|function|goto|if|import|in|instanceof|is|keyof|let|NaN|new|null|package|return|super|switch|this|throw|true|try|typeof|undefined|var|void|while|with|yield)(?!\w)|([<>=.?:&|!~*/%+-])|(0x[\dabcdef]+|0o[01234567]+|0b[01]+|\d+(?:\.[\d_]+)?(?:e[+-]?[\d_]+)?)|([$\w]+)(?=\()|([$\wąćęłńóśżźĄĆĘŁŃÓŚŻŹ]+)/,
@@ -693,9 +583,6 @@ export const nanolightJs = nanolight.bind(0,
693
583
  ]
694
584
  )
695
585
 
696
- /**
697
- * A helper for choosing the correct singular and plural.
698
- */
699
586
  export const plUral = (
700
587
  /** @type {string} */ singular,
701
588
  /** @type {string} */ plural2,
@@ -714,9 +601,6 @@ export const plUral = (
714
601
  : plural5
715
602
  }
716
603
 
717
- /**
718
- * A helper that protect calls to nested properties by `Proxy` which initializes non-existent values with an empty object.
719
- */
720
604
  // @ts-expect-error
721
605
  export const pro = (/** @type {any} */ ref) => new Proxy(ref, {
722
606
  get (target, key) {
@@ -724,11 +608,6 @@ export const pro = (/** @type {any} */ ref) => new Proxy(ref, {
724
608
  }
725
609
  })
726
610
 
727
- /**
728
- * A helper that provides information about the given `refs`.
729
- *
730
- * It returns an array of triples: `[«name», «prototype-name», «array-of-own-property-names»]`.
731
- */
732
611
  export const refsInfo = (/** @type {any[]} */ ...refs) => {
733
612
  const /** @type {Set<Function>} */ fns = new Set()
734
613
 
@@ -749,12 +628,6 @@ export const refsInfo = (/** @type {any[]} */ ...refs) => {
749
628
  const ZEROS = '0'.repeat(16)
750
629
  let counter = 0
751
630
 
752
- /**
753
- * A helper that generates a UUID v1 identifier (with a creation timestamp).
754
- *
755
- * - The optional `node` parameter should have the format `/^[0123456789abcdef]+$/`.
756
- * Its value will be trimmed to last 12 characters and left padded with zeros.
757
- */
758
631
  export const uuid1 = ({
759
632
  date = new Date(),
760
633
  node = Math.random().toString(16).slice(2)
@@ -774,4 +647,4 @@ export const uuid1 = ({
774
647
  (ZEROS + (counter & 4095).toString(16)).slice(-3),
775
648
  '-',
776
649
  (ZEROS + node).slice(-12))
777
- }
650
+ }
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": "2023.11.3"
43
+ "version": "2023.11.4"
44
44
  }