@blackbyte/sugar 1.0.0-beta.3 → 1.0.0-beta.4
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/dist/shared/currency/currencyStringToObject.d.ts +8 -9
- package/dist/shared/currency/currencyStringToObject.js.map +1 -1
- package/dist/shared/datetime/_exports.d.ts +4 -1
- package/dist/shared/datetime/_exports.js +4 -1
- package/dist/shared/datetime/_exports.js.map +1 -1
- package/dist/shared/datetime/diffBetweenDates.d.ts +39 -0
- package/dist/shared/datetime/diffBetweenDates.js +25 -0
- package/dist/shared/datetime/diffBetweenDates.js.map +1 -0
- package/dist/shared/datetime/parseDate.d.ts +38 -0
- package/dist/shared/datetime/parseDate.js +34 -0
- package/dist/shared/datetime/parseDate.js.map +1 -0
- package/dist/shared/datetime/toYyyyMmDd.d.ts +34 -0
- package/dist/shared/datetime/toYyyyMmDd.js +19 -0
- package/dist/shared/datetime/toYyyyMmDd.js.map +1 -0
- package/package.json +3 -1
|
@@ -7,12 +7,11 @@
|
|
|
7
7
|
* @status stable
|
|
8
8
|
*
|
|
9
9
|
* This function take a currency string like "120 USD" and convert it to an object
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* }
|
|
10
|
+
* containing these properties:
|
|
11
|
+
*
|
|
12
|
+
* - `amount`: 120,
|
|
13
|
+
* - `code`: USD,
|
|
14
|
+
* - `symbol`: $
|
|
16
15
|
*
|
|
17
16
|
* @param {String} currency The currency string to convert
|
|
18
17
|
* @return {TCurrencyToObject} The currency object
|
|
@@ -23,9 +22,9 @@
|
|
|
23
22
|
* import { currencyStringToObject } from '@blackbyte/sugar/currency';
|
|
24
23
|
* currencyStringToObject('120 $');
|
|
25
24
|
* {
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
25
|
+
* amount: 120,
|
|
26
|
+
* code: 'USD',
|
|
27
|
+
* symbol: '$'
|
|
29
28
|
* }
|
|
30
29
|
*
|
|
31
30
|
* @see https://www.npmjs.com/package/currency-symbol-map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currencyStringToObject.js","sourceRoot":"","sources":["../../../src/shared/currency/currencyStringToObject.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"currencyStringToObject.js","sourceRoot":"","sources":["../../../src/shared/currency/currencyStringToObject.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AA0CpD,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,QAAgB;;IAEhB,iBAAiB;IACjB,MAAM,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;IAEpC,yBAAyB;IACzB,MAAM,YAAY,GAAW,QAAQ,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAEzE,aAAa;IACb,MAAM,SAAS,GAAG,iBAAiB,CAAC,iBAAwB,CAAC;IAE7D,kCAAkC;IAClC,IAAI,IAAI,GAAG,EAAE,EACX,MAAM,GAAG,EAAE,CAAC;IACd,IAAI,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC;QAC5B,IAAI,GAAG,YAAY,CAAC;QACpB,MAAM,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;IACnC,CAAC;SAAM,CAAC;QACN,IAAI;YACF,MAAA,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,YAAY,CAAC,mCACrE,EAAE,CAAC;QACL,MAAM,GAAG,YAAY,CAAC;IACxB,CAAC;IAED,OAAO;QACL,MAAM,EAAE,MAAM;QACd,IAAI;QACJ,MAAM;KACP,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import diffBetweenDates from './diffBetweenDates.js';
|
|
1
2
|
import formatDuration from './formatDuration.js';
|
|
3
|
+
import parseDate from './parseDate.js';
|
|
2
4
|
import sleep from './sleep.js';
|
|
3
5
|
import timeAgo from './timeAgo.js';
|
|
6
|
+
import toYyyyMmDd from './toYyyyMmDd.js';
|
|
4
7
|
import utcTime from './utcTime.js';
|
|
5
8
|
import wait from './wait.js';
|
|
6
9
|
export * from './convertTime.js';
|
|
7
|
-
export { formatDuration as __formatDuration, sleep as __sleep, timeAgo as __timeAgo, utcTime as __utcTime, wait as __wait, formatDuration, sleep, timeAgo, utcTime, wait, };
|
|
10
|
+
export { diffBetweenDates as __diffBetweenDates, formatDuration as __formatDuration, parseDate as __parseDate, sleep as __sleep, timeAgo as __timeAgo, toYyyyMmDd as __toYyyyMmDd, utcTime as __utcTime, wait as __wait, diffBetweenDates, formatDuration, parseDate, sleep, timeAgo, toYyyyMmDd, utcTime, wait, };
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import diffBetweenDates from './diffBetweenDates.js';
|
|
1
2
|
import formatDuration from './formatDuration.js';
|
|
3
|
+
import parseDate from './parseDate.js';
|
|
2
4
|
import sleep from './sleep.js';
|
|
3
5
|
import timeAgo from './timeAgo.js';
|
|
6
|
+
import toYyyyMmDd from './toYyyyMmDd.js';
|
|
4
7
|
import utcTime from './utcTime.js';
|
|
5
8
|
import wait from './wait.js';
|
|
6
9
|
export * from './convertTime.js';
|
|
7
|
-
export { formatDuration as __formatDuration, sleep as __sleep, timeAgo as __timeAgo, utcTime as __utcTime, wait as __wait, formatDuration, sleep, timeAgo, utcTime, wait, };
|
|
10
|
+
export { diffBetweenDates as __diffBetweenDates, formatDuration as __formatDuration, parseDate as __parseDate, sleep as __sleep, timeAgo as __timeAgo, toYyyyMmDd as __toYyyyMmDd, utcTime as __utcTime, wait as __wait, diffBetweenDates, formatDuration, parseDate, sleep, timeAgo, toYyyyMmDd, utcTime, wait, };
|
|
8
11
|
//# sourceMappingURL=_exports.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_exports.js","sourceRoot":"","sources":["../../../src/shared/datetime/_exports.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,qBAAqB,CAAC;AACjD,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,cAAc,kBAAkB,CAAC;AACjC,OAAO,EACL,cAAc,IAAI,gBAAgB,EAClC,KAAK,IAAI,OAAO,EAChB,OAAO,IAAI,SAAS,EACpB,OAAO,IAAI,SAAS,EACpB,IAAI,IAAI,MAAM,EACd,cAAc,EACd,KAAK,EACL,OAAO,EACP,OAAO,EACP,IAAI,GACL,CAAC"}
|
|
1
|
+
{"version":3,"file":"_exports.js","sourceRoot":"","sources":["../../../src/shared/datetime/_exports.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,uBAAuB,CAAC;AACrD,OAAO,cAAc,MAAM,qBAAqB,CAAC;AACjD,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,UAAU,MAAM,iBAAiB,CAAC;AACzC,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,cAAc,kBAAkB,CAAC;AACjC,OAAO,EACL,gBAAgB,IAAI,kBAAkB,EACtC,cAAc,IAAI,gBAAgB,EAClC,SAAS,IAAI,WAAW,EACxB,KAAK,IAAI,OAAO,EAChB,OAAO,IAAI,SAAS,EACpB,UAAU,IAAI,YAAY,EAC1B,OAAO,IAAI,SAAS,EACpB,IAAI,IAAI,MAAM,EACd,gBAAgB,EAChB,cAAc,EACd,SAAS,EACT,KAAK,EACL,OAAO,EACP,UAAU,EACV,OAAO,EACP,IAAI,GACL,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @name diffBetweenDates
|
|
3
|
+
* @namespace shared.datetime
|
|
4
|
+
* @type Function
|
|
5
|
+
* @platform js
|
|
6
|
+
* @platform node
|
|
7
|
+
* @status stable
|
|
8
|
+
*
|
|
9
|
+
* This function allows you to get the difference between two date strings.
|
|
10
|
+
* It will returns you an object with the difference represented with these properties (years, months, days, hours, minutes, seconds).
|
|
11
|
+
* Under the hood, it make uses of the wonderful [Luxon](https://moment.github.io/luxon) library.
|
|
12
|
+
*
|
|
13
|
+
* @param {String} date The date string to parse
|
|
14
|
+
* @param {TDiffBetweenDatesSettings} [settings={}] Some settings to configure your parsing
|
|
15
|
+
* @return {Date} The `Date` instance representing your date string
|
|
16
|
+
*
|
|
17
|
+
* @setting {String} [format=''] If you know the format of your date string, you can pass it here. This will make the parsing faster and more reliable. See [Luxon documentation](https://moment.github.io/luxon/#/parsing?id=table-of-tokens) for the list of supported tokens.
|
|
18
|
+
*
|
|
19
|
+
* @snippet diffBetweenDates($1, $2, $3)
|
|
20
|
+
*
|
|
21
|
+
* @example js
|
|
22
|
+
* import { diffBetweenDates } from '@blackbyte/sugar/datetime';
|
|
23
|
+
* diffBetweenDates('1945-10-12', '2025-10-15');
|
|
24
|
+
*
|
|
25
|
+
* @see https://moment.github.io/luxon
|
|
26
|
+
* @since 1.0.0
|
|
27
|
+
* @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
|
|
28
|
+
*/
|
|
29
|
+
export type TDiffBetweenDatesSettings = {
|
|
30
|
+
format: string;
|
|
31
|
+
};
|
|
32
|
+
export default function diffBetweenDates(date1: string | Date, date2: string | Date, settings?: Partial<TDiffBetweenDatesSettings>): {
|
|
33
|
+
years?: number;
|
|
34
|
+
months?: number;
|
|
35
|
+
days?: number;
|
|
36
|
+
hours?: number;
|
|
37
|
+
minutes?: number;
|
|
38
|
+
seconds?: number;
|
|
39
|
+
} | null;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DateTime } from 'luxon';
|
|
2
|
+
import parseDate from './parseDate.js';
|
|
3
|
+
export default function diffBetweenDates(date1, date2, settings) {
|
|
4
|
+
const finalSettings = Object.assign({ format: '' }, (settings !== null && settings !== void 0 ? settings : {}));
|
|
5
|
+
// prse the passed date
|
|
6
|
+
const jsDate1 = parseDate(date1, finalSettings);
|
|
7
|
+
const jsDate2 = parseDate(date2, finalSettings);
|
|
8
|
+
if (!jsDate1 || !jsDate2) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const luxonDate1 = DateTime.fromJSDate(jsDate1);
|
|
12
|
+
const luxonDate2 = DateTime.fromJSDate(jsDate2);
|
|
13
|
+
const diff = luxonDate2
|
|
14
|
+
.diff(luxonDate1, [
|
|
15
|
+
'years',
|
|
16
|
+
'months',
|
|
17
|
+
'days',
|
|
18
|
+
'hours',
|
|
19
|
+
'minutes',
|
|
20
|
+
'seconds',
|
|
21
|
+
])
|
|
22
|
+
.toObject();
|
|
23
|
+
return diff;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=diffBetweenDates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diffBetweenDates.js","sourceRoot":"","sources":["../../../src/shared/datetime/diffBetweenDates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAmCvC,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,KAAoB,EACpB,KAAoB,EACpB,QAA6C;IAS7C,MAAM,aAAa,mBACjB,MAAM,EAAE,EAAE,IACP,CAAC,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CAAC,CACpB,CAAC;IAEF,uBAAuB;IACvB,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAChD,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAEhD,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAChD,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAEhD,MAAM,IAAI,GAAG,UAAU;SACpB,IAAI,CAAC,UAAU,EAAE;QAChB,OAAO;QACP,QAAQ;QACR,MAAM;QACN,OAAO;QACP,SAAS;QACT,SAAS;KACV,CAAC;SACD,QAAQ,EAAE,CAAC;IAEd,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @name parseDate
|
|
3
|
+
* @namespace shared.datetime
|
|
4
|
+
* @type Function
|
|
5
|
+
* @platform js
|
|
6
|
+
* @platform node
|
|
7
|
+
* @status stable
|
|
8
|
+
*
|
|
9
|
+
* This function allows you to parse a date string. It will returns the `Date` instance for this date.
|
|
10
|
+
* Under the hood, it make uses of the wonderful [Luxon](https://moment.github.io/luxon) library.
|
|
11
|
+
* Make sure to use the library if you need more control over your dates.
|
|
12
|
+
* Luxon support these date formats:
|
|
13
|
+
*
|
|
14
|
+
* - ISO 8601
|
|
15
|
+
* - RFC2822
|
|
16
|
+
* - HTTP (header)
|
|
17
|
+
*
|
|
18
|
+
* @param {String} date The date string to parse
|
|
19
|
+
* @param {TParseDateSettings} [settings={}] Some settings to configure your parsing
|
|
20
|
+
* @return {Date} The `Date` instance representing your date string
|
|
21
|
+
*
|
|
22
|
+
* @setting {String} [format=''] If you know the format of your date string, you can pass it here. This will make the parsing faster and more reliable. See [Luxon documentation](https://moment.github.io/luxon/#/parsing?id=table-of-tokens) for the list of supported tokens.
|
|
23
|
+
*
|
|
24
|
+
* @snippet parseDate($1, $2)
|
|
25
|
+
*
|
|
26
|
+
* @example js
|
|
27
|
+
* import { parseDate } from '@blackbyte/sugar/datetime';
|
|
28
|
+
* parseDate('2025-10-12');
|
|
29
|
+
* parseDate('2024-10-15T10:30:00Z');
|
|
30
|
+
*
|
|
31
|
+
* @see https://moment.github.io/luxon
|
|
32
|
+
* @since 1.0.0
|
|
33
|
+
* @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
|
|
34
|
+
*/
|
|
35
|
+
export type TParseDateSettings = {
|
|
36
|
+
format: string;
|
|
37
|
+
};
|
|
38
|
+
export default function parseDate(date: string | Date, settings?: Partial<TParseDateSettings>): Date | null;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { DateTime } from 'luxon';
|
|
2
|
+
export default function parseDate(date, settings) {
|
|
3
|
+
const finalSettings = Object.assign({ format: '' }, (settings !== null && settings !== void 0 ? settings : {}));
|
|
4
|
+
let luxonDate;
|
|
5
|
+
// if it is already a date, we just return it
|
|
6
|
+
if (date instanceof Date) {
|
|
7
|
+
return date;
|
|
8
|
+
}
|
|
9
|
+
// if a format is passed, we check this.
|
|
10
|
+
// if it's invalid, we return null
|
|
11
|
+
if (finalSettings.format) {
|
|
12
|
+
luxonDate = DateTime.fromFormat(date, finalSettings.format);
|
|
13
|
+
}
|
|
14
|
+
if (luxonDate === null || luxonDate === void 0 ? void 0 : luxonDate.invalid) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
// otherwise we try to parse the date string
|
|
18
|
+
// using all the format supported by luxon
|
|
19
|
+
luxonDate = DateTime.fromISO(date);
|
|
20
|
+
if (!(luxonDate === null || luxonDate === void 0 ? void 0 : luxonDate.invalid)) {
|
|
21
|
+
return luxonDate.toJSDate();
|
|
22
|
+
}
|
|
23
|
+
luxonDate = DateTime.fromRFC2822(date);
|
|
24
|
+
if (!(luxonDate === null || luxonDate === void 0 ? void 0 : luxonDate.invalid)) {
|
|
25
|
+
return luxonDate.toJSDate();
|
|
26
|
+
}
|
|
27
|
+
luxonDate = DateTime.fromHTTP(date);
|
|
28
|
+
if (!(luxonDate === null || luxonDate === void 0 ? void 0 : luxonDate.invalid)) {
|
|
29
|
+
return luxonDate.toJSDate();
|
|
30
|
+
}
|
|
31
|
+
// nothing worked...
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=parseDate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseDate.js","sourceRoot":"","sources":["../../../src/shared/datetime/parseDate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAyCjC,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,IAAmB,EACnB,QAAsC;IAEtC,MAAM,aAAa,mBACjB,MAAM,EAAE,EAAE,IACP,CAAC,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CAAC,CACpB,CAAC;IACF,IAAI,SAAS,CAAC;IAEd,6CAA6C;IAC7C,IAAI,IAAI,YAAY,IAAI,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,wCAAwC;IACxC,kCAAkC;IAClC,IAAI,aAAa,CAAC,MAAM,EAAE,CAAC;QACzB,SAAS,GAAG,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC9D,CAAC;IACD,IAAI,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,OAAO,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,4CAA4C;IAC5C,0CAA0C;IAC1C,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,OAAO,CAAA,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC9B,CAAC;IAED,SAAS,GAAG,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACvC,IAAI,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,OAAO,CAAA,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC9B,CAAC;IAED,SAAS,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,OAAO,CAAA,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC9B,CAAC;IAED,oBAAoB;IACpB,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @name toYyyyMmDd
|
|
3
|
+
* @namespace shared.datetime
|
|
4
|
+
* @type Function
|
|
5
|
+
* @platform js
|
|
6
|
+
* @platform node
|
|
7
|
+
* @status stable
|
|
8
|
+
*
|
|
9
|
+
* This function allows you to pass any date string or Date instance and get back this
|
|
10
|
+
* one formatted as `YYYY-MM-DD`.
|
|
11
|
+
* This format is useful when you need to store dates in a database, set a date input value, etc...
|
|
12
|
+
* Under the hood, it make uses of the wonderful [Luxon](https://moment.github.io/luxon) library.
|
|
13
|
+
*
|
|
14
|
+
* @param {String} date The date (string) to convert to `YYYY-MM-DD`
|
|
15
|
+
* @param {TtoYyyyMmDdSettings} [settings={}] Some settings to configure your parsing
|
|
16
|
+
* @return {String} The date formatted as `YYYY-MM-DD`
|
|
17
|
+
*
|
|
18
|
+
* @setting {String} [format=''] If you know the format of your date string, you can pass it here. This will make the parsing faster and more reliable. See [Luxon documentation](https://moment.github.io/luxon/#/parsing?id=table-of-tokens) for the list of supported tokens.
|
|
19
|
+
*
|
|
20
|
+
* @snippet toYyyyMmDd($1, $2, $3)
|
|
21
|
+
*
|
|
22
|
+
* @example js
|
|
23
|
+
* import { toYyyyMmDd } from '@blackbyte/sugar/datetime';
|
|
24
|
+
* toYyyyMmDd('2025-10-15T14:30:00+02:00'); // '2025-10-15'
|
|
25
|
+
*
|
|
26
|
+
* @see https://moment.github.io/luxon
|
|
27
|
+
* @since 1.0.0
|
|
28
|
+
* @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
|
|
29
|
+
*/
|
|
30
|
+
export type TtoYyyyMmDdSettings = {
|
|
31
|
+
format: string;
|
|
32
|
+
separator: string;
|
|
33
|
+
};
|
|
34
|
+
export default function toYyyyMmDd(date: string | Date, settings?: Partial<TtoYyyyMmDdSettings>): string | null;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import parseDate from './parseDate.js';
|
|
2
|
+
export default function toYyyyMmDd(date, settings) {
|
|
3
|
+
const finalSettings = Object.assign({ format: '', separator: '-' }, (settings !== null && settings !== void 0 ? settings : {}));
|
|
4
|
+
if (typeof date === 'string' && date.match(/^\d{4}-\d{2}-\d{2}$/)) {
|
|
5
|
+
// already in the correct format
|
|
6
|
+
return date;
|
|
7
|
+
}
|
|
8
|
+
// prse the passed date
|
|
9
|
+
const jsDate = parseDate(date, finalSettings);
|
|
10
|
+
if (!jsDate) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const dateStr = jsDate
|
|
14
|
+
.toISOString()
|
|
15
|
+
.split('T')[0]
|
|
16
|
+
.replace('-', finalSettings.separator);
|
|
17
|
+
return dateStr;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=toYyyyMmDd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toYyyyMmDd.js","sourceRoot":"","sources":["../../../src/shared/datetime/toYyyyMmDd.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAqCvC,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,IAAmB,EACnB,QAAuC;IAEvC,MAAM,aAAa,mBACjB,MAAM,EAAE,EAAE,EACV,SAAS,EAAE,GAAG,IACX,CAAC,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CAAC,CACpB,CAAC;IAEF,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,EAAE,CAAC;QAClE,gCAAgC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,uBAAuB;IACvB,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAC9C,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,OAAO,GAAG,MAAM;SACnB,WAAW,EAAE;SACb,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;SACb,OAAO,CAAC,GAAG,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IACzC,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blackbyte/sugar",
|
|
3
3
|
"description": "The toolkit that you missed... like a sugar in your coffee!",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.4",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript",
|
|
7
7
|
"typescript",
|
|
@@ -203,6 +203,7 @@
|
|
|
203
203
|
},
|
|
204
204
|
"dependencies": {
|
|
205
205
|
"@faker-js/faker": "^8.4.1",
|
|
206
|
+
"@types/luxon": "^3.7.1",
|
|
206
207
|
"aggregation": "^1.2.7",
|
|
207
208
|
"atob": "^2.1.2",
|
|
208
209
|
"blueimp-md5": "^2.19.0",
|
|
@@ -238,6 +239,7 @@
|
|
|
238
239
|
"json-cyclic": "^1.0.2",
|
|
239
240
|
"lodash.clone": "^4.5.0",
|
|
240
241
|
"lodash.clonedeep": "^4.5.0",
|
|
242
|
+
"luxon": "^3.7.2",
|
|
241
243
|
"mark.js": "^8.11.1",
|
|
242
244
|
"memoizee": "^0.4.15",
|
|
243
245
|
"micromatch": "^4.0.5",
|