yummies 7.11.0 → 7.13.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 (159) hide show
  1. package/README.md +5 -87
  2. package/async.cjs +179 -48
  3. package/async.cjs.map +1 -1
  4. package/async.d.ts +125 -7
  5. package/async.js +180 -54
  6. package/async.js.map +1 -1
  7. package/chunk-CVq3Gv4J.cjs +50 -0
  8. package/chunk-YKewjYmz.js +37 -0
  9. package/common.cjs +48 -8
  10. package/common.cjs.map +1 -1
  11. package/common.d.ts +53 -2
  12. package/common.js +49 -11
  13. package/common.js.map +1 -1
  14. package/complex.cjs +275 -128
  15. package/complex.cjs.map +1 -1
  16. package/complex.d.ts +66 -0
  17. package/complex.js +275 -133
  18. package/complex.js.map +1 -1
  19. package/cookie.cjs +17 -7
  20. package/cookie.cjs.map +1 -1
  21. package/cookie.d.ts +26 -0
  22. package/cookie.js +18 -9
  23. package/cookie.js.map +1 -1
  24. package/css.cjs +163 -39
  25. package/css.cjs.map +1 -1
  26. package/css.d.ts +115 -6
  27. package/css.js +159 -41
  28. package/css.js.map +1 -1
  29. package/data.cjs +90 -55
  30. package/data.cjs.map +1 -1
  31. package/data.d.ts +50 -0
  32. package/data.js +91 -61
  33. package/data.js.map +1 -1
  34. package/date-time.cjs +594 -412
  35. package/date-time.cjs.map +1 -1
  36. package/date-time.d.ts +105 -0
  37. package/date-time.js +591 -421
  38. package/date-time.js.map +1 -1
  39. package/device.cjs +65 -23
  40. package/device.cjs.map +1 -1
  41. package/device.d.ts +49 -0
  42. package/device.js +66 -31
  43. package/device.js.map +1 -1
  44. package/encodings.cjs +275 -266
  45. package/encodings.cjs.map +1 -1
  46. package/encodings.d.ts +25 -0
  47. package/encodings.js +276 -268
  48. package/encodings.js.map +1 -1
  49. package/errors.cjs +36 -18
  50. package/errors.cjs.map +1 -1
  51. package/errors.d.ts +17 -0
  52. package/errors.js +35 -19
  53. package/errors.js.map +1 -1
  54. package/file.cjs +58 -24
  55. package/file.cjs.map +1 -1
  56. package/file.d.ts +32 -0
  57. package/file.js +59 -27
  58. package/file.js.map +1 -1
  59. package/format.cjs +125 -83
  60. package/format.cjs.map +1 -1
  61. package/format.d.ts +18 -0
  62. package/format.js +118 -82
  63. package/format.js.map +1 -1
  64. package/html.cjs +242 -137
  65. package/html.cjs.map +1 -1
  66. package/html.d.ts +81 -0
  67. package/html.js +239 -150
  68. package/html.js.map +1 -1
  69. package/id.cjs +90 -17
  70. package/id.cjs.map +1 -1
  71. package/id.d.ts +16 -0
  72. package/id.js +89 -24
  73. package/id.js.map +1 -1
  74. package/imports.cjs +57 -29
  75. package/imports.cjs.map +1 -1
  76. package/imports.d.ts +24 -0
  77. package/imports.js +56 -31
  78. package/imports.js.map +1 -1
  79. package/math.cjs +32 -6
  80. package/math.cjs.map +1 -1
  81. package/math.d.ts +33 -0
  82. package/math.js +33 -10
  83. package/math.js.map +1 -1
  84. package/media.cjs +291 -84
  85. package/media.cjs.map +1 -1
  86. package/media.d.ts +204 -2
  87. package/media.js +290 -93
  88. package/media.js.map +1 -1
  89. package/mobx.cjs +449 -193
  90. package/mobx.cjs.map +1 -1
  91. package/mobx.d.ts +108 -0
  92. package/mobx.js +447 -200
  93. package/mobx.js.map +1 -1
  94. package/ms.cjs +37 -10
  95. package/ms.cjs.map +1 -1
  96. package/ms.d.ts +16 -0
  97. package/ms.js +38 -13
  98. package/ms.js.map +1 -1
  99. package/number.cjs +29 -7
  100. package/number.cjs.map +1 -1
  101. package/number.d.ts +16 -0
  102. package/number.js +30 -9
  103. package/number.js.map +1 -1
  104. package/package.json +11 -3
  105. package/parser.cjs +117 -64
  106. package/parser.cjs.map +1 -1
  107. package/parser.d.ts +17 -0
  108. package/parser.js +111 -64
  109. package/parser.js.map +1 -1
  110. package/price.cjs +24 -18
  111. package/price.cjs.map +1 -1
  112. package/price.d.ts +24 -0
  113. package/price.js +25 -20
  114. package/price.js.map +1 -1
  115. package/random.cjs +95 -13
  116. package/random.cjs.map +1 -1
  117. package/random.d.ts +80 -0
  118. package/random.js +96 -22
  119. package/random.js.map +1 -1
  120. package/react.cjs +673 -214
  121. package/react.cjs.map +1 -1
  122. package/react.d.ts +21 -0
  123. package/react.js +674 -239
  124. package/react.js.map +1 -1
  125. package/sound.cjs +30 -9
  126. package/sound.cjs.map +1 -1
  127. package/sound.d.ts +16 -0
  128. package/sound.js +31 -11
  129. package/sound.js.map +1 -1
  130. package/storage.cjs +49 -50
  131. package/storage.cjs.map +1 -1
  132. package/storage.d.ts +24 -0
  133. package/storage.js +50 -53
  134. package/storage.js.map +1 -1
  135. package/text.cjs +67 -34
  136. package/text.cjs.map +1 -1
  137. package/text.d.ts +16 -0
  138. package/text.js +68 -37
  139. package/text.js.map +1 -1
  140. package/type-guard.cjs +292 -72
  141. package/type-guard.cjs.map +1 -1
  142. package/type-guard.d.ts +18 -0
  143. package/type-guard.js +288 -73
  144. package/type-guard.js.map +1 -1
  145. package/types.cjs +0 -2
  146. package/types.d.ts +41 -0
  147. package/types.global.cjs +0 -2
  148. package/types.global.d.ts +41 -0
  149. package/types.global.js +0 -2
  150. package/types.js +0 -2
  151. package/vibrate.cjs +47 -6
  152. package/vibrate.cjs.map +1 -1
  153. package/vibrate.d.ts +39 -1
  154. package/vibrate.js +48 -8
  155. package/vibrate.js.map +1 -1
  156. package/types.cjs.map +0 -1
  157. package/types.global.cjs.map +0 -1
  158. package/types.global.js.map +0 -1
  159. package/types.js.map +0 -1
package/errors.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"errors.cjs","sources":["../src/errors.ts"],"sourcesContent":["import { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\n\ntype GetErrorTextEnhancer = (error: any) => string;\ntype GetErrorTextFormatErrorFn = (error: Error) => string;\n\n/**\n * Universal function for transforming any errors into readable error text\n *\n * This function can be enhanced with custom handlers using:\n * - `getErrorText.unknownErrorText`\n * - `getErrorText.formatError`\n * - `getErrorText.enhance`\n */\nexport const getErrorText = (error: unknown) => {\n if (!error) {\n return getErrorText.unknownErrorText;\n }\n\n if (typeGuard.isString(error)) {\n return error || getErrorText.unknownErrorText;\n }\n\n if (error instanceof Error) {\n return (\n (getErrorText.formatError?.(error) ?? error.message) ||\n getErrorText.unknownErrorText\n );\n }\n\n if (getErrorText.enhance) {\n return getErrorText.enhance(error) ?? getErrorText.unknownErrorText;\n } else {\n return getErrorText.unknownErrorText;\n }\n};\n\ngetErrorText.unknownErrorText = '';\ngetErrorText.formatError = null as Maybe<GetErrorTextFormatErrorFn>;\ngetErrorText.enhance = null as Maybe<GetErrorTextEnhancer>;\n"],"names":["typeGuard"],"mappings":";;;AAcO,MAAM,eAAe,CAAC,UAAmB;AAC9C,MAAI,CAAC,OAAO;AACV,WAAO,aAAa;AAAA,EACtB;AAEA,MAAIA,UAAAA,UAAU,SAAS,KAAK,GAAG;AAC7B,WAAO,SAAS,aAAa;AAAA,EAC/B;AAEA,MAAI,iBAAiB,OAAO;AAC1B,YACG,aAAa,cAAc,KAAK,KAAK,MAAM,YAC5C,aAAa;AAAA,EAEjB;AAEA,MAAI,aAAa,SAAS;AACxB,WAAO,aAAa,QAAQ,KAAK,KAAK,aAAa;AAAA,EACrD,OAAO;AACL,WAAO,aAAa;AAAA,EACtB;AACF;AAEA,aAAa,mBAAmB;AAChC,aAAa,cAAc;AAC3B,aAAa,UAAU;;"}
1
+ {"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * ---header-docs-section---\n * # yummies/errors\n *\n * ## Description\n *\n * Turns thrown values, `Error` objects, and unknown API failures into a single human-readable string\n * for toasts, forms, and logs. The default `getErrorText` can be extended with custom formatters and\n * enhancers so domain-specific errors still map to stable copy without try/catch boilerplate.\n *\n * ## Usage\n *\n * ```ts\n * import { getErrorText } from \"yummies/errors\";\n * ```\n */\n\nimport { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\n\ntype GetErrorTextEnhancer = (error: any) => string;\ntype GetErrorTextFormatErrorFn = (error: Error) => string;\n\n/**\n * Universal function for transforming any errors into readable error text\n *\n * This function can be enhanced with custom handlers using:\n * - `getErrorText.unknownErrorText`\n * - `getErrorText.formatError`\n * - `getErrorText.enhance`\n */\nexport const getErrorText = (error: unknown) => {\n if (!error) {\n return getErrorText.unknownErrorText;\n }\n\n if (typeGuard.isString(error)) {\n return error || getErrorText.unknownErrorText;\n }\n\n if (error instanceof Error) {\n return (\n (getErrorText.formatError?.(error) ?? error.message) ||\n getErrorText.unknownErrorText\n );\n }\n\n if (getErrorText.enhance) {\n return getErrorText.enhance(error) ?? getErrorText.unknownErrorText;\n } else {\n return getErrorText.unknownErrorText;\n }\n};\n\ngetErrorText.unknownErrorText = '';\ngetErrorText.formatError = null as Maybe<GetErrorTextFormatErrorFn>;\ngetErrorText.enhance = null as Maybe<GetErrorTextEnhancer>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,IAAa,gBAAgB,UAAmB;AAC9C,KAAI,CAAC,MACH,QAAO,aAAa;AAGtB,KAAI,mBAAA,UAAU,SAAS,MAAM,CAC3B,QAAO,SAAS,aAAa;AAG/B,KAAI,iBAAiB,MACnB,SACG,aAAa,cAAc,MAAM,IAAI,MAAM,YAC5C,aAAa;AAIjB,KAAI,aAAa,QACf,QAAO,aAAa,QAAQ,MAAM,IAAI,aAAa;KAEnD,QAAO,aAAa;;AAIxB,aAAa,mBAAmB;AAChC,aAAa,cAAc;AAC3B,aAAa,UAAU"}
package/errors.d.ts CHANGED
@@ -1,5 +1,22 @@
1
1
  import { Maybe } from 'yummies/types';
2
2
 
3
+ /**
4
+ * ---header-docs-section---
5
+ * # yummies/errors
6
+ *
7
+ * ## Description
8
+ *
9
+ * Turns thrown values, `Error` objects, and unknown API failures into a single human-readable string
10
+ * for toasts, forms, and logs. The default `getErrorText` can be extended with custom formatters and
11
+ * enhancers so domain-specific errors still map to stable copy without try/catch boilerplate.
12
+ *
13
+ * ## Usage
14
+ *
15
+ * ```ts
16
+ * import { getErrorText } from "yummies/errors";
17
+ * ```
18
+ */
19
+
3
20
  type GetErrorTextEnhancer = (error: any) => string;
4
21
  type GetErrorTextFormatErrorFn = (error: Error) => string;
5
22
  /**
package/errors.js CHANGED
@@ -1,24 +1,40 @@
1
1
  import { typeGuard } from "yummies/type-guard";
2
- const getErrorText = (error) => {
3
- if (!error) {
4
- return getErrorText.unknownErrorText;
5
- }
6
- if (typeGuard.isString(error)) {
7
- return error || getErrorText.unknownErrorText;
8
- }
9
- if (error instanceof Error) {
10
- return (getErrorText.formatError?.(error) ?? error.message) || getErrorText.unknownErrorText;
11
- }
12
- if (getErrorText.enhance) {
13
- return getErrorText.enhance(error) ?? getErrorText.unknownErrorText;
14
- } else {
15
- return getErrorText.unknownErrorText;
16
- }
2
+ //#region src/errors.ts
3
+ /**
4
+ * ---header-docs-section---
5
+ * # yummies/errors
6
+ *
7
+ * ## Description
8
+ *
9
+ * Turns thrown values, `Error` objects, and unknown API failures into a single human-readable string
10
+ * for toasts, forms, and logs. The default `getErrorText` can be extended with custom formatters and
11
+ * enhancers so domain-specific errors still map to stable copy without try/catch boilerplate.
12
+ *
13
+ * ## Usage
14
+ *
15
+ * ```ts
16
+ * import { getErrorText } from "yummies/errors";
17
+ * ```
18
+ */
19
+ /**
20
+ * Universal function for transforming any errors into readable error text
21
+ *
22
+ * This function can be enhanced with custom handlers using:
23
+ * - `getErrorText.unknownErrorText`
24
+ * - `getErrorText.formatError`
25
+ * - `getErrorText.enhance`
26
+ */
27
+ var getErrorText = (error) => {
28
+ if (!error) return getErrorText.unknownErrorText;
29
+ if (typeGuard.isString(error)) return error || getErrorText.unknownErrorText;
30
+ if (error instanceof Error) return (getErrorText.formatError?.(error) ?? error.message) || getErrorText.unknownErrorText;
31
+ if (getErrorText.enhance) return getErrorText.enhance(error) ?? getErrorText.unknownErrorText;
32
+ else return getErrorText.unknownErrorText;
17
33
  };
18
34
  getErrorText.unknownErrorText = "";
19
35
  getErrorText.formatError = null;
20
36
  getErrorText.enhance = null;
21
- export {
22
- getErrorText
23
- };
24
- //# sourceMappingURL=errors.js.map
37
+ //#endregion
38
+ export { getErrorText };
39
+
40
+ //# sourceMappingURL=errors.js.map
package/errors.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sources":["../src/errors.ts"],"sourcesContent":["import { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\n\ntype GetErrorTextEnhancer = (error: any) => string;\ntype GetErrorTextFormatErrorFn = (error: Error) => string;\n\n/**\n * Universal function for transforming any errors into readable error text\n *\n * This function can be enhanced with custom handlers using:\n * - `getErrorText.unknownErrorText`\n * - `getErrorText.formatError`\n * - `getErrorText.enhance`\n */\nexport const getErrorText = (error: unknown) => {\n if (!error) {\n return getErrorText.unknownErrorText;\n }\n\n if (typeGuard.isString(error)) {\n return error || getErrorText.unknownErrorText;\n }\n\n if (error instanceof Error) {\n return (\n (getErrorText.formatError?.(error) ?? error.message) ||\n getErrorText.unknownErrorText\n );\n }\n\n if (getErrorText.enhance) {\n return getErrorText.enhance(error) ?? getErrorText.unknownErrorText;\n } else {\n return getErrorText.unknownErrorText;\n }\n};\n\ngetErrorText.unknownErrorText = '';\ngetErrorText.formatError = null as Maybe<GetErrorTextFormatErrorFn>;\ngetErrorText.enhance = null as Maybe<GetErrorTextEnhancer>;\n"],"names":[],"mappings":";AAcO,MAAM,eAAe,CAAC,UAAmB;AAC9C,MAAI,CAAC,OAAO;AACV,WAAO,aAAa;AAAA,EACtB;AAEA,MAAI,UAAU,SAAS,KAAK,GAAG;AAC7B,WAAO,SAAS,aAAa;AAAA,EAC/B;AAEA,MAAI,iBAAiB,OAAO;AAC1B,YACG,aAAa,cAAc,KAAK,KAAK,MAAM,YAC5C,aAAa;AAAA,EAEjB;AAEA,MAAI,aAAa,SAAS;AACxB,WAAO,aAAa,QAAQ,KAAK,KAAK,aAAa;AAAA,EACrD,OAAO;AACL,WAAO,aAAa;AAAA,EACtB;AACF;AAEA,aAAa,mBAAmB;AAChC,aAAa,cAAc;AAC3B,aAAa,UAAU;"}
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * ---header-docs-section---\n * # yummies/errors\n *\n * ## Description\n *\n * Turns thrown values, `Error` objects, and unknown API failures into a single human-readable string\n * for toasts, forms, and logs. The default `getErrorText` can be extended with custom formatters and\n * enhancers so domain-specific errors still map to stable copy without try/catch boilerplate.\n *\n * ## Usage\n *\n * ```ts\n * import { getErrorText } from \"yummies/errors\";\n * ```\n */\n\nimport { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\n\ntype GetErrorTextEnhancer = (error: any) => string;\ntype GetErrorTextFormatErrorFn = (error: Error) => string;\n\n/**\n * Universal function for transforming any errors into readable error text\n *\n * This function can be enhanced with custom handlers using:\n * - `getErrorText.unknownErrorText`\n * - `getErrorText.formatError`\n * - `getErrorText.enhance`\n */\nexport const getErrorText = (error: unknown) => {\n if (!error) {\n return getErrorText.unknownErrorText;\n }\n\n if (typeGuard.isString(error)) {\n return error || getErrorText.unknownErrorText;\n }\n\n if (error instanceof Error) {\n return (\n (getErrorText.formatError?.(error) ?? error.message) ||\n getErrorText.unknownErrorText\n );\n }\n\n if (getErrorText.enhance) {\n return getErrorText.enhance(error) ?? getErrorText.unknownErrorText;\n } else {\n return getErrorText.unknownErrorText;\n }\n};\n\ngetErrorText.unknownErrorText = '';\ngetErrorText.formatError = null as Maybe<GetErrorTextFormatErrorFn>;\ngetErrorText.enhance = null as Maybe<GetErrorTextEnhancer>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,IAAa,gBAAgB,UAAmB;AAC9C,KAAI,CAAC,MACH,QAAO,aAAa;AAGtB,KAAI,UAAU,SAAS,MAAM,CAC3B,QAAO,SAAS,aAAa;AAG/B,KAAI,iBAAiB,MACnB,SACG,aAAa,cAAc,MAAM,IAAI,MAAM,YAC5C,aAAa;AAIjB,KAAI,aAAa,QACf,QAAO,aAAa,QAAQ,MAAM,IAAI,aAAa;KAEnD,QAAO,aAAa;;AAIxB,aAAa,mBAAmB;AAChC,aAAa,cAAc;AAC3B,aAAa,UAAU"}
package/file.cjs CHANGED
@@ -1,29 +1,63 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const getBase64FromFile = (file) => {
4
- return new Promise((resolve, reject) => {
5
- const reader = new FileReader();
6
- reader.readAsDataURL(file);
7
- reader.onload = () => {
8
- resolve(reader.result.toString());
9
- };
10
- reader.onerror = (error) => {
11
- reject(error);
12
- };
13
- });
2
+ //#region src/file.ts
3
+ /**
4
+ * ---header-docs-section---
5
+ * # yummies/file
6
+ *
7
+ * ## Description
8
+ *
9
+ * Browser `File` helpers: reading contents as Base64 data URLs or plain text with optional
10
+ * encoding. They wrap `FileReader` in promises so async flows stay linear and errors surface as
11
+ * rejections. Handy for uploads, import wizards, and client-side parsing without extra libraries.
12
+ *
13
+ * ## Usage
14
+ *
15
+ * ```ts
16
+ * import { getBase64FromFile } from "yummies/file";
17
+ * ```
18
+ */
19
+ /**
20
+ * Reads a file as a Base64 data URL.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const value = await getBase64FromFile(file);
25
+ * ```
26
+ */
27
+ var getBase64FromFile = (file) => {
28
+ return new Promise((resolve, reject) => {
29
+ const reader = new FileReader();
30
+ reader.readAsDataURL(file);
31
+ reader.onload = () => {
32
+ resolve(reader.result.toString());
33
+ };
34
+ reader.onerror = (error) => {
35
+ reject(error);
36
+ };
37
+ });
14
38
  };
15
- const getTextFromFile = (file, encoding) => {
16
- return new Promise((resolve, reject) => {
17
- const reader = new FileReader();
18
- reader.readAsText(file, encoding);
19
- reader.onload = () => {
20
- resolve(reader.result.toString());
21
- };
22
- reader.onerror = (error) => {
23
- reject(error);
24
- };
25
- });
39
+ /**
40
+ * Reads a file as text using the provided encoding.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const text = await getTextFromFile(file, 'utf-8');
45
+ * ```
46
+ */
47
+ var getTextFromFile = (file, encoding) => {
48
+ return new Promise((resolve, reject) => {
49
+ const reader = new FileReader();
50
+ reader.readAsText(file, encoding);
51
+ reader.onload = () => {
52
+ resolve(reader.result.toString());
53
+ };
54
+ reader.onerror = (error) => {
55
+ reject(error);
56
+ };
57
+ });
26
58
  };
59
+ //#endregion
27
60
  exports.getBase64FromFile = getBase64FromFile;
28
61
  exports.getTextFromFile = getTextFromFile;
29
- //# sourceMappingURL=file.cjs.map
62
+
63
+ //# sourceMappingURL=file.cjs.map
package/file.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"file.cjs","sources":["../src/file.ts"],"sourcesContent":["export const getBase64FromFile = (file: File) => {\n return new Promise<string>((resolve, reject) => {\n const reader = new FileReader();\n reader.readAsDataURL(file);\n reader.onload = () => {\n resolve(reader.result!.toString());\n };\n reader.onerror = (error) => {\n reject(error);\n };\n });\n};\n\nexport const getTextFromFile = (file: File, encoding?: string) => {\n return new Promise<string>((resolve, reject) => {\n const reader = new FileReader();\n reader.readAsText(file, encoding);\n reader.onload = () => {\n resolve(reader.result!.toString());\n };\n reader.onerror = (error) => {\n reject(error);\n };\n });\n};\n"],"names":[],"mappings":";;AAAO,MAAM,oBAAoB,CAAC,SAAe;AAC/C,SAAO,IAAI,QAAgB,CAAC,SAAS,WAAW;AAC9C,UAAM,SAAS,IAAI,WAAA;AACnB,WAAO,cAAc,IAAI;AACzB,WAAO,SAAS,MAAM;AACpB,cAAQ,OAAO,OAAQ,UAAU;AAAA,IACnC;AACA,WAAO,UAAU,CAAC,UAAU;AAC1B,aAAO,KAAK;AAAA,IACd;AAAA,EACF,CAAC;AACH;AAEO,MAAM,kBAAkB,CAAC,MAAY,aAAsB;AAChE,SAAO,IAAI,QAAgB,CAAC,SAAS,WAAW;AAC9C,UAAM,SAAS,IAAI,WAAA;AACnB,WAAO,WAAW,MAAM,QAAQ;AAChC,WAAO,SAAS,MAAM;AACpB,cAAQ,OAAO,OAAQ,UAAU;AAAA,IACnC;AACA,WAAO,UAAU,CAAC,UAAU;AAC1B,aAAO,KAAK;AAAA,IACd;AAAA,EACF,CAAC;AACH;;;"}
1
+ {"version":3,"file":"file.cjs","names":[],"sources":["../src/file.ts"],"sourcesContent":["/**\n * ---header-docs-section---\n * # yummies/file\n *\n * ## Description\n *\n * Browser `File` helpers: reading contents as Base64 data URLs or plain text with optional\n * encoding. They wrap `FileReader` in promises so async flows stay linear and errors surface as\n * rejections. Handy for uploads, import wizards, and client-side parsing without extra libraries.\n *\n * ## Usage\n *\n * ```ts\n * import { getBase64FromFile } from \"yummies/file\";\n * ```\n */\n\n/**\n * Reads a file as a Base64 data URL.\n *\n * @example\n * ```ts\n * const value = await getBase64FromFile(file);\n * ```\n */\nexport const getBase64FromFile = (file: File) => {\n return new Promise<string>((resolve, reject) => {\n const reader = new FileReader();\n reader.readAsDataURL(file);\n reader.onload = () => {\n resolve(reader.result!.toString());\n };\n reader.onerror = (error) => {\n reject(error);\n };\n });\n};\n\n/**\n * Reads a file as text using the provided encoding.\n *\n * @example\n * ```ts\n * const text = await getTextFromFile(file, 'utf-8');\n * ```\n */\nexport const getTextFromFile = (file: File, encoding?: string) => {\n return new Promise<string>((resolve, reject) => {\n const reader = new FileReader();\n reader.readAsText(file, encoding);\n reader.onload = () => {\n resolve(reader.result!.toString());\n };\n reader.onerror = (error) => {\n reject(error);\n };\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,IAAa,qBAAqB,SAAe;AAC/C,QAAO,IAAI,SAAiB,SAAS,WAAW;EAC9C,MAAM,SAAS,IAAI,YAAY;AAC/B,SAAO,cAAc,KAAK;AAC1B,SAAO,eAAe;AACpB,WAAQ,OAAO,OAAQ,UAAU,CAAC;;AAEpC,SAAO,WAAW,UAAU;AAC1B,UAAO,MAAM;;GAEf;;;;;;;;;;AAWJ,IAAa,mBAAmB,MAAY,aAAsB;AAChE,QAAO,IAAI,SAAiB,SAAS,WAAW;EAC9C,MAAM,SAAS,IAAI,YAAY;AAC/B,SAAO,WAAW,MAAM,SAAS;AACjC,SAAO,eAAe;AACpB,WAAQ,OAAO,OAAQ,UAAU,CAAC;;AAEpC,SAAO,WAAW,UAAU;AAC1B,UAAO,MAAM;;GAEf"}
package/file.d.ts CHANGED
@@ -1,4 +1,36 @@
1
+ /**
2
+ * ---header-docs-section---
3
+ * # yummies/file
4
+ *
5
+ * ## Description
6
+ *
7
+ * Browser `File` helpers: reading contents as Base64 data URLs or plain text with optional
8
+ * encoding. They wrap `FileReader` in promises so async flows stay linear and errors surface as
9
+ * rejections. Handy for uploads, import wizards, and client-side parsing without extra libraries.
10
+ *
11
+ * ## Usage
12
+ *
13
+ * ```ts
14
+ * import { getBase64FromFile } from "yummies/file";
15
+ * ```
16
+ */
17
+ /**
18
+ * Reads a file as a Base64 data URL.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const value = await getBase64FromFile(file);
23
+ * ```
24
+ */
1
25
  declare const getBase64FromFile: (file: File) => Promise<string>;
26
+ /**
27
+ * Reads a file as text using the provided encoding.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const text = await getTextFromFile(file, 'utf-8');
32
+ * ```
33
+ */
2
34
  declare const getTextFromFile: (file: File, encoding?: string) => Promise<string>;
3
35
 
4
36
  export { getBase64FromFile, getTextFromFile };
package/file.js CHANGED
@@ -1,29 +1,61 @@
1
- const getBase64FromFile = (file) => {
2
- return new Promise((resolve, reject) => {
3
- const reader = new FileReader();
4
- reader.readAsDataURL(file);
5
- reader.onload = () => {
6
- resolve(reader.result.toString());
7
- };
8
- reader.onerror = (error) => {
9
- reject(error);
10
- };
11
- });
1
+ //#region src/file.ts
2
+ /**
3
+ * ---header-docs-section---
4
+ * # yummies/file
5
+ *
6
+ * ## Description
7
+ *
8
+ * Browser `File` helpers: reading contents as Base64 data URLs or plain text with optional
9
+ * encoding. They wrap `FileReader` in promises so async flows stay linear and errors surface as
10
+ * rejections. Handy for uploads, import wizards, and client-side parsing without extra libraries.
11
+ *
12
+ * ## Usage
13
+ *
14
+ * ```ts
15
+ * import { getBase64FromFile } from "yummies/file";
16
+ * ```
17
+ */
18
+ /**
19
+ * Reads a file as a Base64 data URL.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * const value = await getBase64FromFile(file);
24
+ * ```
25
+ */
26
+ var getBase64FromFile = (file) => {
27
+ return new Promise((resolve, reject) => {
28
+ const reader = new FileReader();
29
+ reader.readAsDataURL(file);
30
+ reader.onload = () => {
31
+ resolve(reader.result.toString());
32
+ };
33
+ reader.onerror = (error) => {
34
+ reject(error);
35
+ };
36
+ });
12
37
  };
13
- const getTextFromFile = (file, encoding) => {
14
- return new Promise((resolve, reject) => {
15
- const reader = new FileReader();
16
- reader.readAsText(file, encoding);
17
- reader.onload = () => {
18
- resolve(reader.result.toString());
19
- };
20
- reader.onerror = (error) => {
21
- reject(error);
22
- };
23
- });
38
+ /**
39
+ * Reads a file as text using the provided encoding.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * const text = await getTextFromFile(file, 'utf-8');
44
+ * ```
45
+ */
46
+ var getTextFromFile = (file, encoding) => {
47
+ return new Promise((resolve, reject) => {
48
+ const reader = new FileReader();
49
+ reader.readAsText(file, encoding);
50
+ reader.onload = () => {
51
+ resolve(reader.result.toString());
52
+ };
53
+ reader.onerror = (error) => {
54
+ reject(error);
55
+ };
56
+ });
24
57
  };
25
- export {
26
- getBase64FromFile,
27
- getTextFromFile
28
- };
29
- //# sourceMappingURL=file.js.map
58
+ //#endregion
59
+ export { getBase64FromFile, getTextFromFile };
60
+
61
+ //# sourceMappingURL=file.js.map
package/file.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"file.js","sources":["../src/file.ts"],"sourcesContent":["export const getBase64FromFile = (file: File) => {\n return new Promise<string>((resolve, reject) => {\n const reader = new FileReader();\n reader.readAsDataURL(file);\n reader.onload = () => {\n resolve(reader.result!.toString());\n };\n reader.onerror = (error) => {\n reject(error);\n };\n });\n};\n\nexport const getTextFromFile = (file: File, encoding?: string) => {\n return new Promise<string>((resolve, reject) => {\n const reader = new FileReader();\n reader.readAsText(file, encoding);\n reader.onload = () => {\n resolve(reader.result!.toString());\n };\n reader.onerror = (error) => {\n reject(error);\n };\n });\n};\n"],"names":[],"mappings":"AAAO,MAAM,oBAAoB,CAAC,SAAe;AAC/C,SAAO,IAAI,QAAgB,CAAC,SAAS,WAAW;AAC9C,UAAM,SAAS,IAAI,WAAA;AACnB,WAAO,cAAc,IAAI;AACzB,WAAO,SAAS,MAAM;AACpB,cAAQ,OAAO,OAAQ,UAAU;AAAA,IACnC;AACA,WAAO,UAAU,CAAC,UAAU;AAC1B,aAAO,KAAK;AAAA,IACd;AAAA,EACF,CAAC;AACH;AAEO,MAAM,kBAAkB,CAAC,MAAY,aAAsB;AAChE,SAAO,IAAI,QAAgB,CAAC,SAAS,WAAW;AAC9C,UAAM,SAAS,IAAI,WAAA;AACnB,WAAO,WAAW,MAAM,QAAQ;AAChC,WAAO,SAAS,MAAM;AACpB,cAAQ,OAAO,OAAQ,UAAU;AAAA,IACnC;AACA,WAAO,UAAU,CAAC,UAAU;AAC1B,aAAO,KAAK;AAAA,IACd;AAAA,EACF,CAAC;AACH;"}
1
+ {"version":3,"file":"file.js","names":[],"sources":["../src/file.ts"],"sourcesContent":["/**\n * ---header-docs-section---\n * # yummies/file\n *\n * ## Description\n *\n * Browser `File` helpers: reading contents as Base64 data URLs or plain text with optional\n * encoding. They wrap `FileReader` in promises so async flows stay linear and errors surface as\n * rejections. Handy for uploads, import wizards, and client-side parsing without extra libraries.\n *\n * ## Usage\n *\n * ```ts\n * import { getBase64FromFile } from \"yummies/file\";\n * ```\n */\n\n/**\n * Reads a file as a Base64 data URL.\n *\n * @example\n * ```ts\n * const value = await getBase64FromFile(file);\n * ```\n */\nexport const getBase64FromFile = (file: File) => {\n return new Promise<string>((resolve, reject) => {\n const reader = new FileReader();\n reader.readAsDataURL(file);\n reader.onload = () => {\n resolve(reader.result!.toString());\n };\n reader.onerror = (error) => {\n reject(error);\n };\n });\n};\n\n/**\n * Reads a file as text using the provided encoding.\n *\n * @example\n * ```ts\n * const text = await getTextFromFile(file, 'utf-8');\n * ```\n */\nexport const getTextFromFile = (file: File, encoding?: string) => {\n return new Promise<string>((resolve, reject) => {\n const reader = new FileReader();\n reader.readAsText(file, encoding);\n reader.onload = () => {\n resolve(reader.result!.toString());\n };\n reader.onerror = (error) => {\n reject(error);\n };\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,IAAa,qBAAqB,SAAe;AAC/C,QAAO,IAAI,SAAiB,SAAS,WAAW;EAC9C,MAAM,SAAS,IAAI,YAAY;AAC/B,SAAO,cAAc,KAAK;AAC1B,SAAO,eAAe;AACpB,WAAQ,OAAO,OAAQ,UAAU,CAAC;;AAEpC,SAAO,WAAW,UAAU;AAC1B,UAAO,MAAM;;GAEf;;;;;;;;;;AAWJ,IAAa,mBAAmB,MAAY,aAAsB;AAChE,QAAO,IAAI,SAAiB,SAAS,WAAW;EAC9C,MAAM,SAAS,IAAI,YAAY;AAC/B,SAAO,WAAW,MAAM,SAAS;AACjC,SAAO,eAAe;AACpB,WAAQ,OAAO,OAAQ,UAAU,CAAC;;AAEpC,SAAO,WAAW,UAAU;AAC1B,UAAO,MAAM;;GAEf"}
package/format.cjs CHANGED
@@ -1,87 +1,129 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const parser = require("yummies/parser");
4
- const typeGuard = require("yummies/type-guard");
5
- const NO_VALUE = "";
6
- const HYPHEN = "-";
7
- const INFINITY = "∞";
8
- const number = (rawValue, userSettings) => {
9
- const settings = {
10
- ...number.defaultSettings,
11
- ...userSettings
12
- };
13
- const digits = settings.digits ?? 0;
14
- const cutZeros = settings?.cutZeros ?? false;
15
- const delimiter = settings.delimiter ?? " ";
16
- const postfix = settings.postfix ?? "";
17
- const emptyText = settings.emptyText ?? NO_VALUE;
18
- const digitsOnlyForFloat = settings.digitsOnlyForFloat ?? true;
19
- let value;
20
- if (typeGuard.typeGuard.isString(rawValue)) {
21
- value = parser.parser.number(value, { fallback: void 0 });
22
- } else {
23
- value = rawValue;
24
- }
25
- if (typeGuard.typeGuard.isNumber(value)) {
26
- let raw = `${value}`;
27
- if (digits !== false) {
28
- if (settings.cropDigitsOnly) {
29
- const [integerPart2, decimalPart2] = `${raw}`.split(".");
30
- const leftPart = integerPart2;
31
- const rightPart = (decimalPart2 || "").slice(0, digits).padEnd(digits, "0");
32
- if (rightPart) {
33
- raw = `${leftPart}.${rightPart}`;
34
- } else {
35
- raw = leftPart;
36
- }
37
- } else {
38
- raw = value.toFixed(digits);
39
- }
40
- }
41
- if (cutZeros) {
42
- raw = `${+raw}`;
43
- }
44
- const [integerPart, decimalPart] = raw.split(".", 2);
45
- let formattedIntegerPart = integerPart;
46
- let formattedDecimalPart = "";
47
- if (decimalPart && (!digitsOnlyForFloat || !/^0+$/.test(decimalPart))) {
48
- formattedDecimalPart = `.${decimalPart}`;
49
- }
50
- const rgx = /(\d+)(\d{3})/;
51
- while (rgx.test(formattedIntegerPart) && delimiter) {
52
- formattedIntegerPart = formattedIntegerPart.replace(
53
- rgx,
54
- `$1${delimiter}$2`
55
- );
56
- }
57
- return formattedIntegerPart + formattedDecimalPart + postfix;
58
- }
59
- return emptyText;
2
+ const require_chunk = require("./chunk-CVq3Gv4J.cjs");
3
+ let yummies_parser = require("yummies/parser");
4
+ let yummies_type_guard = require("yummies/type-guard");
5
+ //#region src/format/number.ts
6
+ /**
7
+ * Formats a numeric value with thousands separators, fractional digit control
8
+ * and optional postfix text.
9
+ *
10
+ * Invalid, empty or unsupported values fall back to `emptyText`.
11
+ *
12
+ * @param rawValue Number or numeric string to format.
13
+ * @param userSettings Formatting overrides merged with `number.defaultSettings`.
14
+ * @returns Formatted number string or fallback text.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * number(12000); // '12 000'
19
+ * ```
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * number(12.5, { digits: 1, postfix: '%' }); // '12.5%'
24
+ * ```
25
+ */
26
+ var number = (rawValue, userSettings) => {
27
+ const settings = {
28
+ ...number.defaultSettings,
29
+ ...userSettings
30
+ };
31
+ const digits = settings.digits ?? 0;
32
+ const cutZeros = settings?.cutZeros ?? false;
33
+ const delimiter = settings.delimiter ?? " ";
34
+ const postfix = settings.postfix ?? "";
35
+ const emptyText = settings.emptyText ?? "–";
36
+ const digitsOnlyForFloat = settings.digitsOnlyForFloat ?? true;
37
+ let value;
38
+ if (yummies_type_guard.typeGuard.isString(rawValue)) value = yummies_parser.parser.number(value, { fallback: void 0 });
39
+ else value = rawValue;
40
+ if (yummies_type_guard.typeGuard.isNumber(value)) {
41
+ let raw = `${value}`;
42
+ if (digits !== false) if (settings.cropDigitsOnly) {
43
+ const [integerPart, decimalPart] = `${raw}`.split(".");
44
+ const leftPart = integerPart;
45
+ const rightPart = (decimalPart || "").slice(0, digits).padEnd(digits, "0");
46
+ if (rightPart) raw = `${leftPart}.${rightPart}`;
47
+ else raw = leftPart;
48
+ } else raw = value.toFixed(digits);
49
+ if (cutZeros) raw = `${+raw}`;
50
+ const [integerPart, decimalPart] = raw.split(".", 2);
51
+ let formattedIntegerPart = integerPart;
52
+ let formattedDecimalPart = "";
53
+ if (decimalPart && (!digitsOnlyForFloat || !/^0+$/.test(decimalPart))) formattedDecimalPart = `.${decimalPart}`;
54
+ const rgx = /(\d+)(\d{3})/;
55
+ while (rgx.test(formattedIntegerPart) && delimiter) formattedIntegerPart = formattedIntegerPart.replace(rgx, `$1${delimiter}$2`);
56
+ return formattedIntegerPart + formattedDecimalPart + postfix;
57
+ }
58
+ return emptyText;
60
59
  };
61
60
  number.defaultSettings = {};
62
- const percent = (value, settings) => {
63
- const numericValue = parser.parser.number(value, {
64
- ...settings,
65
- digits: settings?.digits ?? 2,
66
- fallback: Number.NaN
67
- });
68
- if (typeGuard.typeGuard.isNumber(numericValue)) {
69
- const divider = settings?.divider ?? ".";
70
- const formattedPercent = divider === "." ? numericValue : `${numericValue}`.replace(".", divider);
71
- return `${formattedPercent}${settings?.delimiter ?? ""}${settings?.symbol ?? "%"}`;
72
- } else {
73
- return settings?.emptyText ?? NO_VALUE;
74
- }
61
+ //#endregion
62
+ //#region src/format/percent.ts
63
+ /**
64
+ * Formats a value as a percent string with configurable decimal precision,
65
+ * decimal divider and suffix symbol.
66
+ *
67
+ * @param value Number or numeric string to format.
68
+ * @param settings Parser and formatting options.
69
+ * @returns Formatted percent string or fallback text for invalid values.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * percent(12.345); // '12.35%'
74
+ * ```
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * percent(12.345, { divider: ',', symbol: ' pct' }); // '12,35 pct'
79
+ * ```
80
+ */
81
+ var percent = (value, settings) => {
82
+ const numericValue = yummies_parser.parser.number(value, {
83
+ ...settings,
84
+ digits: settings?.digits ?? 2,
85
+ fallback: NaN
86
+ });
87
+ if (yummies_type_guard.typeGuard.isNumber(numericValue)) {
88
+ const divider = settings?.divider ?? ".";
89
+ return `${divider === "." ? numericValue : `${numericValue}`.replace(".", divider)}${settings?.delimiter ?? ""}${settings?.symbol ?? "%"}`;
90
+ } else return settings?.emptyText ?? "–";
75
91
  };
76
- const skipSpaces = (value) => value.replaceAll(/\s/g, "");
77
- const _exports = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
78
- __proto__: null,
79
- HYPHEN,
80
- INFINITY,
81
- NO_VALUE,
82
- number,
83
- percent,
84
- skipSpaces
85
- }, Symbol.toStringTag, { value: "Module" }));
86
- exports.format = _exports;
87
- //# sourceMappingURL=format.cjs.map
92
+ //#endregion
93
+ //#region src/format/skip-spaces.ts
94
+ /**
95
+ * Removes all whitespace characters from a string.
96
+ *
97
+ * @param value Source string.
98
+ * @returns String without spaces, tabs and line breaks.
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * skipSpaces('1 000 000'); // '1000000'
103
+ * ```
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * skipSpaces('a\tb\nc'); // 'abc'
108
+ * ```
109
+ */
110
+ var skipSpaces = (value) => value.replaceAll(/\s/g, "");
111
+ //#endregion
112
+ //#region src/format/_exports.ts
113
+ var _exports_exports = /* @__PURE__ */ require_chunk.__exportAll({
114
+ HYPHEN: () => "-",
115
+ INFINITY: () => "∞",
116
+ NO_VALUE: () => "–",
117
+ number: () => number,
118
+ percent: () => percent,
119
+ skipSpaces: () => skipSpaces
120
+ });
121
+ //#endregion
122
+ Object.defineProperty(exports, "format", {
123
+ enumerable: true,
124
+ get: function() {
125
+ return _exports_exports;
126
+ }
127
+ });
128
+
129
+ //# sourceMappingURL=format.cjs.map
package/format.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"format.cjs","sources":["../src/format/constants.ts","../src/format/number.ts","../src/format/percent.ts","../src/format/skip-spaces.ts"],"sourcesContent":["/**\n * Placeholder shown when a formatter cannot produce a meaningful value.\n *\n * @example\n * ```ts\n * const fallback = NO_VALUE;\n * ```\n *\n * @example\n * ```ts\n * format.number(null, { emptyText: NO_VALUE });\n * ```\n */\nexport const NO_VALUE = '–'; // en-dash\n\n/**\n * Plain ASCII hyphen character.\n *\n * @example\n * ```ts\n * const separator = HYPHEN;\n * ```\n *\n * @example\n * ```ts\n * `foo${HYPHEN}bar`;\n * ```\n */\nexport const HYPHEN = '-';\n\n/**\n * Infinity symbol used by numeric formatters and UI output.\n *\n * @example\n * ```ts\n * const label = INFINITY;\n * ```\n *\n * @example\n * ```ts\n * `${INFINITY} items`;\n * ```\n */\nexport const INFINITY = '∞';\n","import { parser } from 'yummies/parser';\nimport { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\nimport { NO_VALUE } from './constants.js';\n\nexport interface NumberFormatSettings {\n delimiter?: string;\n /**\n * digitsOnlyForFloat - Show digits after decimal point only if they are not zeros after converting to number.\n * Example: \"0.00\" -> \"0\", \"0.10\" -> \"0.1\", but \"0.003\" -> \"0.003\"\n *\n * @default true\n */\n digitsOnlyForFloat?: boolean;\n /**\n * Text which will be returned if the value is undefined, null, NaN, Infinity or empty string.\n * Example: \"–\" will be returned if the value is undefined and emptyText is \"–\".\n */\n emptyText?: string;\n /**\n * Text to append to the end of the formatted number.\n * Example: if value is 1000 and postfix is \"₽\", result will be \"1 000₽\".\n */\n postfix?: string;\n /**\n * Fixed number of digits after the decimal point (number.toFixed() method)\n * If set to false, the truncation is ignored!\n */\n digits?: number | false;\n /**\n * Remove trailing zeros from the end of the number\n * Example: 0.010000000000000000000000000000000000000000000 -> 0.01\n */\n cutZeros?: boolean;\n cropDigitsOnly?: boolean;\n}\n\n/**\n * Formats a numeric value with thousands separators, fractional digit control\n * and optional postfix text.\n *\n * Invalid, empty or unsupported values fall back to `emptyText`.\n *\n * @param rawValue Number or numeric string to format.\n * @param userSettings Formatting overrides merged with `number.defaultSettings`.\n * @returns Formatted number string or fallback text.\n *\n * @example\n * ```ts\n * number(12000); // '12 000'\n * ```\n *\n * @example\n * ```ts\n * number(12.5, { digits: 1, postfix: '%' }); // '12.5%'\n * ```\n */\nexport const number = (\n rawValue: Maybe<string | number>,\n userSettings?: Maybe<NumberFormatSettings>,\n): string => {\n const settings = {\n ...number.defaultSettings,\n ...userSettings,\n };\n\n const digits = settings.digits ?? 0;\n const cutZeros = settings?.cutZeros ?? false;\n const delimiter = settings.delimiter ?? ' ';\n const postfix = settings.postfix ?? '';\n const emptyText = settings.emptyText ?? NO_VALUE;\n const digitsOnlyForFloat = settings.digitsOnlyForFloat ?? true;\n\n let value: Maybe<number>;\n\n if (typeGuard.isString(rawValue)) {\n value = parser.number(value, { fallback: undefined });\n } else {\n value = rawValue;\n }\n\n if (typeGuard.isNumber(value)) {\n let raw: string = `${value}`;\n\n if (digits !== false) {\n if (settings.cropDigitsOnly) {\n const [integerPart, decimalPart] = `${raw}`.split('.');\n const leftPart = integerPart;\n const rightPart = (decimalPart || '')\n .slice(0, digits)\n .padEnd(digits, '0');\n\n if (rightPart) {\n raw = `${leftPart}.${rightPart}`;\n } else {\n raw = leftPart;\n }\n } else {\n raw = value.toFixed(digits);\n }\n }\n\n if (cutZeros) {\n raw = `${+raw}`;\n }\n\n const [integerPart, decimalPart] = raw.split('.', 2);\n\n let formattedIntegerPart = integerPart;\n let formattedDecimalPart = '';\n\n if (decimalPart && (!digitsOnlyForFloat || !/^0+$/.test(decimalPart))) {\n formattedDecimalPart = `.${decimalPart}`;\n }\n\n const rgx = /(\\d+)(\\d{3})/;\n\n while (rgx.test(formattedIntegerPart) && delimiter) {\n formattedIntegerPart = formattedIntegerPart.replace(\n rgx,\n `$1${delimiter}$2`,\n );\n }\n\n return formattedIntegerPart + formattedDecimalPart + postfix;\n }\n\n return emptyText;\n};\n\nnumber.defaultSettings = {} as NumberFormatSettings;\n","import { parser } from 'yummies/parser';\nimport { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\n\nimport { NO_VALUE } from './constants.js';\n\nexport interface PercentFormatSettings\n extends Omit<parser.NumberParserSettings, 'fallback'> {\n divider?: string;\n delimiter?: string;\n symbol?: string;\n emptyText?: string;\n}\n\n/**\n * Formats a value as a percent string with configurable decimal precision,\n * decimal divider and suffix symbol.\n *\n * @param value Number or numeric string to format.\n * @param settings Parser and formatting options.\n * @returns Formatted percent string or fallback text for invalid values.\n *\n * @example\n * ```ts\n * percent(12.345); // '12.35%'\n * ```\n *\n * @example\n * ```ts\n * percent(12.345, { divider: ',', symbol: ' pct' }); // '12,35 pct'\n * ```\n */\nexport const percent = (\n value: Maybe<number | string>,\n settings?: PercentFormatSettings,\n) => {\n const numericValue = parser.number(value, {\n ...settings,\n digits: settings?.digits ?? 2,\n fallback: Number.NaN,\n });\n\n if (typeGuard.isNumber(numericValue)) {\n const divider = settings?.divider ?? '.';\n\n const formattedPercent =\n divider === '.' ? numericValue : `${numericValue}`.replace('.', divider);\n\n return `${formattedPercent}${settings?.delimiter ?? ''}${settings?.symbol ?? '%'}`;\n } else {\n return settings?.emptyText ?? NO_VALUE;\n }\n};\n","/**\n * Removes all whitespace characters from a string.\n *\n * @param value Source string.\n * @returns String without spaces, tabs and line breaks.\n *\n * @example\n * ```ts\n * skipSpaces('1 000 000'); // '1000000'\n * ```\n *\n * @example\n * ```ts\n * skipSpaces('a\\tb\\nc'); // 'abc'\n * ```\n */\nexport const skipSpaces = (value: string) => value.replaceAll(/\\s/g, '');\n"],"names":["typeGuard","parser","integerPart","decimalPart"],"mappings":";;;;AAaO,MAAM,WAAW;AAejB,MAAM,SAAS;AAef,MAAM,WAAW;ACcjB,MAAM,SAAS,CACpB,UACA,iBACW;AACX,QAAM,WAAW;AAAA,IACf,GAAG,OAAO;AAAA,IACV,GAAG;AAAA,EAAA;AAGL,QAAM,SAAS,SAAS,UAAU;AAClC,QAAM,WAAW,UAAU,YAAY;AACvC,QAAM,YAAY,SAAS,aAAa;AACxC,QAAM,UAAU,SAAS,WAAW;AACpC,QAAM,YAAY,SAAS,aAAa;AACxC,QAAM,qBAAqB,SAAS,sBAAsB;AAE1D,MAAI;AAEJ,MAAIA,UAAAA,UAAU,SAAS,QAAQ,GAAG;AAChC,YAAQC,OAAAA,OAAO,OAAO,OAAO,EAAE,UAAU,QAAW;AAAA,EACtD,OAAO;AACL,YAAQ;AAAA,EACV;AAEA,MAAID,UAAAA,UAAU,SAAS,KAAK,GAAG;AAC7B,QAAI,MAAc,GAAG,KAAK;AAE1B,QAAI,WAAW,OAAO;AACpB,UAAI,SAAS,gBAAgB;AAC3B,cAAM,CAACE,cAAaC,YAAW,IAAI,GAAG,GAAG,GAAG,MAAM,GAAG;AACrD,cAAM,WAAWD;AACjB,cAAM,aAAaC,gBAAe,IAC/B,MAAM,GAAG,MAAM,EACf,OAAO,QAAQ,GAAG;AAErB,YAAI,WAAW;AACb,gBAAM,GAAG,QAAQ,IAAI,SAAS;AAAA,QAChC,OAAO;AACL,gBAAM;AAAA,QACR;AAAA,MACF,OAAO;AACL,cAAM,MAAM,QAAQ,MAAM;AAAA,MAC5B;AAAA,IACF;AAEA,QAAI,UAAU;AACZ,YAAM,GAAG,CAAC,GAAG;AAAA,IACf;AAEA,UAAM,CAAC,aAAa,WAAW,IAAI,IAAI,MAAM,KAAK,CAAC;AAEnD,QAAI,uBAAuB;AAC3B,QAAI,uBAAuB;AAE3B,QAAI,gBAAgB,CAAC,sBAAsB,CAAC,OAAO,KAAK,WAAW,IAAI;AACrE,6BAAuB,IAAI,WAAW;AAAA,IACxC;AAEA,UAAM,MAAM;AAEZ,WAAO,IAAI,KAAK,oBAAoB,KAAK,WAAW;AAClD,6BAAuB,qBAAqB;AAAA,QAC1C;AAAA,QACA,KAAK,SAAS;AAAA,MAAA;AAAA,IAElB;AAEA,WAAO,uBAAuB,uBAAuB;AAAA,EACvD;AAEA,SAAO;AACT;AAEA,OAAO,kBAAkB,CAAA;AClGlB,MAAM,UAAU,CACrB,OACA,aACG;AACH,QAAM,eAAeF,OAAAA,OAAO,OAAO,OAAO;AAAA,IACxC,GAAG;AAAA,IACH,QAAQ,UAAU,UAAU;AAAA,IAC5B,UAAU,OAAO;AAAA,EAAA,CAClB;AAED,MAAID,UAAAA,UAAU,SAAS,YAAY,GAAG;AACpC,UAAM,UAAU,UAAU,WAAW;AAErC,UAAM,mBACJ,YAAY,MAAM,eAAe,GAAG,YAAY,GAAG,QAAQ,KAAK,OAAO;AAEzE,WAAO,GAAG,gBAAgB,GAAG,UAAU,aAAa,EAAE,GAAG,UAAU,UAAU,GAAG;AAAA,EAClF,OAAO;AACL,WAAO,UAAU,aAAa;AAAA,EAChC;AACF;ACpCO,MAAM,aAAa,CAAC,UAAkB,MAAM,WAAW,OAAO,EAAE;;;;;;;;;;;"}
1
+ {"version":3,"file":"format.cjs","names":[],"sources":["../src/format/number.ts","../src/format/percent.ts","../src/format/skip-spaces.ts","../src/format/_exports.ts"],"sourcesContent":["import { parser } from 'yummies/parser';\nimport { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\nimport { NO_VALUE } from './constants.js';\n\nexport interface NumberFormatSettings {\n delimiter?: string;\n /**\n * digitsOnlyForFloat - Show digits after decimal point only if they are not zeros after converting to number.\n * Example: \"0.00\" -> \"0\", \"0.10\" -> \"0.1\", but \"0.003\" -> \"0.003\"\n *\n * @default true\n */\n digitsOnlyForFloat?: boolean;\n /**\n * Text which will be returned if the value is undefined, null, NaN, Infinity or empty string.\n * Example: \"–\" will be returned if the value is undefined and emptyText is \"–\".\n */\n emptyText?: string;\n /**\n * Text to append to the end of the formatted number.\n * Example: if value is 1000 and postfix is \"₽\", result will be \"1 000₽\".\n */\n postfix?: string;\n /**\n * Fixed number of digits after the decimal point (number.toFixed() method)\n * If set to false, the truncation is ignored!\n */\n digits?: number | false;\n /**\n * Remove trailing zeros from the end of the number\n * Example: 0.010000000000000000000000000000000000000000000 -> 0.01\n */\n cutZeros?: boolean;\n cropDigitsOnly?: boolean;\n}\n\n/**\n * Formats a numeric value with thousands separators, fractional digit control\n * and optional postfix text.\n *\n * Invalid, empty or unsupported values fall back to `emptyText`.\n *\n * @param rawValue Number or numeric string to format.\n * @param userSettings Formatting overrides merged with `number.defaultSettings`.\n * @returns Formatted number string or fallback text.\n *\n * @example\n * ```ts\n * number(12000); // '12 000'\n * ```\n *\n * @example\n * ```ts\n * number(12.5, { digits: 1, postfix: '%' }); // '12.5%'\n * ```\n */\nexport const number = (\n rawValue: Maybe<string | number>,\n userSettings?: Maybe<NumberFormatSettings>,\n): string => {\n const settings = {\n ...number.defaultSettings,\n ...userSettings,\n };\n\n const digits = settings.digits ?? 0;\n const cutZeros = settings?.cutZeros ?? false;\n const delimiter = settings.delimiter ?? ' ';\n const postfix = settings.postfix ?? '';\n const emptyText = settings.emptyText ?? NO_VALUE;\n const digitsOnlyForFloat = settings.digitsOnlyForFloat ?? true;\n\n let value: Maybe<number>;\n\n if (typeGuard.isString(rawValue)) {\n value = parser.number(value, { fallback: undefined });\n } else {\n value = rawValue;\n }\n\n if (typeGuard.isNumber(value)) {\n let raw: string = `${value}`;\n\n if (digits !== false) {\n if (settings.cropDigitsOnly) {\n const [integerPart, decimalPart] = `${raw}`.split('.');\n const leftPart = integerPart;\n const rightPart = (decimalPart || '')\n .slice(0, digits)\n .padEnd(digits, '0');\n\n if (rightPart) {\n raw = `${leftPart}.${rightPart}`;\n } else {\n raw = leftPart;\n }\n } else {\n raw = value.toFixed(digits);\n }\n }\n\n if (cutZeros) {\n raw = `${+raw}`;\n }\n\n const [integerPart, decimalPart] = raw.split('.', 2);\n\n let formattedIntegerPart = integerPart;\n let formattedDecimalPart = '';\n\n if (decimalPart && (!digitsOnlyForFloat || !/^0+$/.test(decimalPart))) {\n formattedDecimalPart = `.${decimalPart}`;\n }\n\n const rgx = /(\\d+)(\\d{3})/;\n\n while (rgx.test(formattedIntegerPart) && delimiter) {\n formattedIntegerPart = formattedIntegerPart.replace(\n rgx,\n `$1${delimiter}$2`,\n );\n }\n\n return formattedIntegerPart + formattedDecimalPart + postfix;\n }\n\n return emptyText;\n};\n\nnumber.defaultSettings = {} as NumberFormatSettings;\n","import { parser } from 'yummies/parser';\nimport { typeGuard } from 'yummies/type-guard';\nimport type { Maybe } from 'yummies/types';\n\nimport { NO_VALUE } from './constants.js';\n\nexport interface PercentFormatSettings\n extends Omit<parser.NumberParserSettings, 'fallback'> {\n divider?: string;\n delimiter?: string;\n symbol?: string;\n emptyText?: string;\n}\n\n/**\n * Formats a value as a percent string with configurable decimal precision,\n * decimal divider and suffix symbol.\n *\n * @param value Number or numeric string to format.\n * @param settings Parser and formatting options.\n * @returns Formatted percent string or fallback text for invalid values.\n *\n * @example\n * ```ts\n * percent(12.345); // '12.35%'\n * ```\n *\n * @example\n * ```ts\n * percent(12.345, { divider: ',', symbol: ' pct' }); // '12,35 pct'\n * ```\n */\nexport const percent = (\n value: Maybe<number | string>,\n settings?: PercentFormatSettings,\n) => {\n const numericValue = parser.number(value, {\n ...settings,\n digits: settings?.digits ?? 2,\n fallback: Number.NaN,\n });\n\n if (typeGuard.isNumber(numericValue)) {\n const divider = settings?.divider ?? '.';\n\n const formattedPercent =\n divider === '.' ? numericValue : `${numericValue}`.replace('.', divider);\n\n return `${formattedPercent}${settings?.delimiter ?? ''}${settings?.symbol ?? '%'}`;\n } else {\n return settings?.emptyText ?? NO_VALUE;\n }\n};\n","/**\n * Removes all whitespace characters from a string.\n *\n * @param value Source string.\n * @returns String without spaces, tabs and line breaks.\n *\n * @example\n * ```ts\n * skipSpaces('1 000 000'); // '1000000'\n * ```\n *\n * @example\n * ```ts\n * skipSpaces('a\\tb\\nc'); // 'abc'\n * ```\n */\nexport const skipSpaces = (value: string) => value.replaceAll(/\\s/g, '');\n","/**\n * ---header-docs-section---\n * # yummies/format\n *\n * ## Description\n *\n * Namespace-style **number, percent, and string** formatting for UI tables, inputs, and charts.\n * Submodules cover locale-aware numbers, percent parsing/formatting, trimming helpers, and shared\n * constants so presentation rules stay centralized and tree-shakable behind the package\n * aggregated **format** export from this entry point.\n *\n * ## Usage\n *\n * ```ts\n * import { format } from \"yummies/format\";\n * ```\n */\n\nexport * from './constants.js';\nexport * from './number.js';\nexport * from './percent.js';\nexport * from './skip-spaces.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,IAAa,UACX,UACA,iBACW;CACX,MAAM,WAAW;EACf,GAAG,OAAO;EACV,GAAG;EACJ;CAED,MAAM,SAAS,SAAS,UAAU;CAClC,MAAM,WAAW,UAAU,YAAY;CACvC,MAAM,YAAY,SAAS,aAAa;CACxC,MAAM,UAAU,SAAS,WAAW;CACpC,MAAM,YAAY,SAAS,aAAA;CAC3B,MAAM,qBAAqB,SAAS,sBAAsB;CAE1D,IAAI;AAEJ,KAAI,mBAAA,UAAU,SAAS,SAAS,CAC9B,SAAQ,eAAA,OAAO,OAAO,OAAO,EAAE,UAAU,KAAA,GAAW,CAAC;KAErD,SAAQ;AAGV,KAAI,mBAAA,UAAU,SAAS,MAAM,EAAE;EAC7B,IAAI,MAAc,GAAG;AAErB,MAAI,WAAW,MACb,KAAI,SAAS,gBAAgB;GAC3B,MAAM,CAAC,aAAa,eAAe,GAAG,MAAM,MAAM,IAAI;GACtD,MAAM,WAAW;GACjB,MAAM,aAAa,eAAe,IAC/B,MAAM,GAAG,OAAO,CAChB,OAAO,QAAQ,IAAI;AAEtB,OAAI,UACF,OAAM,GAAG,SAAS,GAAG;OAErB,OAAM;QAGR,OAAM,MAAM,QAAQ,OAAO;AAI/B,MAAI,SACF,OAAM,GAAG,CAAC;EAGZ,MAAM,CAAC,aAAa,eAAe,IAAI,MAAM,KAAK,EAAE;EAEpD,IAAI,uBAAuB;EAC3B,IAAI,uBAAuB;AAE3B,MAAI,gBAAgB,CAAC,sBAAsB,CAAC,OAAO,KAAK,YAAY,EAClE,wBAAuB,IAAI;EAG7B,MAAM,MAAM;AAEZ,SAAO,IAAI,KAAK,qBAAqB,IAAI,UACvC,wBAAuB,qBAAqB,QAC1C,KACA,KAAK,UAAU,IAChB;AAGH,SAAO,uBAAuB,uBAAuB;;AAGvD,QAAO;;AAGT,OAAO,kBAAkB,EAAE;;;;;;;;;;;;;;;;;;;;;AClG3B,IAAa,WACX,OACA,aACG;CACH,MAAM,eAAe,eAAA,OAAO,OAAO,OAAO;EACxC,GAAG;EACH,QAAQ,UAAU,UAAU;EAC5B,UAAU;EACX,CAAC;AAEF,KAAI,mBAAA,UAAU,SAAS,aAAa,EAAE;EACpC,MAAM,UAAU,UAAU,WAAW;AAKrC,SAAO,GAFL,YAAY,MAAM,eAAe,GAAG,eAAe,QAAQ,KAAK,QAAQ,GAE7C,UAAU,aAAa,KAAK,UAAU,UAAU;OAE7E,QAAO,UAAU,aAAA;;;;;;;;;;;;;;;;;;;;AClCrB,IAAa,cAAc,UAAkB,MAAM,WAAW,OAAO,GAAG"}
package/format.d.ts CHANGED
@@ -144,6 +144,24 @@ declare const percent: (value: Maybe<number | string>, settings?: PercentFormatS
144
144
  */
145
145
  declare const skipSpaces: (value: string) => string;
146
146
 
147
+ /**
148
+ * ---header-docs-section---
149
+ * # yummies/format
150
+ *
151
+ * ## Description
152
+ *
153
+ * Namespace-style **number, percent, and string** formatting for UI tables, inputs, and charts.
154
+ * Submodules cover locale-aware numbers, percent parsing/formatting, trimming helpers, and shared
155
+ * constants so presentation rules stay centralized and tree-shakable behind the package
156
+ * aggregated **format** export from this entry point.
157
+ *
158
+ * ## Usage
159
+ *
160
+ * ```ts
161
+ * import { format } from "yummies/format";
162
+ * ```
163
+ */
164
+
147
165
  declare const _exports_HYPHEN: typeof HYPHEN;
148
166
  declare const _exports_INFINITY: typeof INFINITY;
149
167
  declare const _exports_NO_VALUE: typeof NO_VALUE;