@jackens/nnn 2023.8.27 → 2023.9.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 +8 -1
- package/nnn.js +23 -6
- package/package.json +1 -1
package/nnn.d.ts
CHANGED
|
@@ -181,6 +181,13 @@ export function nanolightJs(codeJs: string): HArgs[1][];
|
|
|
181
181
|
*/
|
|
182
182
|
export function plUral(singular: string, plural2: string, plural5: string, value: number): string;
|
|
183
183
|
|
|
184
|
+
/**
|
|
185
|
+
* A helper that provides information about the given `refs`.
|
|
186
|
+
*
|
|
187
|
+
* It returns an array of triples: `[«name», «prototype-name», «array-of-own-property-names»]`.
|
|
188
|
+
*/
|
|
189
|
+
export function refsInfo(...refs: any[]): [string, string, string[]][];
|
|
190
|
+
|
|
184
191
|
/**
|
|
185
192
|
* A lightweight [HyperScript](https://github.com/hyperhype/hyperscript)-style helper for creating and modifying `SVGElement`s (see also `h`).
|
|
186
193
|
*
|
|
@@ -214,4 +221,4 @@ export function set(value: any, ref: any, ...keys: (string | number | symbol)[])
|
|
|
214
221
|
export function uuid1(options?: {
|
|
215
222
|
date?: Date;
|
|
216
223
|
node?: string;
|
|
217
|
-
}): string;
|
|
224
|
+
}): string;
|
package/nnn.js
CHANGED
|
@@ -260,11 +260,11 @@ export const escape = (
|
|
|
260
260
|
) => String.raw(template, ...escapeValues(escapeMap, values))
|
|
261
261
|
|
|
262
262
|
export const escapeValues = (
|
|
263
|
-
/** @type {EscapeMap}
|
|
264
|
-
/** @type {any[]}
|
|
263
|
+
/** @type {EscapeMap} */ escapeMap,
|
|
264
|
+
/** @type {any[]} */ values
|
|
265
265
|
) => values.map(value => (escapeMap.get(value?.constructor) ?? escapeMap.get(undefined))?.(value) ?? '')
|
|
266
266
|
|
|
267
|
-
const
|
|
267
|
+
const _TAGS_TO_SKIP = { IFRAME: 1, NOSCRIPT: 1, PRE: 1, SCRIPT: 1, STYLE: 1, TEXTAREA: 1 }
|
|
268
268
|
|
|
269
269
|
export const fixTypography = (/** @type {Node} */ node) => {
|
|
270
270
|
const /** @type {Node[]} */ queue = [node]
|
|
@@ -278,7 +278,7 @@ export const fixTypography = (/** @type {Node} */ node) => {
|
|
|
278
278
|
|
|
279
279
|
if (childNode instanceof Text) {
|
|
280
280
|
queue.push(childNode)
|
|
281
|
-
} else if (childNode instanceof Element && !has(childNode.tagName,
|
|
281
|
+
} else if (childNode instanceof Element && !has(childNode.tagName, _TAGS_TO_SKIP)) {
|
|
282
282
|
queue.push(childNode)
|
|
283
283
|
}
|
|
284
284
|
}
|
|
@@ -322,7 +322,7 @@ export const get = (
|
|
|
322
322
|
return ref
|
|
323
323
|
}
|
|
324
324
|
|
|
325
|
-
const /** @type {Record<string, string>} */
|
|
325
|
+
const /** @type {Record<string, string>} */ _NS = {
|
|
326
326
|
xlink: 'http://www.w3.org/1999/xlink'
|
|
327
327
|
}
|
|
328
328
|
|
|
@@ -379,7 +379,7 @@ const _h = (/** @type {string?=} */ namespaceURI) => {
|
|
|
379
379
|
const indexOfColon = name.indexOf(':')
|
|
380
380
|
|
|
381
381
|
if (indexOfColon >= 0) {
|
|
382
|
-
const /** @type {string=} */ ns =
|
|
382
|
+
const /** @type {string=} */ ns = _NS[name.slice(0, indexOfColon)]
|
|
383
383
|
|
|
384
384
|
if (ns != null) {
|
|
385
385
|
const basename = name.slice(indexOfColon + 1)
|
|
@@ -617,6 +617,23 @@ export const plUral = (
|
|
|
617
617
|
: plural5
|
|
618
618
|
}
|
|
619
619
|
|
|
620
|
+
export const refsInfo = (/** @type {any[]} */ ...refs) => {
|
|
621
|
+
const /** @type {Set<Function>} */ fns = new Set()
|
|
622
|
+
|
|
623
|
+
refs.forEach(ref => {
|
|
624
|
+
while (is(Function, ref) && !fns.has(ref) && ref.toString?.()?.includes?.('[native code]')) {
|
|
625
|
+
fns.add(ref)
|
|
626
|
+
ref = Object.getPrototypeOf(ref)
|
|
627
|
+
}
|
|
628
|
+
})
|
|
629
|
+
|
|
630
|
+
return Array.from(fns.values()).map(/** @returns {[string, string, string[]]} */ fn => [
|
|
631
|
+
fn.name,
|
|
632
|
+
Object.getPrototypeOf(fn)?.name ?? '',
|
|
633
|
+
Object.getOwnPropertyNames(fn.prototype ?? Object.create(null)).sort()
|
|
634
|
+
]).sort((a, b) => -(a[0] < b[0]))
|
|
635
|
+
}
|
|
636
|
+
|
|
620
637
|
export const s = _h('http://www.w3.org/2000/svg')
|
|
621
638
|
|
|
622
639
|
export const set = (
|
package/package.json
CHANGED