@untemps/utils 4.0.0-beta.15 → 4.0.0-beta.17
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/README.md
CHANGED
|
@@ -39,4 +39,49 @@ import { interpolate } from '@untemps/utils/string/interpolate'
|
|
|
39
39
|
|
|
40
40
|
```js
|
|
41
41
|
const { isNil } = require('@untemps/utils')
|
|
42
|
-
```
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Available utilities
|
|
45
|
+
|
|
46
|
+
Every utility is exported both from the package root and per-module at `@untemps/utils/<category>/<name>`. See the [Docs](https://utils.untemps.net) for full signatures, parameters, and examples.
|
|
47
|
+
|
|
48
|
+
### array
|
|
49
|
+
- **`extractByIndices`** — extract values from an array at the given indices
|
|
50
|
+
|
|
51
|
+
### async
|
|
52
|
+
- **`debounce`** — delay invocation until after a quiet period; returns a function with `.cancel()`
|
|
53
|
+
- **`standby`** — return a promise that resolves after the given delay
|
|
54
|
+
- **`throttle`** — invoke at most once per interval (leading + trailing); returns a function with `.cancel()`
|
|
55
|
+
|
|
56
|
+
### dom
|
|
57
|
+
- **`createElement`** — create a DOM element from a configuration object
|
|
58
|
+
- **`doElementsOverlap`** — check whether two DOM elements overlap on screen
|
|
59
|
+
- **`getCSSDeclaration`** — find a CSS rule by class name across `document.styleSheets`
|
|
60
|
+
- **`getElement`** — query a DOM element by selector
|
|
61
|
+
- **`isElement`** — check whether a value is a DOM element
|
|
62
|
+
- **`modifyElement`** — set attributes on a DOM element (by reference or selector)
|
|
63
|
+
- **`removeElement`** — remove a DOM element (by reference or selector)
|
|
64
|
+
- **`resolveClassName`** — aggregate class names from strings or `[condition, ifTrue, ifFalse]` tuples
|
|
65
|
+
|
|
66
|
+
### function
|
|
67
|
+
- **`isFunction`** — check whether a value is a function
|
|
68
|
+
|
|
69
|
+
### lang
|
|
70
|
+
- **`isNil`** — check whether a value is `null` or `undefined`
|
|
71
|
+
|
|
72
|
+
### number
|
|
73
|
+
- **`clamp`** — clamp a number between two bounds
|
|
74
|
+
- **`getRandomInteger`** — return a pseudo-random integer in `[min, max]`
|
|
75
|
+
- **`normalizeMinMax`** — return `[min, max]` ensuring `min <= max`
|
|
76
|
+
|
|
77
|
+
### object
|
|
78
|
+
- **`deepClone`** — structured-clone deep copy (functions and DOM nodes are not supported)
|
|
79
|
+
- **`deepMerge`** — recursively merge a source into a target with circular-reference support
|
|
80
|
+
- **`isObject`** — check whether a value is a plain object
|
|
81
|
+
|
|
82
|
+
### string
|
|
83
|
+
- **`generateText`** — generate a string from a dictionary using configurable rules
|
|
84
|
+
- **`generateTokenizedText`** — like `generateText` but also returns token indices
|
|
85
|
+
- **`interpolate`** — replace `%key%`-style tokens in a string
|
|
86
|
+
- **`interpolateLiteral`** — replace `${key}`-style tokens in a literal-like string
|
|
87
|
+
- **`isString`** — check whether a value is a string
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=(e,t=!1)=>{if(e&&(e=e.startsWith(`.`)?e:`.${e}`,document.styleSheets?.length))for(let n of document.styleSheets)for(let
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=(e,t=!1)=>{if(e&&(e=e.startsWith(`.`)?e:`.${e}`,document.styleSheets?.length))for(let n of document.styleSheets){let r;try{r=n.cssRules}catch{continue}for(let n of r){let r=n;if(r.selectorText===e&&r.style)return t?r.style.cssText:r.style}}return null};exports.getCSSDeclaration=e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCSSDeclaration.d.ts","sourceRoot":"","sources":["../../src/dom/getCSSDeclaration.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,iBAAiB,GAAI,WAAW,MAAM,EAAE,oBAAkB,KAAG,mBAAmB,GAAG,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"getCSSDeclaration.d.ts","sourceRoot":"","sources":["../../src/dom/getCSSDeclaration.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,iBAAiB,GAAI,WAAW,MAAM,EAAE,oBAAkB,KAAG,mBAAmB,GAAG,MAAM,GAAG,IAsBxG,CAAA"}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
//#region src/dom/getCSSDeclaration.ts
|
|
2
2
|
var e = (e, t = !1) => {
|
|
3
|
-
if (e && (e = e.startsWith(".") ? e : `.${e}`, document.styleSheets?.length)) for (let n of document.styleSheets)
|
|
4
|
-
let
|
|
5
|
-
|
|
3
|
+
if (e && (e = e.startsWith(".") ? e : `.${e}`, document.styleSheets?.length)) for (let n of document.styleSheets) {
|
|
4
|
+
let r;
|
|
5
|
+
try {
|
|
6
|
+
r = n.cssRules;
|
|
7
|
+
} catch {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
for (let n of r) {
|
|
11
|
+
let r = n;
|
|
12
|
+
if (r.selectorText === e && r.style) return t ? r.style.cssText : r.style;
|
|
13
|
+
}
|
|
6
14
|
}
|
|
7
15
|
return null;
|
|
8
16
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../lang/isNil.cjs`);var t=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),n=e=>Object.keys(e).map(t).join(`|`),r=(r,i={},a=`%`)=>{let o=t(a),s=n(i),c=s?RegExp(`${o}(${s})${o}`,`g`):/(?!)/g;return r.replace(c,(t,n)=>e.isNil(i[n])?
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../lang/isNil.cjs`);var t=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),n=e=>Object.keys(e).map(t).join(`|`),r=(r,i={},a=`%`)=>{let o=t(a),s=n(i),c=s?RegExp(`${o}(${s})${o}`,`g`):/(?!)/g;return r.replace(c,(t,n)=>e.isNil(i[n])?t:String(i[n]))};exports.interpolate=r;
|
|
@@ -2,7 +2,7 @@ import { isNil as e } from "../lang/isNil.js";
|
|
|
2
2
|
//#region src/string/interpolate.ts
|
|
3
3
|
var t = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), n = (e) => Object.keys(e).map(t).join("|"), r = (r, i = {}, a = "%") => {
|
|
4
4
|
let o = t(a), s = n(i), c = s ? RegExp(`${o}(${s})${o}`, "g") : /(?!)/g;
|
|
5
|
-
return r.replace(c, (t, n) => e(i[n]) ?
|
|
5
|
+
return r.replace(c, (t, n) => e(i[n]) ? t : String(i[n]));
|
|
6
6
|
};
|
|
7
7
|
//#endregion
|
|
8
8
|
export { r as interpolate };
|