@bccampus/utils 0.2.2 → 0.3.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 (216) hide show
  1. package/README.md +3 -8
  2. package/dist/array/chunk.cjs +13 -5
  3. package/dist/array/chunk.d.ts +7 -0
  4. package/dist/array/chunk.js +14 -7
  5. package/dist/array/chunk.test.d.ts +1 -0
  6. package/dist/date/iso-date-time/constants.cjs +27 -0
  7. package/dist/date/iso-date-time/constants.d.ts +9 -0
  8. package/dist/date/iso-date-time/constants.js +19 -0
  9. package/dist/date/iso-date-time/index.cjs +8 -0
  10. package/dist/date/iso-date-time/index.d.ts +5 -0
  11. package/dist/date/iso-date-time/index.js +3 -0
  12. package/dist/date/iso-date-time/iso-date-time.arithmetic.test.d.ts +1 -0
  13. package/dist/date/iso-date-time/iso-date-time.cjs +232 -0
  14. package/dist/date/{iso-date-time.d.ts → iso-date-time/iso-date-time.d.ts} +3 -32
  15. package/dist/date/iso-date-time/iso-date-time.format.test.d.ts +1 -0
  16. package/dist/date/iso-date-time/iso-date-time.js +231 -0
  17. package/dist/date/iso-date-time/iso-date-time.test.d.ts +1 -0
  18. package/dist/date/iso-date-time/types.cjs +0 -0
  19. package/dist/date/iso-date-time/types.d.ts +25 -0
  20. package/dist/date/iso-date-time/types.js +0 -0
  21. package/dist/duration/add-durations.cjs +5 -8
  22. package/dist/duration/add-durations.js +5 -9
  23. package/dist/duration/duration.test.d.ts +1 -0
  24. package/dist/duration/is-duration.cjs +4 -3
  25. package/dist/duration/is-duration.js +5 -5
  26. package/dist/duration/to-number.cjs +11 -10
  27. package/dist/duration/to-number.d.ts +1 -1
  28. package/dist/duration/to-number.js +11 -11
  29. package/dist/format/formatter.cjs +31 -31
  30. package/dist/format/formatter.d.ts +4 -4
  31. package/dist/format/formatter.js +32 -37
  32. package/dist/format/formatter.test.d.ts +1 -0
  33. package/dist/format/stringfy.test.d.ts +1 -0
  34. package/dist/format/stringify.cjs +34 -40
  35. package/dist/format/stringify.d.ts +1 -1
  36. package/dist/format/stringify.js +35 -42
  37. package/dist/format/template.cjs +25 -32
  38. package/dist/format/template.d.ts +3 -3
  39. package/dist/format/template.js +24 -33
  40. package/dist/format/template.test.d.ts +1 -0
  41. package/dist/index.cjs +0 -4
  42. package/dist/index.d.ts +0 -1
  43. package/dist/index.js +0 -4
  44. package/dist/object/get.cjs +5 -5
  45. package/dist/object/get.d.ts +1 -1
  46. package/dist/object/get.js +6 -7
  47. package/dist/object/get.test.d.ts +1 -0
  48. package/dist/object/is-object.cjs +5 -2
  49. package/dist/object/is-object.d.ts +1 -1
  50. package/dist/object/is-object.js +6 -4
  51. package/dist/object/is-object.test.d.ts +1 -0
  52. package/dist/object/omit.cjs +14 -16
  53. package/dist/object/omit.d.ts +1 -1
  54. package/dist/object/omit.js +15 -18
  55. package/dist/object/omit.test.d.ts +1 -0
  56. package/dist/object/pick.cjs +10 -9
  57. package/dist/object/pick.d.ts +1 -1
  58. package/dist/object/pick.js +9 -9
  59. package/dist/object/pick.test.d.ts +1 -0
  60. package/dist/object/set.cjs +13 -12
  61. package/dist/object/set.d.ts +1 -1
  62. package/dist/object/set.js +14 -14
  63. package/dist/object/set.test.d.ts +1 -0
  64. package/dist/path/file-url-to-path.cjs +10 -6
  65. package/dist/path/file-url-to-path.js +11 -8
  66. package/dist/path/file-url-to-path.test.d.ts +1 -0
  67. package/dist/path/normalize.cjs +41 -27
  68. package/dist/path/normalize.d.ts +8 -2
  69. package/dist/path/normalize.js +41 -28
  70. package/dist/path/normalize.test.d.ts +1 -0
  71. package/dist/set/difference.cjs +5 -6
  72. package/dist/set/difference.d.ts +1 -1
  73. package/dist/set/difference.js +6 -8
  74. package/dist/set/intersection.cjs +6 -9
  75. package/dist/set/intersection.d.ts +1 -1
  76. package/dist/set/intersection.js +7 -11
  77. package/dist/set/is-superset.cjs +5 -8
  78. package/dist/set/is-superset.d.ts +1 -1
  79. package/dist/set/is-superset.js +6 -10
  80. package/dist/set/set.test.d.ts +1 -0
  81. package/dist/set/symmetric-difference.cjs +6 -10
  82. package/dist/set/symmetric-difference.d.ts +1 -1
  83. package/dist/set/symmetric-difference.js +7 -12
  84. package/dist/set/union.cjs +5 -6
  85. package/dist/set/union.d.ts +1 -1
  86. package/dist/set/union.js +6 -8
  87. package/dist/string/capitalize.cjs +5 -2
  88. package/dist/string/capitalize.d.ts +1 -1
  89. package/dist/string/capitalize.js +6 -4
  90. package/dist/string/capitalize.test.d.ts +1 -0
  91. package/dist/string/normalize.cjs +7 -2
  92. package/dist/string/normalize.js +8 -4
  93. package/dist/string/normalize.test.d.ts +1 -0
  94. package/dist/string/pluralize/index.cjs +5 -4
  95. package/dist/string/pluralize/index.js +4 -5
  96. package/dist/string/pluralize/pluralize.cjs +162 -208
  97. package/dist/string/pluralize/pluralize.d.ts +4 -8
  98. package/dist/string/pluralize/pluralize.js +158 -205
  99. package/dist/string/pluralize/pluralize.test.d.ts +1 -0
  100. package/dist/string/pluralize/rules/index.cjs +8 -9
  101. package/dist/string/pluralize/rules/index.js +1 -6
  102. package/dist/string/pluralize/rules/irregular.cjs +55 -59
  103. package/dist/string/pluralize/rules/irregular.js +56 -61
  104. package/dist/string/pluralize/rules/pluralization.cjs +28 -36
  105. package/dist/string/pluralize/rules/pluralization.js +29 -38
  106. package/dist/string/pluralize/rules/singularization.cjs +27 -44
  107. package/dist/string/pluralize/rules/singularization.js +28 -46
  108. package/dist/string/pluralize/rules/uncountable.cjs +104 -110
  109. package/dist/string/pluralize/rules/uncountable.js +105 -112
  110. package/dist/string/pluralize/types.cjs +0 -1
  111. package/dist/string/pluralize/types.js +0 -1
  112. package/dist/string/slugify/index.cjs +2129 -2246
  113. package/dist/string/slugify/index.js +2130 -2248
  114. package/dist/string/slugify/slugify.test.d.ts +1 -0
  115. package/dist/string/strip-html-tags.cjs +4 -3
  116. package/dist/string/strip-html-tags.js +5 -5
  117. package/dist/string/strip-html-tags.test.d.ts +1 -0
  118. package/dist/string/to-int.cjs +14 -6
  119. package/dist/string/to-int.js +15 -8
  120. package/dist/string/to-int.test.d.ts +1 -0
  121. package/dist/string/to-sentence-case.cjs +6 -6
  122. package/dist/string/to-sentence-case.d.ts +1 -1
  123. package/dist/string/to-sentence-case.js +7 -8
  124. package/dist/string/to-sentence-case.test.d.ts +1 -0
  125. package/dist/string/trim.cjs +8 -7
  126. package/dist/string/trim.js +9 -9
  127. package/dist/string/trim.test.d.ts +1 -0
  128. package/dist/string/truncate.cjs +16 -15
  129. package/dist/string/truncate.js +17 -17
  130. package/dist/string/truncate.test.d.ts +1 -0
  131. package/dist/value/is-empty.cjs +30 -12
  132. package/dist/value/is-empty.d.ts +1 -1
  133. package/dist/value/is-empty.js +31 -14
  134. package/dist/value/value.test.d.ts +1 -0
  135. package/package.json +183 -67
  136. package/dist/array/index.cjs +0 -4
  137. package/dist/array/index.d.ts +0 -1
  138. package/dist/array/index.js +0 -4
  139. package/dist/date/index.cjs +0 -8
  140. package/dist/date/index.d.ts +0 -1
  141. package/dist/date/index.js +0 -8
  142. package/dist/date/iso-date-time.cjs +0 -256
  143. package/dist/date/iso-date-time.js +0 -256
  144. package/dist/duration/index.cjs +0 -8
  145. package/dist/duration/index.d.ts +0 -3
  146. package/dist/duration/index.js +0 -8
  147. package/dist/format/index.cjs +0 -13
  148. package/dist/format/index.d.ts +0 -3
  149. package/dist/format/index.js +0 -13
  150. package/dist/object/index.cjs +0 -12
  151. package/dist/object/index.d.ts +0 -5
  152. package/dist/object/index.js +0 -12
  153. package/dist/path/index.cjs +0 -6
  154. package/dist/path/index.d.ts +0 -2
  155. package/dist/path/index.js +0 -6
  156. package/dist/set/index.cjs +0 -12
  157. package/dist/set/index.d.ts +0 -5
  158. package/dist/set/index.js +0 -12
  159. package/dist/string/index.cjs +0 -14
  160. package/dist/string/index.d.ts +0 -6
  161. package/dist/string/index.js +0 -14
  162. package/dist/value/index.cjs +0 -4
  163. package/dist/value/index.d.ts +0 -1
  164. package/dist/value/index.js +0 -4
  165. package/eslint.config.js +0 -19
  166. package/src/array/chunk.ts +0 -6
  167. package/src/array/index.ts +0 -1
  168. package/src/date/index.ts +0 -1
  169. package/src/date/iso-date-time.ts +0 -356
  170. package/src/duration/add-durations.ts +0 -16
  171. package/src/duration/index.ts +0 -3
  172. package/src/duration/is-duration.ts +0 -5
  173. package/src/duration/to-number.ts +0 -18
  174. package/src/format/formatter.ts +0 -37
  175. package/src/format/index.ts +0 -3
  176. package/src/format/stringify.ts +0 -87
  177. package/src/format/template.ts +0 -48
  178. package/src/index.ts +0 -1
  179. package/src/object/get.ts +0 -9
  180. package/src/object/index.ts +0 -5
  181. package/src/object/is-object.ts +0 -2
  182. package/src/object/omit.ts +0 -21
  183. package/src/object/pick.ts +0 -10
  184. package/src/object/set.ts +0 -15
  185. package/src/path/file-url-to-path.ts +0 -12
  186. package/src/path/index.ts +0 -2
  187. package/src/path/normalize.ts +0 -72
  188. package/src/set/difference.ts +0 -9
  189. package/src/set/index.ts +0 -5
  190. package/src/set/intersection.ts +0 -12
  191. package/src/set/is-superset.ts +0 -12
  192. package/src/set/symmetric-difference.ts +0 -12
  193. package/src/set/union.ts +0 -8
  194. package/src/string/capitalize.ts +0 -2
  195. package/src/string/index.ts +0 -6
  196. package/src/string/normalize.ts +0 -7
  197. package/src/string/pluralize/index.ts +0 -7
  198. package/src/string/pluralize/pluralize.ts +0 -296
  199. package/src/string/pluralize/rules/index.ts +0 -4
  200. package/src/string/pluralize/rules/irregular.ts +0 -59
  201. package/src/string/pluralize/rules/pluralization.ts +0 -40
  202. package/src/string/pluralize/rules/singularization.ts +0 -46
  203. package/src/string/pluralize/rules/uncountable.ts +0 -107
  204. package/src/string/pluralize/types.ts +0 -4
  205. package/src/string/slugify/index.ts +0 -3
  206. package/src/string/strip-html-tags.ts +0 -4
  207. package/src/string/to-int.ts +0 -20
  208. package/src/string/to-sentence-case.ts +0 -6
  209. package/src/string/trim.ts +0 -11
  210. package/src/string/truncate.ts +0 -44
  211. package/src/value/index.ts +0 -1
  212. package/src/value/is-empty.ts +0 -31
  213. package/tsconfig.json +0 -18
  214. package/tsconfig.lib.json +0 -37
  215. package/tsconfig.node.json +0 -25
  216. package/vite.config.ts +0 -76
@@ -0,0 +1,25 @@
1
+ import { InvalidDate } from '.';
2
+ export interface ISODateParts {
3
+ year: string;
4
+ month?: string;
5
+ day?: string;
6
+ }
7
+ export interface ISOTimeParts {
8
+ hours: string;
9
+ minutes?: string;
10
+ seconds?: string;
11
+ milliseconds?: string;
12
+ }
13
+ export type ISOTimezone = 'Z' | `${'+' | '-'}${string}`;
14
+ export interface ParsedDateTime {
15
+ date: ISODateParts;
16
+ time?: ISOTimeParts;
17
+ timezone?: ISOTimezone;
18
+ }
19
+ export type DateFormatOptions = Partial<Intl.DateTimeFormatOptions>;
20
+ export interface DateFormatterConfig {
21
+ noDate?: boolean;
22
+ noTime?: boolean;
23
+ customFormat?: DateFormatOptions;
24
+ }
25
+ export type InvalidDateSymbol = typeof InvalidDate;
File without changes
@@ -1,12 +1,9 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- require("./is-duration.cjs");
4
- const duration_toNumber = require("./to-number.cjs");
2
+ const require_duration_to_number = require("./to-number.cjs");
3
+ //#region src/duration/add-durations.ts
5
4
  function addDuration(left, right) {
6
- const totalDurationInSeconds = duration_toNumber.toNumber(left, "second") + duration_toNumber.toNumber(right, "second");
7
- const hours = Math.floor(totalDurationInSeconds / 3600).toString().padStart(2, "0");
8
- const minutes = Math.floor(totalDurationInSeconds % 3600 / 60).toString().padStart(2, "0");
9
- const seconds = (totalDurationInSeconds % 60).toString().padStart(2, "0");
10
- return `${hours}:${minutes}:${seconds}`;
5
+ const totalDurationInSeconds = require_duration_to_number.toNumber(left, "second") + require_duration_to_number.toNumber(right, "second");
6
+ return `${Math.floor(totalDurationInSeconds / 3600).toString().padStart(2, "0")}:${Math.floor(totalDurationInSeconds % 3600 / 60).toString().padStart(2, "0")}:${(totalDurationInSeconds % 60).toString().padStart(2, "0")}`;
11
7
  }
8
+ //#endregion
12
9
  exports.addDuration = addDuration;
@@ -1,12 +1,8 @@
1
- import "./is-duration.js";
2
1
  import { toNumber } from "./to-number.js";
2
+ //#region src/duration/add-durations.ts
3
3
  function addDuration(left, right) {
4
- const totalDurationInSeconds = toNumber(left, "second") + toNumber(right, "second");
5
- const hours = Math.floor(totalDurationInSeconds / 3600).toString().padStart(2, "0");
6
- const minutes = Math.floor(totalDurationInSeconds % 3600 / 60).toString().padStart(2, "0");
7
- const seconds = (totalDurationInSeconds % 60).toString().padStart(2, "0");
8
- return `${hours}:${minutes}:${seconds}`;
4
+ const totalDurationInSeconds = toNumber(left, "second") + toNumber(right, "second");
5
+ return `${Math.floor(totalDurationInSeconds / 3600).toString().padStart(2, "0")}:${Math.floor(totalDurationInSeconds % 3600 / 60).toString().padStart(2, "0")}:${(totalDurationInSeconds % 60).toString().padStart(2, "0")}`;
9
6
  }
10
- export {
11
- addDuration
12
- };
7
+ //#endregion
8
+ export { addDuration };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,7 +1,8 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const durationRegExp = /^\d{2}:\d{2}:\d{2}$/;
2
+ //#region src/duration/is-duration.ts
3
+ var durationRegExp = /^\d{2}:\d{2}:\d{2}$/;
4
4
  function isDuration(duration) {
5
- return durationRegExp.test(duration);
5
+ return durationRegExp.test(duration);
6
6
  }
7
+ //#endregion
7
8
  exports.isDuration = isDuration;
@@ -1,7 +1,7 @@
1
- const durationRegExp = /^\d{2}:\d{2}:\d{2}$/;
1
+ //#region src/duration/is-duration.ts
2
+ var durationRegExp = /^\d{2}:\d{2}:\d{2}$/;
2
3
  function isDuration(duration) {
3
- return durationRegExp.test(duration);
4
+ return durationRegExp.test(duration);
4
5
  }
5
- export {
6
- isDuration
7
- };
6
+ //#endregion
7
+ export { isDuration };
@@ -1,14 +1,15 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const duration_isDuration = require("./is-duration.cjs");
2
+ const require_duration_is_duration = require("./is-duration.cjs");
3
+ //#region src/duration/to-number.ts
4
4
  function toNumber(duration, unit = "hour") {
5
- if (!duration_isDuration.isDuration(duration)) {
6
- console.error(new Error(`Malformed duration value: ${duration}`));
7
- return 0;
8
- }
9
- const parts = duration.split(":").map((p) => Number(p));
10
- if (unit === "minute") return parts[0] * 60 + parts[1] + parts[2] / 60;
11
- if (unit === "second") return parts[0] * 3600 + parts[1] * 60 + parts[2];
12
- return parts[0] + parts[1] / 60 + parts[2] / 3600;
5
+ if (!require_duration_is_duration.isDuration(duration)) {
6
+ console.error(/* @__PURE__ */ new Error(`Malformed duration value: ${duration}`));
7
+ return 0;
8
+ }
9
+ const parts = duration.split(":").map((p) => Number(p));
10
+ if (unit === "minute") return parts[0] * 60 + parts[1] + parts[2] / 60;
11
+ if (unit === "second") return parts[0] * 3600 + parts[1] * 60 + parts[2];
12
+ return parts[0] + parts[1] / 60 + parts[2] / 3600;
13
13
  }
14
+ //#endregion
14
15
  exports.toNumber = toNumber;
@@ -1 +1 @@
1
- export declare function toNumber(duration: string, unit?: "hour" | "minute" | "second"): number;
1
+ export declare function toNumber(duration: string, unit?: 'hour' | 'minute' | 'second'): number;
@@ -1,14 +1,14 @@
1
1
  import { isDuration } from "./is-duration.js";
2
+ //#region src/duration/to-number.ts
2
3
  function toNumber(duration, unit = "hour") {
3
- if (!isDuration(duration)) {
4
- console.error(new Error(`Malformed duration value: ${duration}`));
5
- return 0;
6
- }
7
- const parts = duration.split(":").map((p) => Number(p));
8
- if (unit === "minute") return parts[0] * 60 + parts[1] + parts[2] / 60;
9
- if (unit === "second") return parts[0] * 3600 + parts[1] * 60 + parts[2];
10
- return parts[0] + parts[1] / 60 + parts[2] / 3600;
4
+ if (!isDuration(duration)) {
5
+ console.error(/* @__PURE__ */ new Error(`Malformed duration value: ${duration}`));
6
+ return 0;
7
+ }
8
+ const parts = duration.split(":").map((p) => Number(p));
9
+ if (unit === "minute") return parts[0] * 60 + parts[1] + parts[2] / 60;
10
+ if (unit === "second") return parts[0] * 3600 + parts[1] * 60 + parts[2];
11
+ return parts[0] + parts[1] / 60 + parts[2] / 3600;
11
12
  }
12
- export {
13
- toNumber
14
- };
13
+ //#endregion
14
+ export { toNumber };
@@ -1,38 +1,38 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const dateFormatter = new Intl.DateTimeFormat("en", {
4
- dateStyle: "full",
5
- timeStyle: "short",
6
- timeZone: "America/Vancouver"
2
+ //#region src/format/formatter.ts
3
+ var dateFormatter = new Intl.DateTimeFormat("en", {
4
+ dateStyle: "full",
5
+ timeStyle: "short",
6
+ timeZone: "America/Vancouver"
7
7
  });
8
- const formatDate = (date) => {
9
- if (date) return dateFormatter.format(date);
10
- return "";
11
- };
12
- const listFormatter = new Intl.ListFormat("en", {
13
- style: "long",
14
- type: "conjunction"
8
+ function formatDate(date) {
9
+ if (date) return dateFormatter.format(date).replace(/\s/g, " ");
10
+ return "";
11
+ }
12
+ var listFormatter = new Intl.ListFormat("en", {
13
+ style: "long",
14
+ type: "conjunction"
15
15
  });
16
- const formatList = (list) => {
17
- if (Array.isArray(list)) return listFormatter.format(list);
18
- return "";
19
- };
20
- const numberFormatter = new Intl.NumberFormat("en", {
21
- maximumFractionDigits: 2
16
+ function formatList(list) {
17
+ if (Array.isArray(list)) return listFormatter.format(list).replace(/\s/g, " ");
18
+ return "";
19
+ }
20
+ var numberFormatter = new Intl.NumberFormat("en", { maximumFractionDigits: 2 });
21
+ function formatNumber(num) {
22
+ if (num) return numberFormatter.format(num).replace(/\s/g, " ");
23
+ return "";
24
+ }
25
+ var currencyFormatter = new Intl.NumberFormat("en", {
26
+ style: "currency",
27
+ currency: "CAD",
28
+ maximumFractionDigits: 2,
29
+ currencyDisplay: "code"
22
30
  });
23
- const formatNumber = (num) => {
24
- if (num) return numberFormatter.format(num);
25
- return "";
26
- };
27
- const currencyFormatter = new Intl.NumberFormat("en", {
28
- style: "currency",
29
- currency: "CAD",
30
- maximumFractionDigits: 2
31
- });
32
- const formatCurrency = (num) => {
33
- if (num) return currencyFormatter.format(num);
34
- return "";
35
- };
31
+ function formatCurrency(num) {
32
+ if (num) return currencyFormatter.format(num).replace(/\s/g, " ");
33
+ return "";
34
+ }
35
+ //#endregion
36
36
  exports.dateFormatter = dateFormatter;
37
37
  exports.formatCurrency = formatCurrency;
38
38
  exports.formatDate = formatDate;
@@ -1,5 +1,5 @@
1
1
  export declare const dateFormatter: Intl.DateTimeFormat;
2
- export declare const formatDate: (date?: Date | null) => string;
3
- export declare const formatList: (list?: string[] | null) => string;
4
- export declare const formatNumber: (num?: number | null) => string;
5
- export declare const formatCurrency: (num?: number | null) => string;
2
+ export declare function formatDate(date?: Date | null): string;
3
+ export declare function formatList(list?: string[] | null): string;
4
+ export declare function formatNumber(num?: number | null): string;
5
+ export declare function formatCurrency(num?: number | null): string;
@@ -1,40 +1,35 @@
1
- const dateFormatter = new Intl.DateTimeFormat("en", {
2
- dateStyle: "full",
3
- timeStyle: "short",
4
- timeZone: "America/Vancouver"
1
+ //#region src/format/formatter.ts
2
+ var dateFormatter = new Intl.DateTimeFormat("en", {
3
+ dateStyle: "full",
4
+ timeStyle: "short",
5
+ timeZone: "America/Vancouver"
5
6
  });
6
- const formatDate = (date) => {
7
- if (date) return dateFormatter.format(date);
8
- return "";
9
- };
10
- const listFormatter = new Intl.ListFormat("en", {
11
- style: "long",
12
- type: "conjunction"
7
+ function formatDate(date) {
8
+ if (date) return dateFormatter.format(date).replace(/\s/g, " ");
9
+ return "";
10
+ }
11
+ var listFormatter = new Intl.ListFormat("en", {
12
+ style: "long",
13
+ type: "conjunction"
13
14
  });
14
- const formatList = (list) => {
15
- if (Array.isArray(list)) return listFormatter.format(list);
16
- return "";
17
- };
18
- const numberFormatter = new Intl.NumberFormat("en", {
19
- maximumFractionDigits: 2
15
+ function formatList(list) {
16
+ if (Array.isArray(list)) return listFormatter.format(list).replace(/\s/g, " ");
17
+ return "";
18
+ }
19
+ var numberFormatter = new Intl.NumberFormat("en", { maximumFractionDigits: 2 });
20
+ function formatNumber(num) {
21
+ if (num) return numberFormatter.format(num).replace(/\s/g, " ");
22
+ return "";
23
+ }
24
+ var currencyFormatter = new Intl.NumberFormat("en", {
25
+ style: "currency",
26
+ currency: "CAD",
27
+ maximumFractionDigits: 2,
28
+ currencyDisplay: "code"
20
29
  });
21
- const formatNumber = (num) => {
22
- if (num) return numberFormatter.format(num);
23
- return "";
24
- };
25
- const currencyFormatter = new Intl.NumberFormat("en", {
26
- style: "currency",
27
- currency: "CAD",
28
- maximumFractionDigits: 2
29
- });
30
- const formatCurrency = (num) => {
31
- if (num) return currencyFormatter.format(num);
32
- return "";
33
- };
34
- export {
35
- dateFormatter,
36
- formatCurrency,
37
- formatDate,
38
- formatList,
39
- formatNumber
40
- };
30
+ function formatCurrency(num) {
31
+ if (num) return currencyFormatter.format(num).replace(/\s/g, " ");
32
+ return "";
33
+ }
34
+ //#endregion
35
+ export { dateFormatter, formatCurrency, formatDate, formatList, formatNumber };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,42 +1,36 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const format_formatter = require("./formatter.cjs");
4
- const date_isoDateTime = require("../date/iso-date-time.cjs");
5
- const stringify = (value, options) => {
6
- const _options = {
7
- invalidValueString: "\0",
8
- // Unicode NUL
9
- withTypeInfo: options?.verbose,
10
- prettyObjects: options?.verbose,
11
- ...options
12
- };
13
- if (value === void 0)
14
- return _options.withTypeInfo ? "[undefined]" : _options.invalidValueString;
15
- if (value === null)
16
- return _options.withTypeInfo ? "[null]" : _options.invalidValueString;
17
- if (typeof value === "string")
18
- return `${_options.withTypeInfo ? "[string] " : ""}${value}`;
19
- if (typeof value === "number")
20
- return `${_options.withTypeInfo ? "[number] " : ""}${format_formatter.formatNumber(value)}`;
21
- if (typeof value === "bigint")
22
- return `${_options.withTypeInfo ? "[bigint] " : ""}${value}`;
23
- if (typeof value === "boolean")
24
- return `${_options.withTypeInfo ? "[boolean] " : ""}${value}`;
25
- if (typeof value === "object") {
26
- if (Array.isArray(value)) {
27
- const stringfiedValue = value.map((el) => stringify(el, _options));
28
- return `${_options.withTypeInfo ? "[array] " : ""}${_options.verbose ? stringfiedValue.join(", ") : format_formatter.formatList(stringfiedValue)}`;
29
- }
30
- if (value instanceof Date)
31
- return `${_options.withTypeInfo ? "[date] " : ""}${format_formatter.dateFormatter.format(value)}`;
32
- if (value instanceof date_isoDateTime.ISODateTime)
33
- return `${_options.withTypeInfo ? "[date] " : ""}${value.format()}`;
34
- return `${_options.withTypeInfo ? "[object] " : ""}${JSON.stringify(value, null, _options.prettyObjects ? 2 : void 0)}`;
35
- }
36
- if (typeof value === "function")
37
- return `${_options.withTypeInfo ? "[function] " : ""}${_options.callFunctions && value.length === 0 ? stringify(value(), _options) : value.toString()}`;
38
- if (typeof value === "symbol")
39
- return `${_options.withTypeInfo ? "[symbol] " : ""}${value.toString()}`;
40
- return _options.invalidValueString;
41
- };
2
+ const require_date_iso_date_time_iso_date_time = require("../date/iso-date-time/iso-date-time.cjs");
3
+ const require_format_formatter = require("./formatter.cjs");
4
+ //#region src/format/stringify.ts
5
+ /**
6
+ * Returns string representation of the value;
7
+ *
8
+ * If the valid is null or undefined, returns `options.invalidValueString`.
9
+ */
10
+ function stringify(value, options) {
11
+ const _options = {
12
+ invalidValueString: "\0",
13
+ withTypeInfo: options?.verbose,
14
+ prettyObjects: options?.verbose,
15
+ ...options
16
+ };
17
+ if (value === null) return _options.withTypeInfo ? "[null]" : _options.invalidValueString;
18
+ if (typeof value === "string") return `${_options.withTypeInfo ? "[string] " : ""}${value}`;
19
+ if (typeof value === "number") return `${_options.withTypeInfo ? "[number] " : ""}${require_format_formatter.formatNumber(value)}`;
20
+ if (typeof value === "bigint") return `${_options.withTypeInfo ? "[bigint] " : ""}${value}`;
21
+ if (typeof value === "boolean") return `${_options.withTypeInfo ? "[boolean] " : ""}${value}`;
22
+ if (typeof value === "object") {
23
+ if (Array.isArray(value)) {
24
+ const stringfiedValue = value.map((el) => stringify(el, _options));
25
+ return `${_options.withTypeInfo ? "[array] " : ""}${_options.verbose ? stringfiedValue.join(", ") : require_format_formatter.formatList(stringfiedValue)}`;
26
+ }
27
+ if (value instanceof Date) return `${_options.withTypeInfo ? "[date] " : ""}${require_format_formatter.dateFormatter.format(value)}`;
28
+ if (value instanceof require_date_iso_date_time_iso_date_time.ISODateTime) return `${_options.withTypeInfo ? "[date] " : ""}${value.format()}`;
29
+ return `${_options.withTypeInfo ? "[object] " : ""}${JSON.stringify(value, null, _options.prettyObjects ? 2 : void 0)}`;
30
+ }
31
+ if (typeof value === "function") return `${_options.withTypeInfo ? "[function] " : ""}${_options.callFunctions && value.length === 0 ? stringify(value(), _options) : value.toString()}`;
32
+ if (typeof value === "symbol") return `${_options.withTypeInfo ? "[symbol] " : ""}${value.toString()}`;
33
+ return _options.withTypeInfo ? "[undefined]" : _options.invalidValueString;
34
+ }
35
+ //#endregion
42
36
  exports.stringify = stringify;
@@ -35,4 +35,4 @@ export interface StringifyValueOptions {
35
35
  *
36
36
  * If the valid is null or undefined, returns `options.invalidValueString`.
37
37
  */
38
- export declare const stringify: (value: unknown, options?: StringifyValueOptions) => string;
38
+ export declare function stringify(value: unknown, options?: StringifyValueOptions): string;
@@ -1,42 +1,35 @@
1
- import { formatNumber, formatList, dateFormatter } from "./formatter.js";
2
- import { ISODateTime } from "../date/iso-date-time.js";
3
- const stringify = (value, options) => {
4
- const _options = {
5
- invalidValueString: "\0",
6
- // Unicode NUL
7
- withTypeInfo: options?.verbose,
8
- prettyObjects: options?.verbose,
9
- ...options
10
- };
11
- if (value === void 0)
12
- return _options.withTypeInfo ? "[undefined]" : _options.invalidValueString;
13
- if (value === null)
14
- return _options.withTypeInfo ? "[null]" : _options.invalidValueString;
15
- if (typeof value === "string")
16
- return `${_options.withTypeInfo ? "[string] " : ""}${value}`;
17
- if (typeof value === "number")
18
- return `${_options.withTypeInfo ? "[number] " : ""}${formatNumber(value)}`;
19
- if (typeof value === "bigint")
20
- return `${_options.withTypeInfo ? "[bigint] " : ""}${value}`;
21
- if (typeof value === "boolean")
22
- return `${_options.withTypeInfo ? "[boolean] " : ""}${value}`;
23
- if (typeof value === "object") {
24
- if (Array.isArray(value)) {
25
- const stringfiedValue = value.map((el) => stringify(el, _options));
26
- return `${_options.withTypeInfo ? "[array] " : ""}${_options.verbose ? stringfiedValue.join(", ") : formatList(stringfiedValue)}`;
27
- }
28
- if (value instanceof Date)
29
- return `${_options.withTypeInfo ? "[date] " : ""}${dateFormatter.format(value)}`;
30
- if (value instanceof ISODateTime)
31
- return `${_options.withTypeInfo ? "[date] " : ""}${value.format()}`;
32
- return `${_options.withTypeInfo ? "[object] " : ""}${JSON.stringify(value, null, _options.prettyObjects ? 2 : void 0)}`;
33
- }
34
- if (typeof value === "function")
35
- return `${_options.withTypeInfo ? "[function] " : ""}${_options.callFunctions && value.length === 0 ? stringify(value(), _options) : value.toString()}`;
36
- if (typeof value === "symbol")
37
- return `${_options.withTypeInfo ? "[symbol] " : ""}${value.toString()}`;
38
- return _options.invalidValueString;
39
- };
40
- export {
41
- stringify
42
- };
1
+ import { ISODateTime } from "../date/iso-date-time/iso-date-time.js";
2
+ import { dateFormatter, formatList, formatNumber } from "./formatter.js";
3
+ //#region src/format/stringify.ts
4
+ /**
5
+ * Returns string representation of the value;
6
+ *
7
+ * If the valid is null or undefined, returns `options.invalidValueString`.
8
+ */
9
+ function stringify(value, options) {
10
+ const _options = {
11
+ invalidValueString: "\0",
12
+ withTypeInfo: options?.verbose,
13
+ prettyObjects: options?.verbose,
14
+ ...options
15
+ };
16
+ if (value === null) return _options.withTypeInfo ? "[null]" : _options.invalidValueString;
17
+ if (typeof value === "string") return `${_options.withTypeInfo ? "[string] " : ""}${value}`;
18
+ if (typeof value === "number") return `${_options.withTypeInfo ? "[number] " : ""}${formatNumber(value)}`;
19
+ if (typeof value === "bigint") return `${_options.withTypeInfo ? "[bigint] " : ""}${value}`;
20
+ if (typeof value === "boolean") return `${_options.withTypeInfo ? "[boolean] " : ""}${value}`;
21
+ if (typeof value === "object") {
22
+ if (Array.isArray(value)) {
23
+ const stringfiedValue = value.map((el) => stringify(el, _options));
24
+ return `${_options.withTypeInfo ? "[array] " : ""}${_options.verbose ? stringfiedValue.join(", ") : formatList(stringfiedValue)}`;
25
+ }
26
+ if (value instanceof Date) return `${_options.withTypeInfo ? "[date] " : ""}${dateFormatter.format(value)}`;
27
+ if (value instanceof ISODateTime) return `${_options.withTypeInfo ? "[date] " : ""}${value.format()}`;
28
+ return `${_options.withTypeInfo ? "[object] " : ""}${JSON.stringify(value, null, _options.prettyObjects ? 2 : void 0)}`;
29
+ }
30
+ if (typeof value === "function") return `${_options.withTypeInfo ? "[function] " : ""}${_options.callFunctions && value.length === 0 ? stringify(value(), _options) : value.toString()}`;
31
+ if (typeof value === "symbol") return `${_options.withTypeInfo ? "[symbol] " : ""}${value.toString()}`;
32
+ return _options.withTypeInfo ? "[undefined]" : _options.invalidValueString;
33
+ }
34
+ //#endregion
35
+ export { stringify };
@@ -1,35 +1,28 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- require("./formatter.cjs");
4
- const format_stringify = require("./stringify.cjs");
5
- const object_get = require("../object/get.cjs");
6
- const tagRegExp = new RegExp(/\${([a-zA-Z0-9_.]+)}/gm);
7
- const template = (text, templateVars) => {
8
- return text.replace(tagRegExp, (match, key) => {
9
- const templateVar = object_get.get(templateVars, key);
10
- const value = typeof templateVar === "function" ? templateVar() : templateVar;
11
- if (value === void 0) return match;
12
- if (value === null) return "";
13
- return format_stringify.stringify(value, { invalidValueString: "" });
14
- });
15
- };
16
- const templateObject = (obj, templateVars) => {
17
- const _objClone = {};
18
- for (const [key, value] of Object.entries(obj)) {
19
- const _key = template(key, templateVars);
20
- if (typeof value === "string") {
21
- _objClone[_key] = template(value, templateVars);
22
- } else if (value && typeof value === "object") {
23
- if (Array.isArray(value))
24
- _objClone[_key] = value.map(
25
- (valueItem) => typeof valueItem === "string" ? template(valueItem, templateVars) : valueItem
26
- );
27
- else _objClone[_key] = templateObject(value, templateVars);
28
- } else {
29
- _objClone[_key] = value;
30
- }
31
- }
32
- return _objClone;
33
- };
2
+ const require_format_stringify = require("./stringify.cjs");
3
+ const require_object_get = require("../object/get.cjs");
4
+ //#region src/format/template.ts
5
+ var tagRegExp = /\$\{([\w.]+)\}/g;
6
+ function template(text, templateVars) {
7
+ return text.replace(tagRegExp, (match, key) => {
8
+ const templateVar = require_object_get.get(templateVars, key);
9
+ const value = typeof templateVar === "function" ? templateVar(templateVars) : templateVar;
10
+ if (value === void 0) return match;
11
+ if (value === null) return "";
12
+ return require_format_stringify.stringify(value, { invalidValueString: "" });
13
+ });
14
+ }
15
+ function templateObject(obj, templateVars) {
16
+ const _objClone = {};
17
+ for (const [key, value] of Object.entries(obj)) {
18
+ const _key = template(key, templateVars);
19
+ if (typeof value === "string") _objClone[_key] = template(value, templateVars);
20
+ else if (value && typeof value === "object") if (Array.isArray(value)) _objClone[_key] = value.map((valueItem) => typeof valueItem === "string" ? template(valueItem, templateVars) : valueItem);
21
+ else _objClone[_key] = templateObject(value, templateVars);
22
+ else _objClone[_key] = value;
23
+ }
24
+ return _objClone;
25
+ }
26
+ //#endregion
34
27
  exports.template = template;
35
28
  exports.templateObject = templateObject;
@@ -1,6 +1,6 @@
1
1
  type TemplateVarValue = unknown | undefined | null;
2
- export type TemplateVar = TemplateVarValue | (() => TemplateVarValue);
2
+ export type TemplateVar = TemplateVarValue | ((templateVars: TemplateVars) => TemplateVarValue);
3
3
  export type TemplateVars = Record<string, TemplateVar>;
4
- export declare const template: (text: string, templateVars: TemplateVars) => string;
5
- export declare const templateObject: <T extends object>(obj: T, templateVars: TemplateVars) => T;
4
+ export declare function template(text: string, templateVars: TemplateVars): string;
5
+ export declare function templateObject<T extends object>(obj: T, templateVars: TemplateVars): T;
6
6
  export {};
@@ -1,35 +1,26 @@
1
- import "./formatter.js";
2
1
  import { stringify } from "./stringify.js";
3
2
  import { get } from "../object/get.js";
4
- const tagRegExp = new RegExp(/\${([a-zA-Z0-9_.]+)}/gm);
5
- const template = (text, templateVars) => {
6
- return text.replace(tagRegExp, (match, key) => {
7
- const templateVar = get(templateVars, key);
8
- const value = typeof templateVar === "function" ? templateVar() : templateVar;
9
- if (value === void 0) return match;
10
- if (value === null) return "";
11
- return stringify(value, { invalidValueString: "" });
12
- });
13
- };
14
- const templateObject = (obj, templateVars) => {
15
- const _objClone = {};
16
- for (const [key, value] of Object.entries(obj)) {
17
- const _key = template(key, templateVars);
18
- if (typeof value === "string") {
19
- _objClone[_key] = template(value, templateVars);
20
- } else if (value && typeof value === "object") {
21
- if (Array.isArray(value))
22
- _objClone[_key] = value.map(
23
- (valueItem) => typeof valueItem === "string" ? template(valueItem, templateVars) : valueItem
24
- );
25
- else _objClone[_key] = templateObject(value, templateVars);
26
- } else {
27
- _objClone[_key] = value;
28
- }
29
- }
30
- return _objClone;
31
- };
32
- export {
33
- template,
34
- templateObject
35
- };
3
+ //#region src/format/template.ts
4
+ var tagRegExp = /\$\{([\w.]+)\}/g;
5
+ function template(text, templateVars) {
6
+ return text.replace(tagRegExp, (match, key) => {
7
+ const templateVar = get(templateVars, key);
8
+ const value = typeof templateVar === "function" ? templateVar(templateVars) : templateVar;
9
+ if (value === void 0) return match;
10
+ if (value === null) return "";
11
+ return stringify(value, { invalidValueString: "" });
12
+ });
13
+ }
14
+ function templateObject(obj, templateVars) {
15
+ const _objClone = {};
16
+ for (const [key, value] of Object.entries(obj)) {
17
+ const _key = template(key, templateVars);
18
+ if (typeof value === "string") _objClone[_key] = template(value, templateVars);
19
+ else if (value && typeof value === "object") if (Array.isArray(value)) _objClone[_key] = value.map((valueItem) => typeof valueItem === "string" ? template(valueItem, templateVars) : valueItem);
20
+ else _objClone[_key] = templateObject(value, templateVars);
21
+ else _objClone[_key] = value;
22
+ }
23
+ return _objClone;
24
+ }
25
+ //#endregion
26
+ export { template, templateObject };
@@ -0,0 +1 @@
1
+ export {};