yummies 7.10.0 → 7.12.0

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 (154) hide show
  1. package/async.cjs +162 -48
  2. package/async.cjs.map +1 -1
  3. package/async.d.ts +112 -13
  4. package/async.js +163 -54
  5. package/async.js.map +1 -1
  6. package/chunk-CVq3Gv4J.cjs +50 -0
  7. package/chunk-YKewjYmz.js +37 -0
  8. package/common.cjs +48 -8
  9. package/common.cjs.map +1 -1
  10. package/common.d.ts +35 -2
  11. package/common.js +49 -11
  12. package/common.js.map +1 -1
  13. package/complex.cjs +275 -104
  14. package/complex.cjs.map +1 -1
  15. package/complex.d.ts +133 -13
  16. package/complex.js +275 -109
  17. package/complex.js.map +1 -1
  18. package/cookie.cjs +17 -7
  19. package/cookie.cjs.map +1 -1
  20. package/cookie.d.ts +8 -0
  21. package/cookie.js +18 -9
  22. package/cookie.js.map +1 -1
  23. package/css.cjs +147 -39
  24. package/css.cjs.map +1 -1
  25. package/css.d.ts +98 -6
  26. package/css.js +143 -41
  27. package/css.js.map +1 -1
  28. package/data.cjs +90 -55
  29. package/data.cjs.map +1 -1
  30. package/data.d.ts +32 -0
  31. package/data.js +91 -61
  32. package/data.js.map +1 -1
  33. package/date-time.cjs +578 -412
  34. package/date-time.cjs.map +1 -1
  35. package/date-time.d.ts +88 -0
  36. package/date-time.js +575 -421
  37. package/date-time.js.map +1 -1
  38. package/device.cjs +48 -23
  39. package/device.cjs.map +1 -1
  40. package/device.d.ts +32 -0
  41. package/device.js +49 -31
  42. package/device.js.map +1 -1
  43. package/encodings.cjs +275 -266
  44. package/encodings.cjs.map +1 -1
  45. package/encodings.d.ts +8 -0
  46. package/encodings.js +276 -268
  47. package/encodings.js.map +1 -1
  48. package/errors.cjs +20 -18
  49. package/errors.cjs.map +1 -1
  50. package/errors.js +19 -19
  51. package/errors.js.map +1 -1
  52. package/file.cjs +42 -24
  53. package/file.cjs.map +1 -1
  54. package/file.d.ts +16 -0
  55. package/file.js +43 -27
  56. package/file.js.map +1 -1
  57. package/format.cjs +125 -83
  58. package/format.cjs.map +1 -1
  59. package/format.d.ts +89 -4
  60. package/format.js +118 -82
  61. package/format.js.map +1 -1
  62. package/html.cjs +226 -137
  63. package/html.cjs.map +1 -1
  64. package/html.d.ts +67 -3
  65. package/html.js +223 -150
  66. package/html.js.map +1 -1
  67. package/id.cjs +74 -17
  68. package/id.cjs.map +1 -1
  69. package/id.d.ts +10 -10
  70. package/id.js +73 -24
  71. package/id.js.map +1 -1
  72. package/imports.cjs +41 -29
  73. package/imports.cjs.map +1 -1
  74. package/imports.d.ts +13 -4
  75. package/imports.js +40 -31
  76. package/imports.js.map +1 -1
  77. package/math.cjs +32 -6
  78. package/math.cjs.map +1 -1
  79. package/math.d.ts +17 -1
  80. package/math.js +33 -10
  81. package/math.js.map +1 -1
  82. package/media.cjs +275 -84
  83. package/media.cjs.map +1 -1
  84. package/media.d.ts +188 -2
  85. package/media.js +274 -93
  86. package/media.js.map +1 -1
  87. package/mobx.cjs +353 -193
  88. package/mobx.cjs.map +1 -1
  89. package/mobx.d.ts +172 -6
  90. package/mobx.js +351 -200
  91. package/mobx.js.map +1 -1
  92. package/ms.cjs +21 -10
  93. package/ms.cjs.map +1 -1
  94. package/ms.d.ts +1 -1
  95. package/ms.js +22 -13
  96. package/ms.js.map +1 -1
  97. package/number.cjs +13 -7
  98. package/number.cjs.map +1 -1
  99. package/number.js +14 -9
  100. package/number.js.map +1 -1
  101. package/package.json +13 -5
  102. package/parser.cjs +117 -64
  103. package/parser.cjs.map +1 -1
  104. package/parser.d.ts +63 -0
  105. package/parser.js +111 -64
  106. package/parser.js.map +1 -1
  107. package/price.cjs +24 -18
  108. package/price.cjs.map +1 -1
  109. package/price.d.ts +8 -0
  110. package/price.js +25 -20
  111. package/price.js.map +1 -1
  112. package/random.cjs +79 -13
  113. package/random.cjs.map +1 -1
  114. package/random.d.ts +64 -0
  115. package/random.js +80 -22
  116. package/random.js.map +1 -1
  117. package/react.cjs +673 -214
  118. package/react.cjs.map +1 -1
  119. package/react.d.ts +428 -9
  120. package/react.js +674 -239
  121. package/react.js.map +1 -1
  122. package/sound.cjs +14 -9
  123. package/sound.cjs.map +1 -1
  124. package/sound.d.ts +1 -1
  125. package/sound.js +15 -11
  126. package/sound.js.map +1 -1
  127. package/storage.cjs +49 -50
  128. package/storage.cjs.map +1 -1
  129. package/storage.d.ts +15 -6
  130. package/storage.js +50 -53
  131. package/storage.js.map +1 -1
  132. package/text.cjs +51 -34
  133. package/text.cjs.map +1 -1
  134. package/text.d.ts +5 -5
  135. package/text.js +52 -37
  136. package/text.js.map +1 -1
  137. package/type-guard.cjs +292 -72
  138. package/type-guard.cjs.map +1 -1
  139. package/type-guard.d.ts +199 -42
  140. package/type-guard.js +288 -73
  141. package/type-guard.js.map +1 -1
  142. package/types.cjs +0 -2
  143. package/types.global.cjs +0 -2
  144. package/types.global.js +0 -2
  145. package/types.js +0 -2
  146. package/vibrate.cjs +31 -6
  147. package/vibrate.cjs.map +1 -1
  148. package/vibrate.d.ts +23 -1
  149. package/vibrate.js +32 -8
  150. package/vibrate.js.map +1 -1
  151. package/types.cjs.map +0 -1
  152. package/types.global.cjs.map +0 -1
  153. package/types.global.js.map +0 -1
  154. package/types.js.map +0 -1
package/ms.cjs CHANGED
@@ -1,14 +1,25 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const unitsToMs = {
4
- ms: 1,
5
- sec: 1e3,
6
- min: 1e3 * 60,
7
- hour: 1e3 * 60 * 60,
8
- day: 1e3 * 60 * 60 * 24,
9
- week: 1e3 * 60 * 60 * 24 * 7
2
+ //#region src/ms.ts
3
+ var unitsToMs = {
4
+ ms: 1,
5
+ sec: 1e3,
6
+ min: 1e3 * 60,
7
+ hour: 1e3 * 60 * 60,
8
+ day: 1e3 * 60 * 60 * 24,
9
+ week: 1e3 * 60 * 60 * 24 * 7
10
10
  };
11
- const ms = (value, unit = "ms") => value * unitsToMs[unit];
11
+ /**
12
+ * Converts a value in the specified unit to milliseconds.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * ms(1, 'min') // 60_000
17
+ * ms(30, 'sec') // 30_000
18
+ * ```
19
+ */
20
+ var ms = (value, unit = "ms") => value * unitsToMs[unit];
21
+ //#endregion
12
22
  exports.ms = ms;
13
23
  exports.unitsToMs = unitsToMs;
14
- //# sourceMappingURL=ms.cjs.map
24
+
25
+ //# sourceMappingURL=ms.cjs.map
package/ms.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ms.cjs","sources":["../src/ms.ts"],"sourcesContent":["export const unitsToMs = {\n ms: 1,\n sec: 1000,\n min: 1000 * 60,\n hour: 1000 * 60 * 60,\n day: 1000 * 60 * 60 * 24,\n week: 1000 * 60 * 60 * 24 * 7,\n} as const;\n\n/**\n * Переводит значение в юнитах в миллисекунды\n *\n * @example\n * ```ts\n * ms(1, 'min') // 60_000\n * ms(30, 'sec') // 30_000\n * ```\n */\nexport const ms = (value: number, unit: keyof typeof unitsToMs = 'ms') =>\n value * unitsToMs[unit];\n"],"names":[],"mappings":";;AAAO,MAAM,YAAY;AAAA,EACvB,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,KAAK,MAAO;AAAA,EACZ,MAAM,MAAO,KAAK;AAAA,EAClB,KAAK,MAAO,KAAK,KAAK;AAAA,EACtB,MAAM,MAAO,KAAK,KAAK,KAAK;AAC9B;AAWO,MAAM,KAAK,CAAC,OAAe,OAA+B,SAC/D,QAAQ,UAAU,IAAI;;;"}
1
+ {"version":3,"file":"ms.cjs","names":[],"sources":["../src/ms.ts"],"sourcesContent":["export const unitsToMs = {\n ms: 1,\n sec: 1000,\n min: 1000 * 60,\n hour: 1000 * 60 * 60,\n day: 1000 * 60 * 60 * 24,\n week: 1000 * 60 * 60 * 24 * 7,\n} as const;\n\n/**\n * Converts a value in the specified unit to milliseconds.\n *\n * @example\n * ```ts\n * ms(1, 'min') // 60_000\n * ms(30, 'sec') // 30_000\n * ```\n */\nexport const ms = (value: number, unit: keyof typeof unitsToMs = 'ms') =>\n value * unitsToMs[unit];\n"],"mappings":";;AAAA,IAAa,YAAY;CACvB,IAAI;CACJ,KAAK;CACL,KAAK,MAAO;CACZ,MAAM,MAAO,KAAK;CAClB,KAAK,MAAO,KAAK,KAAK;CACtB,MAAM,MAAO,KAAK,KAAK,KAAK;CAC7B;;;;;;;;;;AAWD,IAAa,MAAM,OAAe,OAA+B,SAC/D,QAAQ,UAAU"}
package/ms.d.ts CHANGED
@@ -7,7 +7,7 @@ declare const unitsToMs: {
7
7
  readonly week: number;
8
8
  };
9
9
  /**
10
- * Переводит значение в юнитах в миллисекунды
10
+ * Converts a value in the specified unit to milliseconds.
11
11
  *
12
12
  * @example
13
13
  * ```ts
package/ms.js CHANGED
@@ -1,14 +1,23 @@
1
- const unitsToMs = {
2
- ms: 1,
3
- sec: 1e3,
4
- min: 1e3 * 60,
5
- hour: 1e3 * 60 * 60,
6
- day: 1e3 * 60 * 60 * 24,
7
- week: 1e3 * 60 * 60 * 24 * 7
1
+ //#region src/ms.ts
2
+ var unitsToMs = {
3
+ ms: 1,
4
+ sec: 1e3,
5
+ min: 1e3 * 60,
6
+ hour: 1e3 * 60 * 60,
7
+ day: 1e3 * 60 * 60 * 24,
8
+ week: 1e3 * 60 * 60 * 24 * 7
8
9
  };
9
- const ms = (value, unit = "ms") => value * unitsToMs[unit];
10
- export {
11
- ms,
12
- unitsToMs
13
- };
14
- //# sourceMappingURL=ms.js.map
10
+ /**
11
+ * Converts a value in the specified unit to milliseconds.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * ms(1, 'min') // 60_000
16
+ * ms(30, 'sec') // 30_000
17
+ * ```
18
+ */
19
+ var ms = (value, unit = "ms") => value * unitsToMs[unit];
20
+ //#endregion
21
+ export { ms, unitsToMs };
22
+
23
+ //# sourceMappingURL=ms.js.map
package/ms.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ms.js","sources":["../src/ms.ts"],"sourcesContent":["export const unitsToMs = {\n ms: 1,\n sec: 1000,\n min: 1000 * 60,\n hour: 1000 * 60 * 60,\n day: 1000 * 60 * 60 * 24,\n week: 1000 * 60 * 60 * 24 * 7,\n} as const;\n\n/**\n * Переводит значение в юнитах в миллисекунды\n *\n * @example\n * ```ts\n * ms(1, 'min') // 60_000\n * ms(30, 'sec') // 30_000\n * ```\n */\nexport const ms = (value: number, unit: keyof typeof unitsToMs = 'ms') =>\n value * unitsToMs[unit];\n"],"names":[],"mappings":"AAAO,MAAM,YAAY;AAAA,EACvB,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,KAAK,MAAO;AAAA,EACZ,MAAM,MAAO,KAAK;AAAA,EAClB,KAAK,MAAO,KAAK,KAAK;AAAA,EACtB,MAAM,MAAO,KAAK,KAAK,KAAK;AAC9B;AAWO,MAAM,KAAK,CAAC,OAAe,OAA+B,SAC/D,QAAQ,UAAU,IAAI;"}
1
+ {"version":3,"file":"ms.js","names":[],"sources":["../src/ms.ts"],"sourcesContent":["export const unitsToMs = {\n ms: 1,\n sec: 1000,\n min: 1000 * 60,\n hour: 1000 * 60 * 60,\n day: 1000 * 60 * 60 * 24,\n week: 1000 * 60 * 60 * 24 * 7,\n} as const;\n\n/**\n * Converts a value in the specified unit to milliseconds.\n *\n * @example\n * ```ts\n * ms(1, 'min') // 60_000\n * ms(30, 'sec') // 30_000\n * ```\n */\nexport const ms = (value: number, unit: keyof typeof unitsToMs = 'ms') =>\n value * unitsToMs[unit];\n"],"mappings":";AAAA,IAAa,YAAY;CACvB,IAAI;CACJ,KAAK;CACL,KAAK,MAAO;CACZ,MAAM,MAAO,KAAK;CAClB,KAAK,MAAO,KAAK,KAAK;CACtB,MAAM,MAAO,KAAK,KAAK,KAAK;CAC7B;;;;;;;;;;AAWD,IAAa,MAAM,OAAe,OAA+B,SAC/D,QAAQ,UAAU"}
package/number.cjs CHANGED
@@ -1,11 +1,17 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/number.ts
3
+ /**
4
+ * Works like `parseFloat(number.toFixed(4))` but performance better
5
+ *
6
+ * @example
7
+ * round(191.212999999999999999999999, 4) // 191.213
8
+ */
3
9
  function round(value, decimalPlaces = 0) {
4
- if (!decimalPlaces) {
5
- return Math.round(value);
6
- }
7
- const factor = 10 ** decimalPlaces;
8
- return Math.round(value * factor) / factor;
10
+ if (!decimalPlaces) return Math.round(value);
11
+ const factor = 10 ** decimalPlaces;
12
+ return Math.round(value * factor) / factor;
9
13
  }
14
+ //#endregion
10
15
  exports.round = round;
11
- //# sourceMappingURL=number.cjs.map
16
+
17
+ //# sourceMappingURL=number.cjs.map
package/number.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"number.cjs","sources":["../src/number.ts"],"sourcesContent":["/**\n * Works like `parseFloat(number.toFixed(4))` but performance better\n *\n * @example\n * round(191.212999999999999999999999, 4) // 191.213\n */\nexport function round(value: number, decimalPlaces: number = 0): number {\n if (!decimalPlaces) {\n return Math.round(value);\n }\n\n const factor = 10 ** decimalPlaces;\n return Math.round(value * factor) / factor;\n}\n"],"names":[],"mappings":";;AAMO,SAAS,MAAM,OAAe,gBAAwB,GAAW;AACtE,MAAI,CAAC,eAAe;AAClB,WAAO,KAAK,MAAM,KAAK;AAAA,EACzB;AAEA,QAAM,SAAS,MAAM;AACrB,SAAO,KAAK,MAAM,QAAQ,MAAM,IAAI;AACtC;;"}
1
+ {"version":3,"file":"number.cjs","names":[],"sources":["../src/number.ts"],"sourcesContent":["/**\n * Works like `parseFloat(number.toFixed(4))` but performance better\n *\n * @example\n * round(191.212999999999999999999999, 4) // 191.213\n */\nexport function round(value: number, decimalPlaces: number = 0): number {\n if (!decimalPlaces) {\n return Math.round(value);\n }\n\n const factor = 10 ** decimalPlaces;\n return Math.round(value * factor) / factor;\n}\n"],"mappings":";;;;;;;;AAMA,SAAgB,MAAM,OAAe,gBAAwB,GAAW;AACtE,KAAI,CAAC,cACH,QAAO,KAAK,MAAM,MAAM;CAG1B,MAAM,SAAS,MAAM;AACrB,QAAO,KAAK,MAAM,QAAQ,OAAO,GAAG"}
package/number.js CHANGED
@@ -1,11 +1,16 @@
1
+ //#region src/number.ts
2
+ /**
3
+ * Works like `parseFloat(number.toFixed(4))` but performance better
4
+ *
5
+ * @example
6
+ * round(191.212999999999999999999999, 4) // 191.213
7
+ */
1
8
  function round(value, decimalPlaces = 0) {
2
- if (!decimalPlaces) {
3
- return Math.round(value);
4
- }
5
- const factor = 10 ** decimalPlaces;
6
- return Math.round(value * factor) / factor;
9
+ if (!decimalPlaces) return Math.round(value);
10
+ const factor = 10 ** decimalPlaces;
11
+ return Math.round(value * factor) / factor;
7
12
  }
8
- export {
9
- round
10
- };
11
- //# sourceMappingURL=number.js.map
13
+ //#endregion
14
+ export { round };
15
+
16
+ //# sourceMappingURL=number.js.map
package/number.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"number.js","sources":["../src/number.ts"],"sourcesContent":["/**\n * Works like `parseFloat(number.toFixed(4))` but performance better\n *\n * @example\n * round(191.212999999999999999999999, 4) // 191.213\n */\nexport function round(value: number, decimalPlaces: number = 0): number {\n if (!decimalPlaces) {\n return Math.round(value);\n }\n\n const factor = 10 ** decimalPlaces;\n return Math.round(value * factor) / factor;\n}\n"],"names":[],"mappings":"AAMO,SAAS,MAAM,OAAe,gBAAwB,GAAW;AACtE,MAAI,CAAC,eAAe;AAClB,WAAO,KAAK,MAAM,KAAK;AAAA,EACzB;AAEA,QAAM,SAAS,MAAM;AACrB,SAAO,KAAK,MAAM,QAAQ,MAAM,IAAI;AACtC;"}
1
+ {"version":3,"file":"number.js","names":[],"sources":["../src/number.ts"],"sourcesContent":["/**\n * Works like `parseFloat(number.toFixed(4))` but performance better\n *\n * @example\n * round(191.212999999999999999999999, 4) // 191.213\n */\nexport function round(value: number, decimalPlaces: number = 0): number {\n if (!decimalPlaces) {\n return Math.round(value);\n }\n\n const factor = 10 ** decimalPlaces;\n return Math.round(value * factor) / factor;\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,MAAM,OAAe,gBAAwB,GAAW;AACtE,KAAI,CAAC,cACH,QAAO,KAAK,MAAM,MAAM;CAG1B,MAAM,SAAS,MAAM;AACrB,QAAO,KAAK,MAAM,QAAQ,OAAO,GAAG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yummies",
3
- "version": "7.10.0",
3
+ "version": "7.12.0",
4
4
  "keywords": [
5
5
  "javascript",
6
6
  "typescript",
@@ -33,10 +33,10 @@
33
33
  "dependencies": {
34
34
  "class-variance-authority": "^0.7.1",
35
35
  "clsx": "^2.1.1",
36
- "dayjs": "^1.11.13",
37
- "dompurify": "^3.2.6",
38
- "nanoid": "^5.1.5",
39
- "tailwind-merge": "^3.3.1"
36
+ "dayjs": "^1.11.20",
37
+ "dompurify": "^3.3.3",
38
+ "nanoid": "^5.1.7",
39
+ "tailwind-merge": "^3.5.0"
40
40
  },
41
41
  "type": "module",
42
42
  "exports": {
@@ -46,6 +46,14 @@
46
46
  "require": "./async.cjs",
47
47
  "default": "./async.js"
48
48
  },
49
+ "./chunk-CVq3Gv4J": {
50
+ "require": "./chunk-CVq3Gv4J.cjs",
51
+ "default": "./chunk-CVq3Gv4J.cjs"
52
+ },
53
+ "./chunk-YKewjYmz": {
54
+ "import": "./chunk-YKewjYmz.js",
55
+ "default": "./chunk-YKewjYmz.js"
56
+ },
49
57
  "./common": {
50
58
  "types": "./common.d.ts",
51
59
  "import": "./common.js",
package/parser.cjs CHANGED
@@ -1,69 +1,122 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const format = require("yummies/format");
4
- const typeGuard = require("yummies/type-guard");
5
- const number = (input, userSettings) => {
6
- const settings = {
7
- ...number.defaultSettings,
8
- ...userSettings
9
- };
10
- const fallback = "fallback" in settings ? settings.fallback : 0;
11
- let result;
12
- if (typeGuard.typeGuard.isNumber(input)) {
13
- result = input;
14
- } else if (typeGuard.typeGuard.isString(input)) {
15
- const formattedInput = format.format.skipSpaces(input).replace(",", ".");
16
- if (formattedInput === "") {
17
- result = fallback;
18
- } else {
19
- result = Number(formattedInput);
20
- }
21
- } else {
22
- result = fallback;
23
- }
24
- if (typeGuard.typeGuard.isNumber(result)) {
25
- if (settings?.clamped != null) {
26
- result = Math.max(
27
- settings.clamped[0] ?? -Infinity,
28
- Math.min(result, settings.clamped[1] ?? Infinity)
29
- );
30
- }
31
- if (settings?.ceil != null) {
32
- result = Math.ceil(result);
33
- }
34
- if (settings?.floor != null) {
35
- result = Math.floor(result);
36
- }
37
- if (settings?.digits != null) {
38
- result = +result.toFixed(settings.digits);
39
- }
40
- return result;
41
- } else {
42
- return fallback;
43
- }
2
+ const require_chunk = require("./chunk-CVq3Gv4J.cjs");
3
+ let yummies_type_guard = require("yummies/type-guard");
4
+ let yummies_format = require("yummies/format");
5
+ //#region src/parser/number.ts
6
+ /**
7
+ * Parses a number from raw input and optionally clamps, rounds or limits
8
+ * fractional digits.
9
+ *
10
+ * Strings are normalized by removing spaces and replacing `,` with `.` before
11
+ * parsing. Invalid inputs return the configured fallback.
12
+ *
13
+ * @template TFallback Fallback value type returned when parsing fails.
14
+ * @param input Raw value to parse.
15
+ * @param userSettings Parser settings merged with `number.defaultSettings`.
16
+ * @returns Parsed number or fallback value.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * number('1 234,5'); // 1234.5
21
+ * ```
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * number('bad', { fallback: 0 }); // 0
26
+ * ```
27
+ */
28
+ var number = (input, userSettings) => {
29
+ const settings = {
30
+ ...number.defaultSettings,
31
+ ...userSettings
32
+ };
33
+ const fallback = "fallback" in settings ? settings.fallback : 0;
34
+ let result;
35
+ if (yummies_type_guard.typeGuard.isNumber(input)) result = input;
36
+ else if (yummies_type_guard.typeGuard.isString(input)) {
37
+ const formattedInput = yummies_format.format.skipSpaces(input).replace(",", ".");
38
+ if (formattedInput === "") result = fallback;
39
+ else result = Number(formattedInput);
40
+ } else result = fallback;
41
+ if (yummies_type_guard.typeGuard.isNumber(result)) {
42
+ if (settings?.clamped != null) result = Math.max(settings.clamped[0] ?? -Infinity, Math.min(result, settings.clamped[1] ?? Infinity));
43
+ if (settings?.ceil != null) result = Math.ceil(result);
44
+ if (settings?.floor != null) result = Math.floor(result);
45
+ if (settings?.digits != null) result = +result.toFixed(settings.digits);
46
+ return result;
47
+ } else return fallback;
44
48
  };
45
49
  number.defaultSettings = {};
46
- const percent = (value, maxValue, settings) => {
47
- return number(Number(value) / Number(maxValue) * 100, settings);
50
+ //#endregion
51
+ //#region src/parser/percent.ts
52
+ /**
53
+ * Converts a value into a percentage of `maxValue` and parses the result with
54
+ * the shared numeric parser.
55
+ *
56
+ * @template TFallback Fallback value type returned when parsing fails.
57
+ * @param value Current value.
58
+ * @param maxValue Maximum value representing `100%`.
59
+ * @param settings Numeric parser settings for the computed percentage.
60
+ * @returns Parsed percentage or fallback value.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * percent(25, 200); // 12.5
65
+ * ```
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * percent('bad', 100, { fallback: 0 }); // 0
70
+ * ```
71
+ */
72
+ var percent = (value, maxValue, settings) => {
73
+ return number(Number(value) / Number(maxValue) * 100, settings);
48
74
  };
49
- const string = (input, settings) => {
50
- const fallback = settings && "fallback" in settings ? settings.fallback : "";
51
- if (input == null) {
52
- return fallback;
53
- }
54
- if (typeGuard.typeGuard.isObject(input)) {
55
- if (settings?.prettyJson) {
56
- return JSON.stringify(input, null, 2);
57
- }
58
- return JSON.stringify(input);
59
- }
60
- return String(input);
75
+ //#endregion
76
+ //#region src/parser/string.ts
77
+ /**
78
+ * Converts arbitrary input into a string representation.
79
+ *
80
+ * Objects are serialized with `JSON.stringify`, optionally pretty-printed, and
81
+ * nullish values resolve to the configured fallback.
82
+ *
83
+ * @template TFallback Fallback value type returned for nullish input.
84
+ * @param input Raw value to stringify.
85
+ * @param settings String conversion settings.
86
+ * @returns Stringified input or fallback value.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * string(123); // '123'
91
+ * ```
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * string({ id: 1 }, { prettyJson: true });
96
+ * ```
97
+ */
98
+ var string = (input, settings) => {
99
+ const fallback = settings && "fallback" in settings ? settings.fallback : "";
100
+ if (input == null) return fallback;
101
+ if (yummies_type_guard.typeGuard.isObject(input)) {
102
+ if (settings?.prettyJson) return JSON.stringify(input, null, 2);
103
+ return JSON.stringify(input);
104
+ }
105
+ return String(input);
61
106
  };
62
- const _exports = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
63
- __proto__: null,
64
- number,
65
- percent,
66
- string
67
- }, Symbol.toStringTag, { value: "Module" }));
68
- exports.parser = _exports;
69
- //# sourceMappingURL=parser.cjs.map
107
+ //#endregion
108
+ //#region src/parser/_exports.ts
109
+ var _exports_exports = /* @__PURE__ */ require_chunk.__exportAll({
110
+ number: () => number,
111
+ percent: () => percent,
112
+ string: () => string
113
+ });
114
+ //#endregion
115
+ Object.defineProperty(exports, "parser", {
116
+ enumerable: true,
117
+ get: function() {
118
+ return _exports_exports;
119
+ }
120
+ });
121
+
122
+ //# sourceMappingURL=parser.cjs.map
package/parser.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"parser.cjs","sources":["../src/parser/number.ts","../src/parser/percent.ts","../src/parser/string.ts"],"sourcesContent":["import { format } from 'yummies/format';\nimport { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\n\nexport interface NumberParserSettings<TFallback = number> {\n digits?: number;\n fallback?: TFallback;\n /**\n * Round to upper boundary\n * 5.1 -> 6\n */\n ceil?: boolean;\n /**\n * Round to bottom boundary\n * 5.9 -> 5\n */\n floor?: boolean;\n clamped?: [min?: Maybe<number>, max?: Maybe<number>];\n}\n\nexport const number = <TFallback = number>(\n input: Maybe<unknown>,\n userSettings?: Maybe<NumberParserSettings<TFallback>>,\n): number | TFallback => {\n const settings = {\n ...number.defaultSettings,\n ...userSettings,\n };\n\n const fallback = (\n 'fallback' in settings ? settings.fallback : 0\n ) as TFallback;\n\n let result: number;\n\n if (typeGuard.isNumber(input)) {\n result = input;\n } else if (typeGuard.isString(input)) {\n const formattedInput = format.skipSpaces(input).replace(',', '.');\n if (formattedInput === '') {\n result = fallback as any;\n } else {\n result = Number(formattedInput);\n }\n } else {\n result = fallback as any;\n }\n\n if (typeGuard.isNumber(result)) {\n if (settings?.clamped != null) {\n result = Math.max(\n settings.clamped[0] ?? -Infinity,\n Math.min(result, settings.clamped[1] ?? Infinity),\n );\n }\n\n if (settings?.ceil != null) {\n result = Math.ceil(result);\n }\n\n if (settings?.floor != null) {\n result = Math.floor(result);\n }\n\n if (settings?.digits != null) {\n result = +result.toFixed(settings.digits);\n }\n\n return result;\n } else {\n return fallback;\n }\n};\n\nnumber.defaultSettings = {} as NumberParserSettings;\n","import type { Maybe } from 'yummies/types';\n\nimport { type NumberParserSettings, number } from './number.js';\n\nexport const percent = <TFallback = number>(\n value: Maybe<string | number>,\n maxValue?: Maybe<string | number>,\n settings?: Maybe<NumberParserSettings<TFallback>>,\n) => {\n return number<TFallback>((Number(value) / Number(maxValue)) * 100, settings);\n};\n","import { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\n\nexport interface StringParserSettings<TFallback = string> {\n fallback?: TFallback;\n prettyJson?: boolean;\n}\n\nexport const string = <TFallback = string>(\n input: Maybe<unknown>,\n settings?: Maybe<StringParserSettings<TFallback>>,\n): string | TFallback => {\n const fallback =\n settings && 'fallback' in settings ? (settings.fallback as TFallback) : '';\n\n if (input == null) {\n return fallback;\n }\n\n if (typeGuard.isObject(input)) {\n if (settings?.prettyJson) {\n return JSON.stringify(input, null, 2);\n }\n\n return JSON.stringify(input);\n }\n\n return String(input);\n};\n"],"names":["typeGuard","format"],"mappings":";;;;AAoBO,MAAM,SAAS,CACpB,OACA,iBACuB;AACvB,QAAM,WAAW;AAAA,IACf,GAAG,OAAO;AAAA,IACV,GAAG;AAAA,EAAA;AAGL,QAAM,WACJ,cAAc,WAAW,SAAS,WAAW;AAG/C,MAAI;AAEJ,MAAIA,UAAAA,UAAU,SAAS,KAAK,GAAG;AAC7B,aAAS;AAAA,EACX,WAAWA,UAAAA,UAAU,SAAS,KAAK,GAAG;AACpC,UAAM,iBAAiBC,OAAAA,OAAO,WAAW,KAAK,EAAE,QAAQ,KAAK,GAAG;AAChE,QAAI,mBAAmB,IAAI;AACzB,eAAS;AAAA,IACX,OAAO;AACL,eAAS,OAAO,cAAc;AAAA,IAChC;AAAA,EACF,OAAO;AACL,aAAS;AAAA,EACX;AAEA,MAAID,UAAAA,UAAU,SAAS,MAAM,GAAG;AAC9B,QAAI,UAAU,WAAW,MAAM;AAC7B,eAAS,KAAK;AAAA,QACZ,SAAS,QAAQ,CAAC,KAAK;AAAA,QACvB,KAAK,IAAI,QAAQ,SAAS,QAAQ,CAAC,KAAK,QAAQ;AAAA,MAAA;AAAA,IAEpD;AAEA,QAAI,UAAU,QAAQ,MAAM;AAC1B,eAAS,KAAK,KAAK,MAAM;AAAA,IAC3B;AAEA,QAAI,UAAU,SAAS,MAAM;AAC3B,eAAS,KAAK,MAAM,MAAM;AAAA,IAC5B;AAEA,QAAI,UAAU,UAAU,MAAM;AAC5B,eAAS,CAAC,OAAO,QAAQ,SAAS,MAAM;AAAA,IAC1C;AAEA,WAAO;AAAA,EACT,OAAO;AACL,WAAO;AAAA,EACT;AACF;AAEA,OAAO,kBAAkB,CAAA;ACtElB,MAAM,UAAU,CACrB,OACA,UACA,aACG;AACH,SAAO,OAAmB,OAAO,KAAK,IAAI,OAAO,QAAQ,IAAK,KAAK,QAAQ;AAC7E;ACFO,MAAM,SAAS,CACpB,OACA,aACuB;AACvB,QAAM,WACJ,YAAY,cAAc,WAAY,SAAS,WAAyB;AAE1E,MAAI,SAAS,MAAM;AACjB,WAAO;AAAA,EACT;AAEA,MAAIA,UAAAA,UAAU,SAAS,KAAK,GAAG;AAC7B,QAAI,UAAU,YAAY;AACxB,aAAO,KAAK,UAAU,OAAO,MAAM,CAAC;AAAA,IACtC;AAEA,WAAO,KAAK,UAAU,KAAK;AAAA,EAC7B;AAEA,SAAO,OAAO,KAAK;AACrB;;;;;;;;"}
1
+ {"version":3,"file":"parser.cjs","names":[],"sources":["../src/parser/number.ts","../src/parser/percent.ts","../src/parser/string.ts","../src/parser/_exports.ts"],"sourcesContent":["import { format } from 'yummies/format';\nimport { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\n\nexport interface NumberParserSettings<TFallback = number> {\n digits?: number;\n fallback?: TFallback;\n /**\n * Round to upper boundary\n * 5.1 -> 6\n */\n ceil?: boolean;\n /**\n * Round to bottom boundary\n * 5.9 -> 5\n */\n floor?: boolean;\n clamped?: [min?: Maybe<number>, max?: Maybe<number>];\n}\n\n/**\n * Parses a number from raw input and optionally clamps, rounds or limits\n * fractional digits.\n *\n * Strings are normalized by removing spaces and replacing `,` with `.` before\n * parsing. Invalid inputs return the configured fallback.\n *\n * @template TFallback Fallback value type returned when parsing fails.\n * @param input Raw value to parse.\n * @param userSettings Parser settings merged with `number.defaultSettings`.\n * @returns Parsed number or fallback value.\n *\n * @example\n * ```ts\n * number('1 234,5'); // 1234.5\n * ```\n *\n * @example\n * ```ts\n * number('bad', { fallback: 0 }); // 0\n * ```\n */\nexport const number = <TFallback = number>(\n input: Maybe<unknown>,\n userSettings?: Maybe<NumberParserSettings<TFallback>>,\n): number | TFallback => {\n const settings = {\n ...number.defaultSettings,\n ...userSettings,\n };\n\n const fallback = (\n 'fallback' in settings ? settings.fallback : 0\n ) as TFallback;\n\n let result: number;\n\n if (typeGuard.isNumber(input)) {\n result = input;\n } else if (typeGuard.isString(input)) {\n const formattedInput = format.skipSpaces(input).replace(',', '.');\n if (formattedInput === '') {\n result = fallback as any;\n } else {\n result = Number(formattedInput);\n }\n } else {\n result = fallback as any;\n }\n\n if (typeGuard.isNumber(result)) {\n if (settings?.clamped != null) {\n result = Math.max(\n settings.clamped[0] ?? -Infinity,\n Math.min(result, settings.clamped[1] ?? Infinity),\n );\n }\n\n if (settings?.ceil != null) {\n result = Math.ceil(result);\n }\n\n if (settings?.floor != null) {\n result = Math.floor(result);\n }\n\n if (settings?.digits != null) {\n result = +result.toFixed(settings.digits);\n }\n\n return result;\n } else {\n return fallback;\n }\n};\n\nnumber.defaultSettings = {} as NumberParserSettings;\n","import type { Maybe } from 'yummies/types';\n\nimport { type NumberParserSettings, number } from './number.js';\n\n/**\n * Converts a value into a percentage of `maxValue` and parses the result with\n * the shared numeric parser.\n *\n * @template TFallback Fallback value type returned when parsing fails.\n * @param value Current value.\n * @param maxValue Maximum value representing `100%`.\n * @param settings Numeric parser settings for the computed percentage.\n * @returns Parsed percentage or fallback value.\n *\n * @example\n * ```ts\n * percent(25, 200); // 12.5\n * ```\n *\n * @example\n * ```ts\n * percent('bad', 100, { fallback: 0 }); // 0\n * ```\n */\nexport const percent = <TFallback = number>(\n value: Maybe<string | number>,\n maxValue?: Maybe<string | number>,\n settings?: Maybe<NumberParserSettings<TFallback>>,\n) => {\n return number<TFallback>((Number(value) / Number(maxValue)) * 100, settings);\n};\n","import { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\n\nexport interface StringParserSettings<TFallback = string> {\n fallback?: TFallback;\n prettyJson?: boolean;\n}\n\n/**\n * Converts arbitrary input into a string representation.\n *\n * Objects are serialized with `JSON.stringify`, optionally pretty-printed, and\n * nullish values resolve to the configured fallback.\n *\n * @template TFallback Fallback value type returned for nullish input.\n * @param input Raw value to stringify.\n * @param settings String conversion settings.\n * @returns Stringified input or fallback value.\n *\n * @example\n * ```ts\n * string(123); // '123'\n * ```\n *\n * @example\n * ```ts\n * string({ id: 1 }, { prettyJson: true });\n * ```\n */\nexport const string = <TFallback = string>(\n input: Maybe<unknown>,\n settings?: Maybe<StringParserSettings<TFallback>>,\n): string | TFallback => {\n const fallback =\n settings && 'fallback' in settings ? (settings.fallback as TFallback) : '';\n\n if (input == null) {\n return fallback;\n }\n\n if (typeGuard.isObject(input)) {\n if (settings?.prettyJson) {\n return JSON.stringify(input, null, 2);\n }\n\n return JSON.stringify(input);\n }\n\n return String(input);\n};\n","export * from './number.js';\nexport * from './percent.js';\nexport * from './string.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,IAAa,UACX,OACA,iBACuB;CACvB,MAAM,WAAW;EACf,GAAG,OAAO;EACV,GAAG;EACJ;CAED,MAAM,WACJ,cAAc,WAAW,SAAS,WAAW;CAG/C,IAAI;AAEJ,KAAI,mBAAA,UAAU,SAAS,MAAM,CAC3B,UAAS;UACA,mBAAA,UAAU,SAAS,MAAM,EAAE;EACpC,MAAM,iBAAiB,eAAA,OAAO,WAAW,MAAM,CAAC,QAAQ,KAAK,IAAI;AACjE,MAAI,mBAAmB,GACrB,UAAS;MAET,UAAS,OAAO,eAAe;OAGjC,UAAS;AAGX,KAAI,mBAAA,UAAU,SAAS,OAAO,EAAE;AAC9B,MAAI,UAAU,WAAW,KACvB,UAAS,KAAK,IACZ,SAAS,QAAQ,MAAM,WACvB,KAAK,IAAI,QAAQ,SAAS,QAAQ,MAAM,SAAS,CAClD;AAGH,MAAI,UAAU,QAAQ,KACpB,UAAS,KAAK,KAAK,OAAO;AAG5B,MAAI,UAAU,SAAS,KACrB,UAAS,KAAK,MAAM,OAAO;AAG7B,MAAI,UAAU,UAAU,KACtB,UAAS,CAAC,OAAO,QAAQ,SAAS,OAAO;AAG3C,SAAO;OAEP,QAAO;;AAIX,OAAO,kBAAkB,EAAE;;;;;;;;;;;;;;;;;;;;;;;ACxE3B,IAAa,WACX,OACA,UACA,aACG;AACH,QAAO,OAAmB,OAAO,MAAM,GAAG,OAAO,SAAS,GAAI,KAAK,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;ACA9E,IAAa,UACX,OACA,aACuB;CACvB,MAAM,WACJ,YAAY,cAAc,WAAY,SAAS,WAAyB;AAE1E,KAAI,SAAS,KACX,QAAO;AAGT,KAAI,mBAAA,UAAU,SAAS,MAAM,EAAE;AAC7B,MAAI,UAAU,WACZ,QAAO,KAAK,UAAU,OAAO,MAAM,EAAE;AAGvC,SAAO,KAAK,UAAU,MAAM;;AAG9B,QAAO,OAAO,MAAM"}
package/parser.d.ts CHANGED
@@ -15,17 +15,80 @@ interface NumberParserSettings<TFallback = number> {
15
15
  floor?: boolean;
16
16
  clamped?: [min?: Maybe<number>, max?: Maybe<number>];
17
17
  }
18
+ /**
19
+ * Parses a number from raw input and optionally clamps, rounds or limits
20
+ * fractional digits.
21
+ *
22
+ * Strings are normalized by removing spaces and replacing `,` with `.` before
23
+ * parsing. Invalid inputs return the configured fallback.
24
+ *
25
+ * @template TFallback Fallback value type returned when parsing fails.
26
+ * @param input Raw value to parse.
27
+ * @param userSettings Parser settings merged with `number.defaultSettings`.
28
+ * @returns Parsed number or fallback value.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * number('1 234,5'); // 1234.5
33
+ * ```
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * number('bad', { fallback: 0 }); // 0
38
+ * ```
39
+ */
18
40
  declare const number: {
19
41
  <TFallback = number>(input: Maybe<unknown>, userSettings?: Maybe<NumberParserSettings<TFallback>>): number | TFallback;
20
42
  defaultSettings: NumberParserSettings<number>;
21
43
  };
22
44
 
45
+ /**
46
+ * Converts a value into a percentage of `maxValue` and parses the result with
47
+ * the shared numeric parser.
48
+ *
49
+ * @template TFallback Fallback value type returned when parsing fails.
50
+ * @param value Current value.
51
+ * @param maxValue Maximum value representing `100%`.
52
+ * @param settings Numeric parser settings for the computed percentage.
53
+ * @returns Parsed percentage or fallback value.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * percent(25, 200); // 12.5
58
+ * ```
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * percent('bad', 100, { fallback: 0 }); // 0
63
+ * ```
64
+ */
23
65
  declare const percent: <TFallback = number>(value: Maybe<string | number>, maxValue?: Maybe<string | number>, settings?: Maybe<NumberParserSettings<TFallback>>) => number | TFallback;
24
66
 
25
67
  interface StringParserSettings<TFallback = string> {
26
68
  fallback?: TFallback;
27
69
  prettyJson?: boolean;
28
70
  }
71
+ /**
72
+ * Converts arbitrary input into a string representation.
73
+ *
74
+ * Objects are serialized with `JSON.stringify`, optionally pretty-printed, and
75
+ * nullish values resolve to the configured fallback.
76
+ *
77
+ * @template TFallback Fallback value type returned for nullish input.
78
+ * @param input Raw value to stringify.
79
+ * @param settings String conversion settings.
80
+ * @returns Stringified input or fallback value.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * string(123); // '123'
85
+ * ```
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * string({ id: 1 }, { prettyJson: true });
90
+ * ```
91
+ */
29
92
  declare const string: <TFallback = string>(input: Maybe<unknown>, settings?: Maybe<StringParserSettings<TFallback>>) => string | TFallback;
30
93
 
31
94
  type _exports_NumberParserSettings<TFallback = number> = NumberParserSettings<TFallback>;