@bccampus/utils 0.2.3 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -8
- package/dist/array/chunk.cjs +13 -5
- package/dist/array/chunk.d.ts +7 -0
- package/dist/array/chunk.js +14 -7
- package/dist/array/chunk.test.d.ts +1 -0
- package/dist/date/iso-date-time/constants.cjs +27 -0
- package/dist/date/iso-date-time/constants.d.ts +9 -0
- package/dist/date/iso-date-time/constants.js +19 -0
- package/dist/date/iso-date-time/index.cjs +8 -0
- package/dist/date/iso-date-time/index.d.ts +5 -0
- package/dist/date/iso-date-time/index.js +3 -0
- package/dist/date/iso-date-time/iso-date-time.arithmetic.test.d.ts +1 -0
- package/dist/date/iso-date-time/iso-date-time.cjs +232 -0
- package/dist/date/{iso-date-time.d.ts → iso-date-time/iso-date-time.d.ts} +3 -32
- package/dist/date/iso-date-time/iso-date-time.format.test.d.ts +1 -0
- package/dist/date/iso-date-time/iso-date-time.js +231 -0
- package/dist/date/iso-date-time/iso-date-time.test.d.ts +1 -0
- package/dist/date/iso-date-time/types.cjs +0 -0
- package/dist/date/iso-date-time/types.d.ts +25 -0
- package/dist/date/iso-date-time/types.js +0 -0
- package/dist/duration/add-durations.cjs +5 -8
- package/dist/duration/add-durations.js +5 -9
- package/dist/duration/duration.test.d.ts +1 -0
- package/dist/duration/is-duration.cjs +4 -3
- package/dist/duration/is-duration.js +5 -5
- package/dist/duration/to-number.cjs +11 -10
- package/dist/duration/to-number.d.ts +1 -1
- package/dist/duration/to-number.js +11 -11
- package/dist/format/formatter.cjs +31 -31
- package/dist/format/formatter.d.ts +4 -4
- package/dist/format/formatter.js +32 -37
- package/dist/format/formatter.test.d.ts +1 -0
- package/dist/format/stringfy.test.d.ts +1 -0
- package/dist/format/stringify.cjs +34 -40
- package/dist/format/stringify.d.ts +1 -1
- package/dist/format/stringify.js +35 -42
- package/dist/format/template.cjs +25 -32
- package/dist/format/template.d.ts +3 -3
- package/dist/format/template.js +24 -33
- package/dist/format/template.test.d.ts +1 -0
- package/dist/index.cjs +0 -1
- package/dist/index.js +0 -1
- package/dist/object/get.cjs +5 -5
- package/dist/object/get.d.ts +1 -1
- package/dist/object/get.js +6 -7
- package/dist/object/get.test.d.ts +1 -0
- package/dist/object/is-object.cjs +5 -2
- package/dist/object/is-object.d.ts +1 -1
- package/dist/object/is-object.js +6 -4
- package/dist/object/is-object.test.d.ts +1 -0
- package/dist/object/omit.cjs +14 -16
- package/dist/object/omit.d.ts +1 -1
- package/dist/object/omit.js +15 -18
- package/dist/object/omit.test.d.ts +1 -0
- package/dist/object/pick.cjs +10 -9
- package/dist/object/pick.d.ts +1 -1
- package/dist/object/pick.js +9 -9
- package/dist/object/pick.test.d.ts +1 -0
- package/dist/object/set.cjs +13 -12
- package/dist/object/set.d.ts +1 -1
- package/dist/object/set.js +14 -14
- package/dist/object/set.test.d.ts +1 -0
- package/dist/path/file-url-to-path.cjs +10 -6
- package/dist/path/file-url-to-path.js +11 -8
- package/dist/path/file-url-to-path.test.d.ts +1 -0
- package/dist/path/normalize.cjs +41 -27
- package/dist/path/normalize.d.ts +8 -2
- package/dist/path/normalize.js +41 -28
- package/dist/path/normalize.test.d.ts +1 -0
- package/dist/set/difference.cjs +5 -6
- package/dist/set/difference.d.ts +1 -1
- package/dist/set/difference.js +6 -8
- package/dist/set/intersection.cjs +6 -9
- package/dist/set/intersection.d.ts +1 -1
- package/dist/set/intersection.js +7 -11
- package/dist/set/is-superset.cjs +5 -8
- package/dist/set/is-superset.d.ts +1 -1
- package/dist/set/is-superset.js +6 -10
- package/dist/set/set.test.d.ts +1 -0
- package/dist/set/symmetric-difference.cjs +6 -10
- package/dist/set/symmetric-difference.d.ts +1 -1
- package/dist/set/symmetric-difference.js +7 -12
- package/dist/set/union.cjs +5 -6
- package/dist/set/union.d.ts +1 -1
- package/dist/set/union.js +6 -8
- package/dist/string/capitalize.cjs +5 -2
- package/dist/string/capitalize.d.ts +1 -1
- package/dist/string/capitalize.js +6 -4
- package/dist/string/capitalize.test.d.ts +1 -0
- package/dist/string/normalize.cjs +7 -2
- package/dist/string/normalize.js +8 -4
- package/dist/string/normalize.test.d.ts +1 -0
- package/dist/string/pluralize/index.cjs +5 -4
- package/dist/string/pluralize/index.js +4 -5
- package/dist/string/pluralize/pluralize.cjs +162 -208
- package/dist/string/pluralize/pluralize.d.ts +4 -8
- package/dist/string/pluralize/pluralize.js +158 -205
- package/dist/string/pluralize/pluralize.test.d.ts +1 -0
- package/dist/string/pluralize/rules/index.cjs +8 -9
- package/dist/string/pluralize/rules/index.js +1 -6
- package/dist/string/pluralize/rules/irregular.cjs +55 -59
- package/dist/string/pluralize/rules/irregular.js +56 -61
- package/dist/string/pluralize/rules/pluralization.cjs +28 -36
- package/dist/string/pluralize/rules/pluralization.js +29 -38
- package/dist/string/pluralize/rules/singularization.cjs +27 -44
- package/dist/string/pluralize/rules/singularization.js +28 -46
- package/dist/string/pluralize/rules/uncountable.cjs +104 -110
- package/dist/string/pluralize/rules/uncountable.js +105 -112
- package/dist/string/pluralize/types.cjs +0 -1
- package/dist/string/pluralize/types.js +0 -1
- package/dist/string/slugify/index.cjs +2131 -2246
- package/dist/string/slugify/index.d.ts +1 -1
- package/dist/string/slugify/index.js +2132 -2248
- package/dist/string/slugify/slugify.test.d.ts +1 -0
- package/dist/string/strip-html-tags.cjs +4 -3
- package/dist/string/strip-html-tags.js +5 -5
- package/dist/string/strip-html-tags.test.d.ts +1 -0
- package/dist/string/to-int.cjs +14 -6
- package/dist/string/to-int.js +15 -8
- package/dist/string/to-int.test.d.ts +1 -0
- package/dist/string/to-sentence-case.cjs +6 -6
- package/dist/string/to-sentence-case.d.ts +1 -1
- package/dist/string/to-sentence-case.js +7 -8
- package/dist/string/to-sentence-case.test.d.ts +1 -0
- package/dist/string/trim.cjs +8 -7
- package/dist/string/trim.js +9 -9
- package/dist/string/trim.test.d.ts +1 -0
- package/dist/string/truncate.cjs +16 -15
- package/dist/string/truncate.js +17 -17
- package/dist/string/truncate.test.d.ts +1 -0
- package/dist/value/is-empty.cjs +30 -12
- package/dist/value/is-empty.d.ts +1 -1
- package/dist/value/is-empty.js +31 -14
- package/dist/value/value.test.d.ts +1 -0
- package/package.json +180 -69
- package/dist/array/index.cjs +0 -4
- package/dist/array/index.d.ts +0 -2
- package/dist/array/index.js +0 -4
- package/dist/date/index.cjs +0 -8
- package/dist/date/index.d.ts +0 -3
- package/dist/date/index.js +0 -8
- package/dist/date/iso-date-time.cjs +0 -256
- package/dist/date/iso-date-time.js +0 -256
- package/dist/duration/index.cjs +0 -8
- package/dist/duration/index.d.ts +0 -4
- package/dist/duration/index.js +0 -8
- package/dist/format/index.cjs +0 -13
- package/dist/format/index.d.ts +0 -5
- package/dist/format/index.js +0 -13
- package/dist/object/index.cjs +0 -12
- package/dist/object/index.d.ts +0 -6
- package/dist/object/index.js +0 -12
- package/dist/path/index.cjs +0 -6
- package/dist/path/index.d.ts +0 -4
- package/dist/path/index.js +0 -6
- package/dist/set/index.cjs +0 -12
- package/dist/set/index.d.ts +0 -6
- package/dist/set/index.js +0 -12
- package/dist/string/index.cjs +0 -14
- package/dist/string/index.d.ts +0 -8
- package/dist/string/index.js +0 -14
- package/dist/value/index.cjs +0 -4
- package/dist/value/index.d.ts +0 -2
- package/dist/value/index.js +0 -4
|
@@ -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("./
|
|
4
|
-
|
|
2
|
+
const require_duration_to_number = require("./to-number.cjs");
|
|
3
|
+
//#region src/duration/add-durations.ts
|
|
5
4
|
function addDuration(left, right) {
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
5
|
-
|
|
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
|
-
|
|
11
|
-
|
|
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
|
-
|
|
2
|
+
//#region src/duration/is-duration.ts
|
|
3
|
+
var durationRegExp = /^\d{2}:\d{2}:\d{2}$/;
|
|
4
4
|
function isDuration(duration) {
|
|
5
|
-
|
|
5
|
+
return durationRegExp.test(duration);
|
|
6
6
|
}
|
|
7
|
+
//#endregion
|
|
7
8
|
exports.isDuration = isDuration;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/duration/is-duration.ts
|
|
2
|
+
var durationRegExp = /^\d{2}:\d{2}:\d{2}$/;
|
|
2
3
|
function isDuration(duration) {
|
|
3
|
-
|
|
4
|
+
return durationRegExp.test(duration);
|
|
4
5
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
6
|
+
//#endregion
|
|
7
|
+
export { isDuration };
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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?:
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { toNumber };
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
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
|
|
3
|
-
export declare
|
|
4
|
-
export declare
|
|
5
|
-
export declare
|
|
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;
|
package/dist/format/formatter.js
CHANGED
|
@@ -1,40 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
|
38
|
+
export declare function stringify(value: unknown, options?: StringifyValueOptions): string;
|
package/dist/format/stringify.js
CHANGED
|
@@ -1,42 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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 };
|
package/dist/format/template.cjs
CHANGED
|
@@ -1,35 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
require("./
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
5
|
-
export declare
|
|
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 {};
|
package/dist/format/template.js
CHANGED
|
@@ -1,35 +1,26 @@
|
|
|
1
|
-
import "./formatter.js";
|
|
2
1
|
import { stringify } from "./stringify.js";
|
|
3
2
|
import { get } from "../object/get.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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 {};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|