@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.
- 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 -4
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -4
- 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 +2129 -2246
- package/dist/string/slugify/index.js +2130 -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 +183 -67
- package/dist/array/index.cjs +0 -4
- package/dist/array/index.d.ts +0 -1
- package/dist/array/index.js +0 -4
- package/dist/date/index.cjs +0 -8
- package/dist/date/index.d.ts +0 -1
- 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 -3
- package/dist/duration/index.js +0 -8
- package/dist/format/index.cjs +0 -13
- package/dist/format/index.d.ts +0 -3
- package/dist/format/index.js +0 -13
- package/dist/object/index.cjs +0 -12
- package/dist/object/index.d.ts +0 -5
- package/dist/object/index.js +0 -12
- package/dist/path/index.cjs +0 -6
- package/dist/path/index.d.ts +0 -2
- package/dist/path/index.js +0 -6
- package/dist/set/index.cjs +0 -12
- package/dist/set/index.d.ts +0 -5
- package/dist/set/index.js +0 -12
- package/dist/string/index.cjs +0 -14
- package/dist/string/index.d.ts +0 -6
- package/dist/string/index.js +0 -14
- package/dist/value/index.cjs +0 -4
- package/dist/value/index.d.ts +0 -1
- package/dist/value/index.js +0 -4
- package/eslint.config.js +0 -19
- package/src/array/chunk.ts +0 -6
- package/src/array/index.ts +0 -1
- package/src/date/index.ts +0 -1
- package/src/date/iso-date-time.ts +0 -356
- package/src/duration/add-durations.ts +0 -16
- package/src/duration/index.ts +0 -3
- package/src/duration/is-duration.ts +0 -5
- package/src/duration/to-number.ts +0 -18
- package/src/format/formatter.ts +0 -37
- package/src/format/index.ts +0 -3
- package/src/format/stringify.ts +0 -87
- package/src/format/template.ts +0 -48
- package/src/index.ts +0 -1
- package/src/object/get.ts +0 -9
- package/src/object/index.ts +0 -5
- package/src/object/is-object.ts +0 -2
- package/src/object/omit.ts +0 -21
- package/src/object/pick.ts +0 -10
- package/src/object/set.ts +0 -15
- package/src/path/file-url-to-path.ts +0 -12
- package/src/path/index.ts +0 -2
- package/src/path/normalize.ts +0 -72
- package/src/set/difference.ts +0 -9
- package/src/set/index.ts +0 -5
- package/src/set/intersection.ts +0 -12
- package/src/set/is-superset.ts +0 -12
- package/src/set/symmetric-difference.ts +0 -12
- package/src/set/union.ts +0 -8
- package/src/string/capitalize.ts +0 -2
- package/src/string/index.ts +0 -6
- package/src/string/normalize.ts +0 -7
- package/src/string/pluralize/index.ts +0 -7
- package/src/string/pluralize/pluralize.ts +0 -296
- package/src/string/pluralize/rules/index.ts +0 -4
- package/src/string/pluralize/rules/irregular.ts +0 -59
- package/src/string/pluralize/rules/pluralization.ts +0 -40
- package/src/string/pluralize/rules/singularization.ts +0 -46
- package/src/string/pluralize/rules/uncountable.ts +0 -107
- package/src/string/pluralize/types.ts +0 -4
- package/src/string/slugify/index.ts +0 -3
- package/src/string/strip-html-tags.ts +0 -4
- package/src/string/to-int.ts +0 -20
- package/src/string/to-sentence-case.ts +0 -6
- package/src/string/trim.ts +0 -11
- package/src/string/truncate.ts +0 -44
- package/src/value/index.ts +0 -1
- package/src/value/is-empty.ts +0 -31
- package/tsconfig.json +0 -18
- package/tsconfig.lib.json +0 -37
- package/tsconfig.node.json +0 -25
- package/vite.config.ts +0 -76
package/dist/date/index.cjs
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const date_isoDateTime = require("./iso-date-time.cjs");
|
|
4
|
-
exports.DefaultDateFormat = date_isoDateTime.DefaultDateFormat;
|
|
5
|
-
exports.DefaultTimeFormat = date_isoDateTime.DefaultTimeFormat;
|
|
6
|
-
exports.DefaultTimezone = date_isoDateTime.DefaultTimezone;
|
|
7
|
-
exports.ISODateTime = date_isoDateTime.ISODateTime;
|
|
8
|
-
exports.InvalidDate = date_isoDateTime.InvalidDate;
|
package/dist/date/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './iso-date-time';
|
package/dist/date/index.js
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const isoDateTimeRegEx = new RegExp("^([0-9-]+)(T([0-9:.,]+)(Z|[+-]([0-9:]+))?)?$");
|
|
4
|
-
const dateRegEx = new RegExp("^(\\d{4})-?(\\d{2})?-?(\\d{2})?$");
|
|
5
|
-
const timeRegEx = new RegExp("^(\\d{2}):?(\\d{2})?:?(\\d{2})?(\\.(\\d{3}))?$");
|
|
6
|
-
const timezoneRegEx = new RegExp("^Z|^[+-]((\\d{2}):?(\\d{2})?)$");
|
|
7
|
-
const InvalidDate = /* @__PURE__ */ Symbol("Invalid Date");
|
|
8
|
-
const DefaultDateFormat = {
|
|
9
|
-
year: "numeric",
|
|
10
|
-
month: "long",
|
|
11
|
-
day: "2-digit"
|
|
12
|
-
};
|
|
13
|
-
const DefaultTimeFormat = {
|
|
14
|
-
hour: "2-digit",
|
|
15
|
-
minute: "2-digit",
|
|
16
|
-
timeZoneName: "short"
|
|
17
|
-
};
|
|
18
|
-
const DefaultTimezone = "America/Vancouver";
|
|
19
|
-
class ISODateTime {
|
|
20
|
-
#parsed;
|
|
21
|
-
#date;
|
|
22
|
-
#string;
|
|
23
|
-
constructor(isoDatetime) {
|
|
24
|
-
if (typeof isoDatetime === "string") {
|
|
25
|
-
this.#parsed = ISODateTime.parse(isoDatetime);
|
|
26
|
-
if (this.#parsed) {
|
|
27
|
-
this.#date = new Date(ISODateTime.toString(this));
|
|
28
|
-
} else {
|
|
29
|
-
this.#date = InvalidDate;
|
|
30
|
-
console.error(`Failed to parse date for value: ${isoDatetime}`);
|
|
31
|
-
}
|
|
32
|
-
} else if (typeof isoDatetime === "number" && Number.isFinite(isoDatetime)) {
|
|
33
|
-
this.#date = new Date(isoDatetime);
|
|
34
|
-
this.#parsed = ISODateTime.parse(this.#date.toISOString());
|
|
35
|
-
} else {
|
|
36
|
-
this.#date = /* @__PURE__ */ new Date();
|
|
37
|
-
this.#parsed = ISODateTime.parse(this.#date.toISOString());
|
|
38
|
-
}
|
|
39
|
-
if (this.#date !== InvalidDate) this.#string = this.#date.toISOString();
|
|
40
|
-
else this.#string = "Invalid Date";
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Get date and time components
|
|
44
|
-
*/
|
|
45
|
-
get parts() {
|
|
46
|
-
return this.#parsed;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Get timezone
|
|
50
|
-
*/
|
|
51
|
-
get timezone() {
|
|
52
|
-
return this.parts?.timezone ?? "UTC";
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Parse a string in ISO DateTime format.
|
|
56
|
-
* If the input is valid, returns date and time components;
|
|
57
|
-
* otherwise, returns `undefined`.
|
|
58
|
-
*/
|
|
59
|
-
static parse(isoDatetime) {
|
|
60
|
-
const isoDatetimeParts = isoDatetime.match(isoDateTimeRegEx);
|
|
61
|
-
if (isoDatetimeParts) {
|
|
62
|
-
const dateParts = isoDatetimeParts[1] && isoDatetimeParts[1].match(dateRegEx);
|
|
63
|
-
if (!dateParts) return void 0;
|
|
64
|
-
const parsedDateTime = {
|
|
65
|
-
date: { year: dateParts[1], month: dateParts[2], day: dateParts[3] }
|
|
66
|
-
};
|
|
67
|
-
const timeParts = isoDatetimeParts[3] && isoDatetimeParts[3].match(timeRegEx);
|
|
68
|
-
if (timeParts) {
|
|
69
|
-
parsedDateTime.time = {
|
|
70
|
-
hours: timeParts[1],
|
|
71
|
-
minutes: timeParts[2],
|
|
72
|
-
seconds: timeParts[3],
|
|
73
|
-
milliseconds: timeParts[5]
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
const tzParts = isoDatetimeParts[4] && isoDatetimeParts[4].match(timezoneRegEx);
|
|
77
|
-
if (tzParts) {
|
|
78
|
-
parsedDateTime.timezone = tzParts[0];
|
|
79
|
-
}
|
|
80
|
-
return parsedDateTime;
|
|
81
|
-
}
|
|
82
|
-
return void 0;
|
|
83
|
-
}
|
|
84
|
-
static getISOString(parts) {
|
|
85
|
-
if (!parts) return "Invalid Date";
|
|
86
|
-
return `${parts.date.year}-${parts.date.month ?? "01"}-${parts.date.day ?? "01"}T${parts.time?.hours ?? "00"}:${parts.time?.minutes ?? "00"}:${parts.time?.seconds ?? "00"}.${parts.time?.milliseconds ?? "000"}${parts.timezone ?? "Z"}`;
|
|
87
|
-
}
|
|
88
|
-
static toString(dateTime) {
|
|
89
|
-
const _p = typeof dateTime === "string" ? ISODateTime.parse(dateTime) : dateTime.parts;
|
|
90
|
-
return ISODateTime.getISOString(_p);
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Returns the stored time value in milliseconds since midnight, January 1, 1970 UTC.
|
|
94
|
-
*/
|
|
95
|
-
valueOf() {
|
|
96
|
-
if (this.#date === InvalidDate) return Number.NaN;
|
|
97
|
-
return this.#date.valueOf();
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Retruns ISO date and time string
|
|
101
|
-
*/
|
|
102
|
-
toString() {
|
|
103
|
-
return this.#string;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Retruns Javascript date object
|
|
107
|
-
*/
|
|
108
|
-
toDate() {
|
|
109
|
-
return this.#date;
|
|
110
|
-
}
|
|
111
|
-
get [Symbol.toStringTag]() {
|
|
112
|
-
return "ISODateTime";
|
|
113
|
-
}
|
|
114
|
-
[Symbol.toPrimitive](hint) {
|
|
115
|
-
if (hint === "string") return this.toString();
|
|
116
|
-
return this.valueOf();
|
|
117
|
-
}
|
|
118
|
-
toJSON() {
|
|
119
|
-
return this.toString();
|
|
120
|
-
}
|
|
121
|
-
static getFormatter(isoDatetime, config) {
|
|
122
|
-
let _format = {};
|
|
123
|
-
if (config?.customFormat?.dateStyle || config?.customFormat?.timeStyle) {
|
|
124
|
-
_format = {
|
|
125
|
-
dateStyle: config?.customFormat?.dateStyle,
|
|
126
|
-
timeStyle: config?.customFormat?.timeStyle
|
|
127
|
-
};
|
|
128
|
-
} else {
|
|
129
|
-
if (config?.noDate === true && config?.noTime === true) {
|
|
130
|
-
_format = { ...config.customFormat };
|
|
131
|
-
} else if (config?.noDate === true && !config?.noTime) {
|
|
132
|
-
_format = { ...DefaultTimeFormat, ...config.customFormat };
|
|
133
|
-
} else if (config?.noTime === true && !config.noDate) {
|
|
134
|
-
_format = { ...DefaultDateFormat, ...config.customFormat };
|
|
135
|
-
} else {
|
|
136
|
-
_format = { ...DefaultDateFormat, ...DefaultTimeFormat, ...config?.customFormat };
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
if (config?.customFormat?.timeZone) _format.timeZone = config.customFormat.timeZone;
|
|
140
|
-
else if (isoDatetime.parts?.time === void 0) _format.timeZone = "UTC";
|
|
141
|
-
else _format.timeZone = DefaultTimezone;
|
|
142
|
-
return new Intl.DateTimeFormat("en", _format);
|
|
143
|
-
}
|
|
144
|
-
static format(isoDatetime, config) {
|
|
145
|
-
const _isoDatetime = typeof isoDatetime === "string" ? new ISODateTime(isoDatetime) : isoDatetime;
|
|
146
|
-
const _date = _isoDatetime.toDate();
|
|
147
|
-
if (_date === InvalidDate) return _isoDatetime.toString();
|
|
148
|
-
const formatter = ISODateTime.getFormatter(_isoDatetime, config);
|
|
149
|
-
return formatter.format(_date);
|
|
150
|
-
}
|
|
151
|
-
static formatRange(startDate, endDate, config) {
|
|
152
|
-
const _startISODateTime = typeof startDate === "string" ? new ISODateTime(startDate) : startDate;
|
|
153
|
-
const _startDate = _startISODateTime.toDate();
|
|
154
|
-
if (_startDate === InvalidDate) return _startISODateTime.toString();
|
|
155
|
-
const _endISODateTime = typeof endDate === "string" ? new ISODateTime(endDate) : endDate;
|
|
156
|
-
const _endDate = _endISODateTime.toDate();
|
|
157
|
-
if (_endDate === InvalidDate) return _endISODateTime.toString();
|
|
158
|
-
if (_startISODateTime.timezone !== _endISODateTime.timezone) throw "Start and end dates in different time zones";
|
|
159
|
-
const formatter = ISODateTime.getFormatter(_startISODateTime, config);
|
|
160
|
-
const formatedRange = formatter.formatRange(_startDate, _endDate).replace(/\s/g, " ");
|
|
161
|
-
return formatedRange.replace(/\s/g, " ");
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Returns formated date and time string
|
|
165
|
-
*/
|
|
166
|
-
format(config) {
|
|
167
|
-
return ISODateTime.format(this, config);
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Adds milliseconds to the date and returns it as a new ISODateTime object
|
|
171
|
-
*/
|
|
172
|
-
addMillisecond(milliseconds) {
|
|
173
|
-
return new ISODateTime(this.valueOf() + milliseconds);
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Adds seconds to the date and returns it as a new ISODateTime object
|
|
177
|
-
*/
|
|
178
|
-
addSecond(seconds) {
|
|
179
|
-
return this.addMillisecond(seconds * 1e3);
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Adds minutes to the date and returns it as a new ISODateTime object
|
|
183
|
-
*/
|
|
184
|
-
addMinute(minutes) {
|
|
185
|
-
return this.addMillisecond(minutes * 6e4);
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Adds hours to the date and returns it as a new ISODateTime object
|
|
189
|
-
*/
|
|
190
|
-
addHour(hours) {
|
|
191
|
-
return this.addMillisecond(hours * 36e5);
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Adds days to the date and returns it as a new ISODateTime object
|
|
195
|
-
*/
|
|
196
|
-
addDay(days) {
|
|
197
|
-
return this.addMillisecond(days * 864e5);
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Returns the start of the previous month as a new ISODateTime object
|
|
201
|
-
*/
|
|
202
|
-
static getPrevMonthStart(date) {
|
|
203
|
-
if (date.parts) {
|
|
204
|
-
const month = date.parts.date.month ? Number(date.parts.date.month) : 1;
|
|
205
|
-
const prevMonth = month === 1 ? 12 : month - 1;
|
|
206
|
-
const year = month === 1 ? (Number(date.parts.date.year) - 1).toString() : date.parts.date.year;
|
|
207
|
-
const prevParts = {
|
|
208
|
-
date: {
|
|
209
|
-
year,
|
|
210
|
-
month: prevMonth.toString().padStart(2, "0"),
|
|
211
|
-
day: "01"
|
|
212
|
-
},
|
|
213
|
-
timezone: date.parts.timezone
|
|
214
|
-
};
|
|
215
|
-
return new ISODateTime(ISODateTime.getISOString(prevParts));
|
|
216
|
-
}
|
|
217
|
-
return date;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Returns the start of the previous month as a new ISODateTime object
|
|
221
|
-
*/
|
|
222
|
-
getPrevMonthStart() {
|
|
223
|
-
return ISODateTime.getPrevMonthStart(this);
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Returns the start of the next month as a new ISODateTime object
|
|
227
|
-
*/
|
|
228
|
-
static getNextMonthStart(date) {
|
|
229
|
-
if (date.parts) {
|
|
230
|
-
const month = date.parts.date.month ? Number(date.parts.date.month) : 1;
|
|
231
|
-
const nextMonth = month % 12 + 1;
|
|
232
|
-
const year = month === 12 ? (Number(date.parts.date.year) + 1).toString() : date.parts.date.year;
|
|
233
|
-
const nextParts = {
|
|
234
|
-
date: {
|
|
235
|
-
year,
|
|
236
|
-
month: nextMonth.toString().padStart(2, "0"),
|
|
237
|
-
day: "01"
|
|
238
|
-
},
|
|
239
|
-
timezone: date.parts.timezone
|
|
240
|
-
};
|
|
241
|
-
return new ISODateTime(ISODateTime.getISOString(nextParts));
|
|
242
|
-
}
|
|
243
|
-
return date;
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Returns the start of the next month as a new ISODateTime object
|
|
247
|
-
*/
|
|
248
|
-
getNextMonthStart() {
|
|
249
|
-
return ISODateTime.getNextMonthStart(this);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
exports.DefaultDateFormat = DefaultDateFormat;
|
|
253
|
-
exports.DefaultTimeFormat = DefaultTimeFormat;
|
|
254
|
-
exports.DefaultTimezone = DefaultTimezone;
|
|
255
|
-
exports.ISODateTime = ISODateTime;
|
|
256
|
-
exports.InvalidDate = InvalidDate;
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
const isoDateTimeRegEx = new RegExp("^([0-9-]+)(T([0-9:.,]+)(Z|[+-]([0-9:]+))?)?$");
|
|
2
|
-
const dateRegEx = new RegExp("^(\\d{4})-?(\\d{2})?-?(\\d{2})?$");
|
|
3
|
-
const timeRegEx = new RegExp("^(\\d{2}):?(\\d{2})?:?(\\d{2})?(\\.(\\d{3}))?$");
|
|
4
|
-
const timezoneRegEx = new RegExp("^Z|^[+-]((\\d{2}):?(\\d{2})?)$");
|
|
5
|
-
const InvalidDate = /* @__PURE__ */ Symbol("Invalid Date");
|
|
6
|
-
const DefaultDateFormat = {
|
|
7
|
-
year: "numeric",
|
|
8
|
-
month: "long",
|
|
9
|
-
day: "2-digit"
|
|
10
|
-
};
|
|
11
|
-
const DefaultTimeFormat = {
|
|
12
|
-
hour: "2-digit",
|
|
13
|
-
minute: "2-digit",
|
|
14
|
-
timeZoneName: "short"
|
|
15
|
-
};
|
|
16
|
-
const DefaultTimezone = "America/Vancouver";
|
|
17
|
-
class ISODateTime {
|
|
18
|
-
#parsed;
|
|
19
|
-
#date;
|
|
20
|
-
#string;
|
|
21
|
-
constructor(isoDatetime) {
|
|
22
|
-
if (typeof isoDatetime === "string") {
|
|
23
|
-
this.#parsed = ISODateTime.parse(isoDatetime);
|
|
24
|
-
if (this.#parsed) {
|
|
25
|
-
this.#date = new Date(ISODateTime.toString(this));
|
|
26
|
-
} else {
|
|
27
|
-
this.#date = InvalidDate;
|
|
28
|
-
console.error(`Failed to parse date for value: ${isoDatetime}`);
|
|
29
|
-
}
|
|
30
|
-
} else if (typeof isoDatetime === "number" && Number.isFinite(isoDatetime)) {
|
|
31
|
-
this.#date = new Date(isoDatetime);
|
|
32
|
-
this.#parsed = ISODateTime.parse(this.#date.toISOString());
|
|
33
|
-
} else {
|
|
34
|
-
this.#date = /* @__PURE__ */ new Date();
|
|
35
|
-
this.#parsed = ISODateTime.parse(this.#date.toISOString());
|
|
36
|
-
}
|
|
37
|
-
if (this.#date !== InvalidDate) this.#string = this.#date.toISOString();
|
|
38
|
-
else this.#string = "Invalid Date";
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Get date and time components
|
|
42
|
-
*/
|
|
43
|
-
get parts() {
|
|
44
|
-
return this.#parsed;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Get timezone
|
|
48
|
-
*/
|
|
49
|
-
get timezone() {
|
|
50
|
-
return this.parts?.timezone ?? "UTC";
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Parse a string in ISO DateTime format.
|
|
54
|
-
* If the input is valid, returns date and time components;
|
|
55
|
-
* otherwise, returns `undefined`.
|
|
56
|
-
*/
|
|
57
|
-
static parse(isoDatetime) {
|
|
58
|
-
const isoDatetimeParts = isoDatetime.match(isoDateTimeRegEx);
|
|
59
|
-
if (isoDatetimeParts) {
|
|
60
|
-
const dateParts = isoDatetimeParts[1] && isoDatetimeParts[1].match(dateRegEx);
|
|
61
|
-
if (!dateParts) return void 0;
|
|
62
|
-
const parsedDateTime = {
|
|
63
|
-
date: { year: dateParts[1], month: dateParts[2], day: dateParts[3] }
|
|
64
|
-
};
|
|
65
|
-
const timeParts = isoDatetimeParts[3] && isoDatetimeParts[3].match(timeRegEx);
|
|
66
|
-
if (timeParts) {
|
|
67
|
-
parsedDateTime.time = {
|
|
68
|
-
hours: timeParts[1],
|
|
69
|
-
minutes: timeParts[2],
|
|
70
|
-
seconds: timeParts[3],
|
|
71
|
-
milliseconds: timeParts[5]
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
const tzParts = isoDatetimeParts[4] && isoDatetimeParts[4].match(timezoneRegEx);
|
|
75
|
-
if (tzParts) {
|
|
76
|
-
parsedDateTime.timezone = tzParts[0];
|
|
77
|
-
}
|
|
78
|
-
return parsedDateTime;
|
|
79
|
-
}
|
|
80
|
-
return void 0;
|
|
81
|
-
}
|
|
82
|
-
static getISOString(parts) {
|
|
83
|
-
if (!parts) return "Invalid Date";
|
|
84
|
-
return `${parts.date.year}-${parts.date.month ?? "01"}-${parts.date.day ?? "01"}T${parts.time?.hours ?? "00"}:${parts.time?.minutes ?? "00"}:${parts.time?.seconds ?? "00"}.${parts.time?.milliseconds ?? "000"}${parts.timezone ?? "Z"}`;
|
|
85
|
-
}
|
|
86
|
-
static toString(dateTime) {
|
|
87
|
-
const _p = typeof dateTime === "string" ? ISODateTime.parse(dateTime) : dateTime.parts;
|
|
88
|
-
return ISODateTime.getISOString(_p);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Returns the stored time value in milliseconds since midnight, January 1, 1970 UTC.
|
|
92
|
-
*/
|
|
93
|
-
valueOf() {
|
|
94
|
-
if (this.#date === InvalidDate) return Number.NaN;
|
|
95
|
-
return this.#date.valueOf();
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Retruns ISO date and time string
|
|
99
|
-
*/
|
|
100
|
-
toString() {
|
|
101
|
-
return this.#string;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Retruns Javascript date object
|
|
105
|
-
*/
|
|
106
|
-
toDate() {
|
|
107
|
-
return this.#date;
|
|
108
|
-
}
|
|
109
|
-
get [Symbol.toStringTag]() {
|
|
110
|
-
return "ISODateTime";
|
|
111
|
-
}
|
|
112
|
-
[Symbol.toPrimitive](hint) {
|
|
113
|
-
if (hint === "string") return this.toString();
|
|
114
|
-
return this.valueOf();
|
|
115
|
-
}
|
|
116
|
-
toJSON() {
|
|
117
|
-
return this.toString();
|
|
118
|
-
}
|
|
119
|
-
static getFormatter(isoDatetime, config) {
|
|
120
|
-
let _format = {};
|
|
121
|
-
if (config?.customFormat?.dateStyle || config?.customFormat?.timeStyle) {
|
|
122
|
-
_format = {
|
|
123
|
-
dateStyle: config?.customFormat?.dateStyle,
|
|
124
|
-
timeStyle: config?.customFormat?.timeStyle
|
|
125
|
-
};
|
|
126
|
-
} else {
|
|
127
|
-
if (config?.noDate === true && config?.noTime === true) {
|
|
128
|
-
_format = { ...config.customFormat };
|
|
129
|
-
} else if (config?.noDate === true && !config?.noTime) {
|
|
130
|
-
_format = { ...DefaultTimeFormat, ...config.customFormat };
|
|
131
|
-
} else if (config?.noTime === true && !config.noDate) {
|
|
132
|
-
_format = { ...DefaultDateFormat, ...config.customFormat };
|
|
133
|
-
} else {
|
|
134
|
-
_format = { ...DefaultDateFormat, ...DefaultTimeFormat, ...config?.customFormat };
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
if (config?.customFormat?.timeZone) _format.timeZone = config.customFormat.timeZone;
|
|
138
|
-
else if (isoDatetime.parts?.time === void 0) _format.timeZone = "UTC";
|
|
139
|
-
else _format.timeZone = DefaultTimezone;
|
|
140
|
-
return new Intl.DateTimeFormat("en", _format);
|
|
141
|
-
}
|
|
142
|
-
static format(isoDatetime, config) {
|
|
143
|
-
const _isoDatetime = typeof isoDatetime === "string" ? new ISODateTime(isoDatetime) : isoDatetime;
|
|
144
|
-
const _date = _isoDatetime.toDate();
|
|
145
|
-
if (_date === InvalidDate) return _isoDatetime.toString();
|
|
146
|
-
const formatter = ISODateTime.getFormatter(_isoDatetime, config);
|
|
147
|
-
return formatter.format(_date);
|
|
148
|
-
}
|
|
149
|
-
static formatRange(startDate, endDate, config) {
|
|
150
|
-
const _startISODateTime = typeof startDate === "string" ? new ISODateTime(startDate) : startDate;
|
|
151
|
-
const _startDate = _startISODateTime.toDate();
|
|
152
|
-
if (_startDate === InvalidDate) return _startISODateTime.toString();
|
|
153
|
-
const _endISODateTime = typeof endDate === "string" ? new ISODateTime(endDate) : endDate;
|
|
154
|
-
const _endDate = _endISODateTime.toDate();
|
|
155
|
-
if (_endDate === InvalidDate) return _endISODateTime.toString();
|
|
156
|
-
if (_startISODateTime.timezone !== _endISODateTime.timezone) throw "Start and end dates in different time zones";
|
|
157
|
-
const formatter = ISODateTime.getFormatter(_startISODateTime, config);
|
|
158
|
-
const formatedRange = formatter.formatRange(_startDate, _endDate).replace(/\s/g, " ");
|
|
159
|
-
return formatedRange.replace(/\s/g, " ");
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Returns formated date and time string
|
|
163
|
-
*/
|
|
164
|
-
format(config) {
|
|
165
|
-
return ISODateTime.format(this, config);
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Adds milliseconds to the date and returns it as a new ISODateTime object
|
|
169
|
-
*/
|
|
170
|
-
addMillisecond(milliseconds) {
|
|
171
|
-
return new ISODateTime(this.valueOf() + milliseconds);
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Adds seconds to the date and returns it as a new ISODateTime object
|
|
175
|
-
*/
|
|
176
|
-
addSecond(seconds) {
|
|
177
|
-
return this.addMillisecond(seconds * 1e3);
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Adds minutes to the date and returns it as a new ISODateTime object
|
|
181
|
-
*/
|
|
182
|
-
addMinute(minutes) {
|
|
183
|
-
return this.addMillisecond(minutes * 6e4);
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Adds hours to the date and returns it as a new ISODateTime object
|
|
187
|
-
*/
|
|
188
|
-
addHour(hours) {
|
|
189
|
-
return this.addMillisecond(hours * 36e5);
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Adds days to the date and returns it as a new ISODateTime object
|
|
193
|
-
*/
|
|
194
|
-
addDay(days) {
|
|
195
|
-
return this.addMillisecond(days * 864e5);
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Returns the start of the previous month as a new ISODateTime object
|
|
199
|
-
*/
|
|
200
|
-
static getPrevMonthStart(date) {
|
|
201
|
-
if (date.parts) {
|
|
202
|
-
const month = date.parts.date.month ? Number(date.parts.date.month) : 1;
|
|
203
|
-
const prevMonth = month === 1 ? 12 : month - 1;
|
|
204
|
-
const year = month === 1 ? (Number(date.parts.date.year) - 1).toString() : date.parts.date.year;
|
|
205
|
-
const prevParts = {
|
|
206
|
-
date: {
|
|
207
|
-
year,
|
|
208
|
-
month: prevMonth.toString().padStart(2, "0"),
|
|
209
|
-
day: "01"
|
|
210
|
-
},
|
|
211
|
-
timezone: date.parts.timezone
|
|
212
|
-
};
|
|
213
|
-
return new ISODateTime(ISODateTime.getISOString(prevParts));
|
|
214
|
-
}
|
|
215
|
-
return date;
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Returns the start of the previous month as a new ISODateTime object
|
|
219
|
-
*/
|
|
220
|
-
getPrevMonthStart() {
|
|
221
|
-
return ISODateTime.getPrevMonthStart(this);
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Returns the start of the next month as a new ISODateTime object
|
|
225
|
-
*/
|
|
226
|
-
static getNextMonthStart(date) {
|
|
227
|
-
if (date.parts) {
|
|
228
|
-
const month = date.parts.date.month ? Number(date.parts.date.month) : 1;
|
|
229
|
-
const nextMonth = month % 12 + 1;
|
|
230
|
-
const year = month === 12 ? (Number(date.parts.date.year) + 1).toString() : date.parts.date.year;
|
|
231
|
-
const nextParts = {
|
|
232
|
-
date: {
|
|
233
|
-
year,
|
|
234
|
-
month: nextMonth.toString().padStart(2, "0"),
|
|
235
|
-
day: "01"
|
|
236
|
-
},
|
|
237
|
-
timezone: date.parts.timezone
|
|
238
|
-
};
|
|
239
|
-
return new ISODateTime(ISODateTime.getISOString(nextParts));
|
|
240
|
-
}
|
|
241
|
-
return date;
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Returns the start of the next month as a new ISODateTime object
|
|
245
|
-
*/
|
|
246
|
-
getNextMonthStart() {
|
|
247
|
-
return ISODateTime.getNextMonthStart(this);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
export {
|
|
251
|
-
DefaultDateFormat,
|
|
252
|
-
DefaultTimeFormat,
|
|
253
|
-
DefaultTimezone,
|
|
254
|
-
ISODateTime,
|
|
255
|
-
InvalidDate
|
|
256
|
-
};
|
package/dist/duration/index.cjs
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const duration_isDuration = require("./is-duration.cjs");
|
|
4
|
-
const duration_toNumber = require("./to-number.cjs");
|
|
5
|
-
const duration_addDurations = require("./add-durations.cjs");
|
|
6
|
-
exports.isDuration = duration_isDuration.isDuration;
|
|
7
|
-
exports.toNumber = duration_toNumber.toNumber;
|
|
8
|
-
exports.addDuration = duration_addDurations.addDuration;
|
package/dist/duration/index.d.ts
DELETED
package/dist/duration/index.js
DELETED
package/dist/format/index.cjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const format_formatter = require("./formatter.cjs");
|
|
4
|
-
const format_stringify = require("./stringify.cjs");
|
|
5
|
-
const format_template = require("./template.cjs");
|
|
6
|
-
exports.dateFormatter = format_formatter.dateFormatter;
|
|
7
|
-
exports.formatCurrency = format_formatter.formatCurrency;
|
|
8
|
-
exports.formatDate = format_formatter.formatDate;
|
|
9
|
-
exports.formatList = format_formatter.formatList;
|
|
10
|
-
exports.formatNumber = format_formatter.formatNumber;
|
|
11
|
-
exports.stringify = format_stringify.stringify;
|
|
12
|
-
exports.template = format_template.template;
|
|
13
|
-
exports.templateObject = format_template.templateObject;
|
package/dist/format/index.d.ts
DELETED
package/dist/format/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { dateFormatter, formatCurrency, formatDate, formatList, formatNumber } from "./formatter.js";
|
|
2
|
-
import { stringify } from "./stringify.js";
|
|
3
|
-
import { template, templateObject } from "./template.js";
|
|
4
|
-
export {
|
|
5
|
-
dateFormatter,
|
|
6
|
-
formatCurrency,
|
|
7
|
-
formatDate,
|
|
8
|
-
formatList,
|
|
9
|
-
formatNumber,
|
|
10
|
-
stringify,
|
|
11
|
-
template,
|
|
12
|
-
templateObject
|
|
13
|
-
};
|
package/dist/object/index.cjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const object_isObject = require("./is-object.cjs");
|
|
4
|
-
const object_get = require("./get.cjs");
|
|
5
|
-
const object_set = require("./set.cjs");
|
|
6
|
-
const object_omit = require("./omit.cjs");
|
|
7
|
-
const object_pick = require("./pick.cjs");
|
|
8
|
-
exports.isObject = object_isObject.isObject;
|
|
9
|
-
exports.get = object_get.get;
|
|
10
|
-
exports.set = object_set.set;
|
|
11
|
-
exports.omit = object_omit.omit;
|
|
12
|
-
exports.pick = object_pick.pick;
|
package/dist/object/index.d.ts
DELETED
package/dist/object/index.js
DELETED
package/dist/path/index.cjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const path_normalize = require("./normalize.cjs");
|
|
4
|
-
const path_fileUrlToPath = require("./file-url-to-path.cjs");
|
|
5
|
-
exports.normalize = path_normalize.normalize;
|
|
6
|
-
exports.fileURLToPath = path_fileUrlToPath.fileURLToPath;
|
package/dist/path/index.d.ts
DELETED
package/dist/path/index.js
DELETED
package/dist/set/index.cjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const set_union = require("./union.cjs");
|
|
4
|
-
const set_intersection = require("./intersection.cjs");
|
|
5
|
-
const set_isSuperset = require("./is-superset.cjs");
|
|
6
|
-
const set_difference = require("./difference.cjs");
|
|
7
|
-
const set_symmetricDifference = require("./symmetric-difference.cjs");
|
|
8
|
-
exports.union = set_union.union;
|
|
9
|
-
exports.intersection = set_intersection.intersection;
|
|
10
|
-
exports.isSuperset = set_isSuperset.isSuperset;
|
|
11
|
-
exports.difference = set_difference.difference;
|
|
12
|
-
exports.symmetricDifference = set_symmetricDifference.symmetricDifference;
|
package/dist/set/index.d.ts
DELETED
package/dist/set/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { union } from "./union.js";
|
|
2
|
-
import { intersection } from "./intersection.js";
|
|
3
|
-
import { isSuperset } from "./is-superset.js";
|
|
4
|
-
import { difference } from "./difference.js";
|
|
5
|
-
import { symmetricDifference } from "./symmetric-difference.js";
|
|
6
|
-
export {
|
|
7
|
-
difference,
|
|
8
|
-
intersection,
|
|
9
|
-
isSuperset,
|
|
10
|
-
symmetricDifference,
|
|
11
|
-
union
|
|
12
|
-
};
|