@untemps/utils 3.0.0 → 3.1.1

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 (90) hide show
  1. package/README.md +23 -0
  2. package/dist/array/extractByIndices.cjs +1 -1
  3. package/dist/array/extractByIndices.d.ts +18 -0
  4. package/dist/array/extractByIndices.d.ts.map +1 -0
  5. package/dist/array/extractByIndices.js +4 -4
  6. package/dist/async/standby.cjs +1 -1
  7. package/dist/async/standby.d.ts +20 -0
  8. package/dist/async/standby.d.ts.map +1 -0
  9. package/dist/async/standby.js +4 -4
  10. package/dist/dom/createElement.cjs +1 -1
  11. package/dist/dom/createElement.d.ts +52 -0
  12. package/dist/dom/createElement.d.ts.map +1 -0
  13. package/dist/dom/createElement.js +9 -18
  14. package/dist/dom/doElementsOverlap.cjs +1 -1
  15. package/dist/dom/doElementsOverlap.d.ts +29 -0
  16. package/dist/dom/doElementsOverlap.d.ts.map +1 -0
  17. package/dist/dom/doElementsOverlap.js +6 -6
  18. package/dist/dom/getCSSDeclaration.cjs +1 -1
  19. package/dist/dom/getCSSDeclaration.d.ts +22 -0
  20. package/dist/dom/getCSSDeclaration.d.ts.map +1 -0
  21. package/dist/dom/getCSSDeclaration.js +9 -12
  22. package/dist/dom/getElement.cjs +1 -1
  23. package/dist/dom/getElement.d.ts +19 -0
  24. package/dist/dom/getElement.d.ts.map +1 -0
  25. package/dist/dom/getElement.js +4 -4
  26. package/dist/dom/isElement.cjs +1 -1
  27. package/dist/dom/isElement.d.ts +16 -0
  28. package/dist/dom/isElement.d.ts.map +1 -0
  29. package/dist/dom/isElement.js +4 -4
  30. package/dist/dom/modifyElement.cjs +1 -1
  31. package/dist/dom/modifyElement.d.ts +20 -0
  32. package/dist/dom/modifyElement.d.ts.map +1 -0
  33. package/dist/dom/modifyElement.js +8 -10
  34. package/dist/dom/removeElement.cjs +1 -1
  35. package/dist/dom/removeElement.d.ts +19 -0
  36. package/dist/dom/removeElement.d.ts.map +1 -0
  37. package/dist/dom/removeElement.js +7 -8
  38. package/dist/dom/resolveClassName.cjs +1 -1
  39. package/dist/dom/resolveClassName.d.ts +22 -0
  40. package/dist/dom/resolveClassName.d.ts.map +1 -0
  41. package/dist/dom/resolveClassName.js +11 -10
  42. package/dist/function/isFunction.cjs +1 -1
  43. package/dist/function/isFunction.d.ts +16 -0
  44. package/dist/function/isFunction.d.ts.map +1 -0
  45. package/dist/function/isFunction.js +4 -4
  46. package/dist/index.cjs +1 -0
  47. package/dist/index.d.ts +26 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +22 -0
  50. package/dist/lang/isNil.cjs +1 -1
  51. package/dist/lang/isNil.d.ts +16 -0
  52. package/dist/lang/isNil.d.ts.map +1 -0
  53. package/dist/lang/isNil.js +4 -4
  54. package/dist/number/getRandomInteger.cjs +1 -1
  55. package/dist/number/getRandomInteger.d.ts +18 -0
  56. package/dist/number/getRandomInteger.d.ts.map +1 -0
  57. package/dist/number/getRandomInteger.js +7 -7
  58. package/dist/number/normalizeMinMax.cjs +1 -1
  59. package/dist/number/normalizeMinMax.d.ts +21 -0
  60. package/dist/number/normalizeMinMax.d.ts.map +1 -0
  61. package/dist/number/normalizeMinMax.js +6 -6
  62. package/dist/object/deepMerge.cjs +1 -1
  63. package/dist/object/deepMerge.d.ts +18 -0
  64. package/dist/object/deepMerge.d.ts.map +1 -0
  65. package/dist/object/deepMerge.js +7 -8
  66. package/dist/object/isObject.cjs +1 -1
  67. package/dist/object/isObject.d.ts +16 -0
  68. package/dist/object/isObject.d.ts.map +1 -0
  69. package/dist/object/isObject.js +4 -4
  70. package/dist/string/generateText.cjs +1 -1
  71. package/dist/string/generateText.d.ts +29 -0
  72. package/dist/string/generateText.d.ts.map +1 -0
  73. package/dist/string/generateText.js +18 -70
  74. package/dist/string/generateTokenizedText.cjs +1 -1
  75. package/dist/string/generateTokenizedText.d.ts +38 -0
  76. package/dist/string/generateTokenizedText.d.ts.map +1 -0
  77. package/dist/string/generateTokenizedText.js +18 -26
  78. package/dist/string/interpolate.cjs +1 -1
  79. package/dist/string/interpolate.d.ts +24 -0
  80. package/dist/string/interpolate.d.ts.map +1 -0
  81. package/dist/string/interpolate.js +10 -13
  82. package/dist/string/interpolateLiteral.cjs +1 -1
  83. package/dist/string/interpolateLiteral.d.ts +22 -0
  84. package/dist/string/interpolateLiteral.d.ts.map +1 -0
  85. package/dist/string/interpolateLiteral.js +4 -4
  86. package/dist/string/isString.cjs +1 -1
  87. package/dist/string/isString.d.ts +16 -0
  88. package/dist/string/isString.d.ts.map +1 -0
  89. package/dist/string/isString.js +4 -4
  90. package/package.json +32 -35
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ import { extractByIndices as e } from "./array/extractByIndices.js";
2
+ import { standby as t } from "./async/standby.js";
3
+ import { createElement as n } from "./dom/createElement.js";
4
+ import { doElementsOverlap as r } from "./dom/doElementsOverlap.js";
5
+ import { getCSSDeclaration as i } from "./dom/getCSSDeclaration.js";
6
+ import { getElement as a } from "./dom/getElement.js";
7
+ import { isElement as o } from "./dom/isElement.js";
8
+ import { isString as s } from "./string/isString.js";
9
+ import { modifyElement as c } from "./dom/modifyElement.js";
10
+ import { removeElement as l } from "./dom/removeElement.js";
11
+ import { resolveClassName as u } from "./dom/resolveClassName.js";
12
+ import { isFunction as d } from "./function/isFunction.js";
13
+ import { isNil as f } from "./lang/isNil.js";
14
+ import { normalizeMinMax as p } from "./number/normalizeMinMax.js";
15
+ import { getRandomInteger as m } from "./number/getRandomInteger.js";
16
+ import { isObject as h } from "./object/isObject.js";
17
+ import { deepMerge as g } from "./object/deepMerge.js";
18
+ import { generateText as _ } from "./string/generateText.js";
19
+ import { generateTokenizedText as v } from "./string/generateTokenizedText.js";
20
+ import { interpolate as y } from "./string/interpolate.js";
21
+ import { interpolateLiteral as b } from "./string/interpolateLiteral.js";
22
+ export { n as createElement, g as deepMerge, r as doElementsOverlap, e as extractByIndices, _ as generateText, v as generateTokenizedText, i as getCSSDeclaration, a as getElement, m as getRandomInteger, y as interpolate, b as interpolateLiteral, o as isElement, d as isFunction, f as isNil, h as isObject, s as isString, c as modifyElement, p as normalizeMinMax, l as removeElement, u as resolveClassName, t as standby };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=e=>e==null;exports.isNil=i;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=e=>e==null;exports.isNil=e;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @module lang/isNil
3
+ */
4
+ /**
5
+ * @function
6
+ * @example
7
+ * import { isNil } from '@untemps/utils/lang/isNil'
8
+ *
9
+ * isNil(undefined) // true
10
+ * isNil(42) // false
11
+ *
12
+ * @param value - The value to check.
13
+ * @returns `true` whether the value is undefined or null.
14
+ */
15
+ export declare const isNil: (value: unknown) => value is null | undefined;
16
+ //# sourceMappingURL=isNil.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isNil.d.ts","sourceRoot":"","sources":["../../src/lang/isNil.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,IAAI,GAAG,SAAkD,CAAA"}
@@ -1,4 +1,4 @@
1
- const i = (n) => n == null;
2
- export {
3
- i as isNil
4
- };
1
+ //#region src/lang/isNil.ts
2
+ var e = (e) => e == null;
3
+ //#endregion
4
+ export { e as isNil };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("./normalizeMinMax.cjs"),o=(n=-Number.MAX_SAFE_INTEGER,r=Number.MAX_SAFE_INTEGER)=>{const{min:e,max:t}=m.normalizeMinMax(n,r);return Math.round(e+Math.random()*(t-e))};exports.getRandomInteger=o;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./normalizeMinMax.cjs`);var t=(t=-(2**53-1),n=2**53-1)=>{let{min:r,max:i}=e.normalizeMinMax(t,n);return Math.floor(r+Math.random()*(i-r+1))};exports.getRandomInteger=t;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @module number/getRandomInteger
3
+ */
4
+ /**
5
+ * @function
6
+ * @example
7
+ * import { getRandomInteger } from '@untemps/utils/number/getRandomInteger'
8
+ *
9
+ * const min = 0
10
+ * const max = 100
11
+ * getRandomInteger(min, max) // 42
12
+ *
13
+ * @param min - The minimum value to pick.
14
+ * @param max - The maximum value to pick.
15
+ * @returns A random integer between min and max.
16
+ */
17
+ export declare const getRandomInteger: (min?: number, max?: number) => number;
18
+ //# sourceMappingURL=getRandomInteger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRandomInteger.d.ts","sourceRoot":"","sources":["../../src/number/getRandomInteger.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB,GAAI,YAA8B,EAAE,YAA6B,KAAG,MAGhG,CAAA"}
@@ -1,8 +1,8 @@
1
- import { normalizeMinMax as t } from "./normalizeMinMax.js";
2
- const a = (n = -Number.MAX_SAFE_INTEGER, r = Number.MAX_SAFE_INTEGER) => {
3
- const { min: m, max: o } = t(n, r);
4
- return Math.round(m + Math.random() * (o - m));
5
- };
6
- export {
7
- a as getRandomInteger
1
+ import { normalizeMinMax as e } from "./normalizeMinMax.js";
2
+ //#region src/number/getRandomInteger.ts
3
+ var t = (t = -(2 ** 53 - 1), n = 2 ** 53 - 1) => {
4
+ let { min: r, max: i } = e(t, n);
5
+ return Math.floor(r + Math.random() * (i - r + 1));
8
6
  };
7
+ //#endregion
8
+ export { t as getRandomInteger };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=(e,t)=>({min:Math.min(e,t),max:Math.max(e,t)});exports.normalizeMinMax=a;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=(e,t)=>({min:Math.min(e,t),max:Math.max(e,t)});exports.normalizeMinMax=e;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @module number/normalizeMinMax
3
+ */
4
+ /**
5
+ * @function
6
+ * @example
7
+ * import { normalizeMinMax } from '@untemps/utils/number/normalizeMinMax'
8
+ *
9
+ * const min = 100
10
+ * const max = 0
11
+ * normalizeMinMax(min, max) // { min: 0, max: 100 }
12
+ *
13
+ * @param min - The minimum value to evaluate.
14
+ * @param max - The maximum value to evaluate.
15
+ * @returns An object where min and max properties are guaranteed.
16
+ */
17
+ export declare const normalizeMinMax: (min: number, max: number) => {
18
+ min: number;
19
+ max: number;
20
+ };
21
+ //# sourceMappingURL=normalizeMinMax.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizeMinMax.d.ts","sourceRoot":"","sources":["../../src/number/normalizeMinMax.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,MAAM,EAAE,KAAK,MAAM,KAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAGnF,CAAA"}
@@ -1,7 +1,7 @@
1
- const t = (a, n) => ({
2
- min: Math.min(a, n),
3
- max: Math.max(a, n)
1
+ //#region src/number/normalizeMinMax.ts
2
+ var e = (e, t) => ({
3
+ min: Math.min(e, t),
4
+ max: Math.max(e, t)
4
5
  });
5
- export {
6
- t as normalizeMinMax
7
- };
6
+ //#endregion
7
+ export { e as normalizeMinMax };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("./isObject.cjs"),n=(e,t)=>{for(const i of Object.keys(e))b.isObject(e[i])&&i in t&&Object.assign(e[i],n(e[i],t[i]));return Object.assign(t||{},e),t};exports.deepMerge=n;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./isObject.cjs`);var t=(n,r)=>{for(let i of Object.keys(n))e.isObject(n[i])&&i in r&&Object.assign(n[i],t(n[i],r[i]));return Object.assign(r||{},n),r};exports.deepMerge=t;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @module object/deepMerge
3
+ */
4
+ /**
5
+ * @function
6
+ * @example
7
+ * import { deepMerge } from '@untemps/utils/object/deepMerge'
8
+ *
9
+ * const source = { foo: 1, bar: { gag: [1, 2, 3], pol: { mur: 'mur' } } }
10
+ * const target = { foo: 2, zaz: { juv: 1 }, bar: { gag: 'gag' } }
11
+ * deepMerge(source, target) // { foo: 1, zaz: { juv: 1 }, bar: { gag: [1, 2, 3], pol: { mur: 'mur' } } }
12
+ *
13
+ * @param source - The object to merge into the target.
14
+ * @param target - The target object where source will be merged.
15
+ * @returns The target object containing both source and target keys with source precedence.
16
+ */
17
+ export declare const deepMerge: (source: Record<string, unknown>, target: Record<string, unknown>) => Record<string, unknown>;
18
+ //# sourceMappingURL=deepMerge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deepMerge.d.ts","sourceRoot":"","sources":["../../src/object/deepMerge.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,SAAS,GACrB,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,MAAM,CAAC,MAAM,EAAE,OAAO,CAWxB,CAAA"}
@@ -1,9 +1,8 @@
1
- import { isObject as b } from "./isObject.js";
2
- const f = (i, e) => {
3
- for (const n of Object.keys(i))
4
- b(i[n]) && n in e && Object.assign(i[n], f(i[n], e[n]));
5
- return Object.assign(e || {}, i), e;
6
- };
7
- export {
8
- f as deepMerge
1
+ import { isObject as e } from "./isObject.js";
2
+ //#region src/object/deepMerge.ts
3
+ var t = (n, r) => {
4
+ for (let i of Object.keys(n)) e(n[i]) && i in r && Object.assign(n[i], t(n[i], r[i]));
5
+ return Object.assign(r || {}, n), r;
9
6
  };
7
+ //#endregion
8
+ export { t as deepMerge };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=t=>Object.getPrototypeOf(t)===Object.prototype;exports.isObject=e;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=e=>Object.getPrototypeOf(e)===Object.prototype;exports.isObject=e;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @module object/isObject
3
+ */
4
+ /**
5
+ * @function
6
+ * @example
7
+ * import { isObject } from '@untemps/utils/object/isObject'
8
+ *
9
+ * isObject({}) // true
10
+ * isObject(42) // false
11
+ *
12
+ * @param value - The value to check.
13
+ * @returns `true` whether the value is an object.
14
+ */
15
+ export declare const isObject: (value: unknown) => value is Record<string, unknown>;
16
+ //# sourceMappingURL=isObject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isObject.d.ts","sourceRoot":"","sources":["../../src/object/isObject.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CACvB,CAAA"}
@@ -1,4 +1,4 @@
1
- const e = (t) => Object.getPrototypeOf(t) === Object.prototype;
2
- export {
3
- e as isObject
4
- };
1
+ //#region src/object/isObject.ts
2
+ var e = (e) => Object.getPrototypeOf(e) === Object.prototype;
3
+ //#endregion
4
+ export { e as isObject };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("../number/getRandomInteger.cjs"),c=require("../number/normalizeMinMax.cjs"),g=["year","learn","key","cook","crosswalk","script","chief","plan","meat","vague","demonstrator","dictionary","visible","bomber","variation","leader","channel","litigation","royalty","impulse","package","oppose","privilege","begin","operation","herd","hemisphere","incongruous","horror","pipe","start","vertical","worry","reform","unlike","exhibition","disagree","allow","patrol","combine","impress","invisible","cage","log","snow","undertake","division","ethics","damage","responsible"],M=(r,a)=>{const{min:e,max:n}=c.normalizeMinMax(Math.abs(r),Math.abs(a)),t=Math.max(e,1),o=Math.max(n,t);return{min:t,max:o}},h=({minWords:r=10,maxWords:a=50,dictionary:e=g}={})=>{let n="";const{min:t,max:o}=M(r,a),s=m.getRandomInteger(t,o);for(let i=0;i<s;i++){const l=e[Math.floor(Math.random()*e.length)];n+=`${i>0?" ":""}${l}`}return n};exports.generateText=h;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../number/normalizeMinMax.cjs`),t=require(`../number/getRandomInteger.cjs`);var n=`year.learn.key.cook.crosswalk.script.chief.plan.meat.vague.demonstrator.dictionary.visible.bomber.variation.leader.channel.litigation.royalty.impulse.package.oppose.privilege.begin.operation.herd.hemisphere.incongruous.horror.pipe.start.vertical.worry.reform.unlike.exhibition.disagree.allow.patrol.combine.impress.invisible.cage.log.snow.undertake.division.ethics.damage.responsible`.split(`.`),r=(t,n)=>{let{min:r,max:i}=e.normalizeMinMax(Math.abs(t),Math.abs(n)),a=Math.max(r,1);return{min:a,max:Math.max(i,a)}},i=({minWords:e=10,maxWords:i=50,dictionary:a=n}={})=>{let o=``,{min:s,max:c}=r(e,i),l=t.getRandomInteger(s,c);for(let e=0;e<l;e++){let t=a[Math.floor(Math.random()*a.length)];o+=`${e>0?` `:``}${t}`}return o};exports.generateText=i;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @module string/generateText
3
+ */
4
+ /**
5
+ * Configuration object for generateText.
6
+ */
7
+ export interface GenerateTextConfig {
8
+ /** The minimum number of words to pick. */
9
+ minWords?: number;
10
+ /** The maximum number of words to pick. */
11
+ maxWords?: number;
12
+ /** A list of words from which picking the words. */
13
+ dictionary?: string[];
14
+ }
15
+ /**
16
+ * @function
17
+ * @example
18
+ * import { generateText } from '@untemps/utils/string/generateText'
19
+ *
20
+ * const minWords = 5;
21
+ * const maxWords = 10;
22
+ * const dictionary = ['foo', 'bar', 'gag'];
23
+ * generateText({minWords, maxWords, dictionary}) // bar foo foo gag gag bar gag gag
24
+ *
25
+ * @param config - The configuration object for the text generation.
26
+ * @returns The generated string.
27
+ */
28
+ export declare const generateText: ({ minWords, maxWords, dictionary }?: GenerateTextConfig) => string;
29
+ //# sourceMappingURL=generateText.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateText.d.ts","sourceRoot":"","sources":["../../src/string/generateText.ts"],"names":[],"mappings":"AAAA;;GAEG;AAmEH;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAClC,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CACrB;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,GAAI,qCAAsD,kBAAuB,KAAG,MAS5G,CAAA"}
@@ -1,71 +1,19 @@
1
- import { getRandomInteger as m } from "../number/getRandomInteger.js";
2
- import { normalizeMinMax as c } from "../number/normalizeMinMax.js";
3
- const p = [
4
- "year",
5
- "learn",
6
- "key",
7
- "cook",
8
- "crosswalk",
9
- "script",
10
- "chief",
11
- "plan",
12
- "meat",
13
- "vague",
14
- "demonstrator",
15
- "dictionary",
16
- "visible",
17
- "bomber",
18
- "variation",
19
- "leader",
20
- "channel",
21
- "litigation",
22
- "royalty",
23
- "impulse",
24
- "package",
25
- "oppose",
26
- "privilege",
27
- "begin",
28
- "operation",
29
- "herd",
30
- "hemisphere",
31
- "incongruous",
32
- "horror",
33
- "pipe",
34
- "start",
35
- "vertical",
36
- "worry",
37
- "reform",
38
- "unlike",
39
- "exhibition",
40
- "disagree",
41
- "allow",
42
- "patrol",
43
- "combine",
44
- "impress",
45
- "invisible",
46
- "cage",
47
- "log",
48
- "snow",
49
- "undertake",
50
- "division",
51
- "ethics",
52
- "damage",
53
- "responsible"
54
- ], g = (a, n) => {
55
- const { min: e, max: o } = c(Math.abs(a), Math.abs(n)), t = Math.max(e, 1), r = Math.max(o, t);
56
- return {
57
- min: t,
58
- max: r
59
- };
60
- }, x = ({ minWords: a = 10, maxWords: n = 50, dictionary: e = p } = {}) => {
61
- let o = "";
62
- const { min: t, max: r } = g(a, n), s = m(t, r);
63
- for (let i = 0; i < s; i++) {
64
- const l = e[Math.floor(Math.random() * e.length)];
65
- o += `${i > 0 ? " " : ""}${l}`;
66
- }
67
- return o;
68
- };
69
- export {
70
- x as generateText
1
+ import { normalizeMinMax as e } from "../number/normalizeMinMax.js";
2
+ import { getRandomInteger as t } from "../number/getRandomInteger.js";
3
+ //#region src/string/generateText.ts
4
+ var n = /* @__PURE__ */ "year.learn.key.cook.crosswalk.script.chief.plan.meat.vague.demonstrator.dictionary.visible.bomber.variation.leader.channel.litigation.royalty.impulse.package.oppose.privilege.begin.operation.herd.hemisphere.incongruous.horror.pipe.start.vertical.worry.reform.unlike.exhibition.disagree.allow.patrol.combine.impress.invisible.cage.log.snow.undertake.division.ethics.damage.responsible".split("."), r = (t, n) => {
5
+ let { min: r, max: i } = e(Math.abs(t), Math.abs(n)), a = Math.max(r, 1);
6
+ return {
7
+ min: a,
8
+ max: Math.max(i, a)
9
+ };
10
+ }, i = ({ minWords: e = 10, maxWords: i = 50, dictionary: a = n } = {}) => {
11
+ let o = "", { min: s, max: c } = r(e, i), l = t(s, c);
12
+ for (let e = 0; e < l; e++) {
13
+ let t = a[Math.floor(Math.random() * a.length)];
14
+ o += `${e > 0 ? " " : ""}${t}`;
15
+ }
16
+ return o;
71
17
  };
18
+ //#endregion
19
+ export { i as generateText };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./generateText.cjs");require("../number/getRandomInteger.cjs");require("../number/normalizeMinMax.cjs");const x=({tokens:e=[],divider:r="%",minWords:i=10,maxWords:l=50,dictionary:g=void 0}={})=>{const n=s.generateText({minWords:Math.max(i,e.length),maxWords:Math.max(l,e.length),dictionary:g}).split(" "),o=Math.max(Math.floor((n.length-e.length)/e.length),1),a=[];for(let t=0;t<e.length;t++){const h=Math.floor(Math.random()*o)+o*t;n[h]=`${r}${e[t]}${r}`,a.push(h)}return{indices:a,text:n.join(" ")}};exports.generateTokenizedText=x;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./generateText.cjs`);var t=({tokens:t=[],divider:n=`%`,minWords:r=10,maxWords:i=50,dictionary:a=void 0}={})=>{let o=e.generateText({minWords:Math.max(r,t.length),maxWords:Math.max(i,t.length),dictionary:a}).split(` `),s=Math.max(Math.floor((o.length-t.length)/t.length),1),c=[];for(let e=0;e<t.length;e++){let r=Math.floor(Math.random()*s)+s*e;o[r]=`${n}${t[e]}${n}`,c.push(r)}return{indices:c,text:o.join(` `)}};exports.generateTokenizedText=t;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @module string/generateTokenizedText
3
+ */
4
+ /**
5
+ * Configuration object for generateTokenizedText.
6
+ */
7
+ export interface GenerateTokenizedTextConfig {
8
+ /** The list of tokens. */
9
+ tokens?: string[];
10
+ /** The symbol that identifies a token. */
11
+ divider?: string;
12
+ /** The minimum number of words to pick. */
13
+ minWords?: number;
14
+ /** The maximum number of words to pick. */
15
+ maxWords?: number;
16
+ /** A list of words from which picking the words. */
17
+ dictionary?: string[];
18
+ }
19
+ /**
20
+ * @function
21
+ * @example
22
+ * import { generateTokenizedText } from '@untemps/utils/string/generateTokenizedText'
23
+ *
24
+ * const tokens = ['pol', 'biz', 'kuy']
25
+ * const divider = '$'
26
+ * const minWords = 5
27
+ * const maxWords = 10
28
+ * const dictionary = ['foo', 'bar', 'gag']
29
+ * generateTokenizedText(tokens, divider, minWords, maxWords, dictionary) // {indices: Array(3), text: "foo $pol$ $biz$ bar gag $kuy$ foo gag foo"}}
30
+ *
31
+ * @param config - The configuration object for the text generation.
32
+ * @returns An object containing a list of token indices and the generated string.
33
+ */
34
+ export declare const generateTokenizedText: ({ tokens, divider, minWords, maxWords, dictionary, }?: GenerateTokenizedTextConfig) => {
35
+ indices: number[];
36
+ text: string;
37
+ };
38
+ //# sourceMappingURL=generateTokenizedText.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateTokenizedText.d.ts","sourceRoot":"","sources":["../../src/string/generateTokenizedText.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC3C,0BAA0B;IAC1B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CACrB;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,qBAAqB,GAAI,uDAMnC,2BAAgC,KAAG;IAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAkBtE,CAAA"}
@@ -1,27 +1,19 @@
1
- import { generateText as m } from "./generateText.js";
2
- import "../number/getRandomInteger.js";
3
- import "../number/normalizeMinMax.js";
4
- const p = ({
5
- tokens: t = [],
6
- divider: o = "%",
7
- minWords: l = 10,
8
- maxWords: x = 50,
9
- dictionary: i = void 0
10
- } = {}) => {
11
- const n = m({
12
- minWords: Math.max(l, t.length),
13
- maxWords: Math.max(x, t.length),
14
- dictionary: i
15
- }).split(" "), r = Math.max(Math.floor((n.length - t.length) / t.length), 1), h = [];
16
- for (let e = 0; e < t.length; e++) {
17
- const a = Math.floor(Math.random() * r) + r * e;
18
- n[a] = `${o}${t[e]}${o}`, h.push(a);
19
- }
20
- return {
21
- indices: h,
22
- text: n.join(" ")
23
- };
24
- };
25
- export {
26
- p as generateTokenizedText
1
+ import { generateText as e } from "./generateText.js";
2
+ //#region src/string/generateTokenizedText.ts
3
+ var t = ({ tokens: t = [], divider: n = "%", minWords: r = 10, maxWords: i = 50, dictionary: a = void 0 } = {}) => {
4
+ let o = e({
5
+ minWords: Math.max(r, t.length),
6
+ maxWords: Math.max(i, t.length),
7
+ dictionary: a
8
+ }).split(" "), s = Math.max(Math.floor((o.length - t.length) / t.length), 1), c = [];
9
+ for (let e = 0; e < t.length; e++) {
10
+ let r = Math.floor(Math.random() * s) + s * e;
11
+ o[r] = `${n}${t[e]}${n}`, c.push(r);
12
+ }
13
+ return {
14
+ indices: c,
15
+ text: o.join(" ")
16
+ };
27
17
  };
18
+ //#endregion
19
+ export { t as generateTokenizedText };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../lang/isNil.cjs"),p=n=>{const e=new RegExp("([\\[\\^\\$\\.|\\?\\*\\+\\(\\)])+","g");return n.replace(e,r=>r.split("").map(t=>"\\"+t).join(""))},l=n=>Object.keys(n).reduce((r,t,s)=>`${r}${s>0?"|":""}${t}`,""),a=(n,e={},r="%")=>{const t=p(r),s=l(e),o=new RegExp(`${t}(${s})${t}`,"g");return n.replace(o,(g,i)=>c.isNil(e[i])?i:e[i])};exports.interpolate=a;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../lang/isNil.cjs`);var t=e=>{let t=RegExp(`([\\[\\^\\$\\.|\\?\\*\\+\\(\\)])+`,`g`);return e.replace(t,e=>e.split(``).map(e=>`\\`+e).join(``))},n=e=>Object.keys(e).reduce((e,t,n)=>`${e}${n>0?`|`:``}${t}`,``),r=(r,i={},a=`%`)=>{let o=t(a),s=n(i),c=RegExp(`${o}(${s})${o}`,`g`);return r.replace(c,(t,n)=>e.isNil(i[n])?n:String(i[n]))};exports.interpolate=r;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @module string/interpolate
3
+ */
4
+ /**
5
+ * @function
6
+ * @example
7
+ * import { interpolate } from '@untemps/utils/string/interpolate'
8
+ *
9
+ * const value = 'A %foo% with a "%bar%" wings and a lot of %fun%'
10
+ * const tokens = {
11
+ * foo: 'bird',
12
+ * bar: 3,
13
+ * fun: 'dignity'
14
+ * }
15
+ * const divider = '%'
16
+ * interpolate(value, tokens, divider) // A bird with a "3" wings and a lot of dignity
17
+ *
18
+ * @param value - The string value to interpolate.
19
+ * @param tokens - An object of key/value pairs to replace the tokens.
20
+ * @param divider - The symbol that identifies a token.
21
+ * @returns The interpolated string.
22
+ */
23
+ export declare const interpolate: (value: string, tokens?: Record<string, unknown>, divider?: string) => string;
24
+ //# sourceMappingURL=interpolate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interpolate.d.ts","sourceRoot":"","sources":["../../src/string/interpolate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAqBH;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,EAAE,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EAAE,gBAAa,KAAG,MAKhG,CAAA"}
@@ -1,14 +1,11 @@
1
- import { isNil as c } from "../lang/isNil.js";
2
- const i = (t) => {
3
- const e = new RegExp("([\\[\\^\\$\\.|\\?\\*\\+\\(\\)])+", "g");
4
- return t.replace(
5
- e,
6
- (o) => o.split("").map((n) => "\\" + n).join("")
7
- );
8
- }, $ = (t) => Object.keys(t).reduce((o, n, p) => `${o}${p > 0 ? "|" : ""}${n}`, ""), d = (t, e = {}, o = "%") => {
9
- const n = i(o), p = $(e), s = new RegExp(`${n}(${p})${n}`, "g");
10
- return t.replace(s, (a, r) => c(e[r]) ? r : e[r]);
11
- };
12
- export {
13
- d as interpolate
1
+ import { isNil as e } from "../lang/isNil.js";
2
+ //#region src/string/interpolate.ts
3
+ var t = (e) => {
4
+ let t = /* @__PURE__ */ RegExp("([\\[\\^\\$\\.|\\?\\*\\+\\(\\)])+", "g");
5
+ return e.replace(t, (e) => e.split("").map((e) => "\\" + e).join(""));
6
+ }, n = (e) => Object.keys(e).reduce((e, t, n) => `${e}${n > 0 ? "|" : ""}${t}`, ""), r = (r, i = {}, a = "%") => {
7
+ let o = t(a), s = n(i), c = RegExp(`${o}(${s})${o}`, "g");
8
+ return r.replace(c, (t, n) => e(i[n]) ? n : String(i[n]));
14
9
  };
10
+ //#endregion
11
+ export { r as interpolate };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=(t,e)=>new Function(...Object.keys(e),`return \`${t}\``)(...Object.values(e));exports.interpolateLiteral=n;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=(e,t)=>Function(...Object.keys(t),`return \`${e}\``)(...Object.values(t));exports.interpolateLiteral=e;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @module string/interpolateLiteral
3
+ */
4
+ /**
5
+ * @function
6
+ * @example
7
+ * import { interpolateLiteral } from '@untemps/utils/string/interpolateLiteral'
8
+ *
9
+ * const value = 'A ${foo} with ${bar} "wings" and a lot of ${fun}'
10
+ * const tokens = {
11
+ * foo: 'bird',
12
+ * bar: 3,
13
+ * fun: 'dignity'
14
+ * }
15
+ * interpolateLiteral(value, tokens) // A bird with 3 "wings" and a lot of dignity
16
+ *
17
+ * @param value - The literal-like string value to interpolate.
18
+ * @param tokens - An object of key/value pairs to replace the tokens.
19
+ * @returns The interpolated string.
20
+ */
21
+ export declare const interpolateLiteral: (value: string, tokens: Record<string, unknown>) => string;
22
+ //# sourceMappingURL=interpolateLiteral.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interpolateLiteral.d.ts","sourceRoot":"","sources":["../../src/string/interpolateLiteral.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,EAAE,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,MAGnF,CAAA"}
@@ -1,4 +1,4 @@
1
- const r = (t, e) => new Function(...Object.keys(e), `return \`${t}\``)(...Object.values(e));
2
- export {
3
- r as interpolateLiteral
4
- };
1
+ //#region src/string/interpolateLiteral.ts
2
+ var e = (e, t) => Function(...Object.keys(t), `return \`${e}\``)(...Object.values(t));
3
+ //#endregion
4
+ export { e as interpolateLiteral };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=t=>typeof t=="string"||Object.prototype.toString.call(t)==="[object String]";exports.isString=e;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=e=>typeof e==`string`||Object.prototype.toString.call(e)===`[object String]`;exports.isString=e;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @module string/isString
3
+ */
4
+ /**
5
+ * @function
6
+ * @example
7
+ * import { isString } from '@untemps/utils/string/isString'
8
+ *
9
+ * isString('foo') // true
10
+ * isString(42) // false
11
+ *
12
+ * @param value - The value to check.
13
+ * @returns `true` whether the value is a string.
14
+ */
15
+ export declare const isString: (value: unknown) => value is string;
16
+ //# sourceMappingURL=isString.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isString.d.ts","sourceRoot":"","sources":["../../src/string/isString.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MACsC,CAAA"}
@@ -1,4 +1,4 @@
1
- const o = (t) => typeof t == "string" || Object.prototype.toString.call(t) === "[object String]";
2
- export {
3
- o as isString
4
- };
1
+ //#region src/string/isString.ts
2
+ var e = (e) => typeof e == "string" || Object.prototype.toString.call(e) === "[object String]";
3
+ //#endregion
4
+ export { e as isString };