@flightlesslabs/time-utils 0.1.0 → 0.2.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/CHANGELOG.md +6 -0
- package/esm/date-creator/createDate/createDate.d.ts +7 -15
- package/esm/date-creator/createDate/createDate.d.ts.map +1 -1
- package/esm/date-creator/createDate/createDate.js +9 -10
- package/esm/date-creator/createDateFactory/createDateFactory.d.ts +25 -8
- package/esm/date-creator/createDateFactory/createDateFactory.d.ts.map +1 -1
- package/esm/date-creator/createDateFactory/createDateFactory.js +2 -26
- package/esm/mod.d.ts +1 -1
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +1 -1
- package/package.json +1 -1
- package/script/date-creator/createDate/createDate.d.ts +7 -15
- package/script/date-creator/createDate/createDate.d.ts.map +1 -1
- package/script/date-creator/createDate/createDate.js +14 -2
- package/script/date-creator/createDateFactory/createDateFactory.d.ts +25 -8
- package/script/date-creator/createDateFactory/createDateFactory.d.ts.map +1 -1
- package/script/date-creator/createDateFactory/createDateFactory.js +2 -26
- package/script/mod.d.ts +1 -1
- package/script/mod.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
declare const createDate: {
|
|
2
|
-
(): ReturnType<typeof import("dayjs")>;
|
|
3
|
-
(date: import("../createDateFactory/types.js").CreateDateInput, format?: import("../createDateFactory/types.js").CreateDateFormat, options?: import("../createDateFactory/types.js").CreateDateOptions): ReturnType<typeof import("dayjs")>;
|
|
4
|
-
};
|
|
5
1
|
/**
|
|
6
|
-
* Default preconfigured
|
|
7
|
-
*
|
|
8
|
-
* Provides a ready-to-use API with UTC, timezone, and custom parsing support
|
|
9
|
-
* without requiring users to configure Dayjs manually.
|
|
2
|
+
* Default preconfigured createDate function.
|
|
10
3
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* createDate();
|
|
14
|
-
* createDate('2024-01-01');
|
|
15
|
-
* createDate('2024-01-01', undefined, { utc: true });
|
|
16
|
-
* ```
|
|
4
|
+
* This is a ready-to-use version of `createDate` that uses a shared,
|
|
5
|
+
* preconfigured Dayjs instance. No manual configuration is required.
|
|
17
6
|
*/
|
|
18
|
-
export
|
|
7
|
+
export declare const createDate: {
|
|
8
|
+
(): ReturnType<typeof import("dayjs")>;
|
|
9
|
+
(date: import("../createDateFactory/types.js").CreateDateInput, format?: import("../createDateFactory/types.js").CreateDateFormat, options?: import("../createDateFactory/types.js").CreateDateOptions): ReturnType<typeof import("dayjs")>;
|
|
10
|
+
};
|
|
19
11
|
//# sourceMappingURL=createDate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDate.d.ts","sourceRoot":"","sources":["../../../src/date-creator/createDate/createDate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createDate.d.ts","sourceRoot":"","sources":["../../../src/date-creator/createDate/createDate.ts"],"names":[],"mappings":"AAYA;;;;;GAKG;AACH,eAAO,MAAM,UAAU;;;CAAyB,CAAC"}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { createDateFactory } from '../createDateFactory/createDateFactory.js';
|
|
2
2
|
import defaultDayjs from '../createDateFactory/dayjs.js';
|
|
3
|
-
const { createDate } = createDateFactory(defaultDayjs);
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
4
|
+
* Preconfigured date factory instance using the default Dayjs setup.
|
|
6
5
|
*
|
|
7
|
-
*
|
|
6
|
+
* This instance is shared internally to provide a consistent date API
|
|
8
7
|
* without requiring users to configure Dayjs manually.
|
|
8
|
+
*/
|
|
9
|
+
const dateFactory = createDateFactory(defaultDayjs);
|
|
10
|
+
/**
|
|
11
|
+
* Default preconfigured createDate function.
|
|
9
12
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* createDate();
|
|
13
|
-
* createDate('2024-01-01');
|
|
14
|
-
* createDate('2024-01-01', undefined, { utc: true });
|
|
15
|
-
* ```
|
|
13
|
+
* This is a ready-to-use version of `createDate` that uses a shared,
|
|
14
|
+
* preconfigured Dayjs instance. No manual configuration is required.
|
|
16
15
|
*/
|
|
17
|
-
export
|
|
16
|
+
export const createDate = dateFactory.createDate;
|
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import defaultDayjs from './dayjs.js';
|
|
2
2
|
import type { CreateDateFormat, CreateDateInput, CreateDateOptions } from './types.js';
|
|
3
3
|
type Dayjs = typeof defaultDayjs;
|
|
4
|
+
/**
|
|
5
|
+
* Return type of `createDateFactory`.
|
|
6
|
+
*
|
|
7
|
+
* Contains the unified date creation function and the underlying Dayjs instance.
|
|
8
|
+
*/
|
|
9
|
+
export type CreateDateFactoryReturn = {
|
|
10
|
+
/**
|
|
11
|
+
* Unified date creation function.
|
|
12
|
+
*
|
|
13
|
+
* Overloads:
|
|
14
|
+
* - `createDate()` → current date/time
|
|
15
|
+
* - `createDate(input, format?, options?)` → parsed date
|
|
16
|
+
*/
|
|
17
|
+
createDate: {
|
|
18
|
+
(): ReturnType<Dayjs>;
|
|
19
|
+
(date: CreateDateInput, format?: CreateDateFormat, options?: CreateDateOptions): ReturnType<Dayjs>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Underlying Dayjs instance used by this factory.
|
|
23
|
+
*/
|
|
24
|
+
dayjs: Dayjs;
|
|
25
|
+
};
|
|
4
26
|
/**
|
|
5
27
|
* Creates a date factory bound to a specific Dayjs instance.
|
|
6
28
|
*
|
|
@@ -15,7 +37,7 @@ type Dayjs = typeof defaultDayjs;
|
|
|
15
37
|
*
|
|
16
38
|
* @param customDayjs - Optional custom Dayjs instance (useful for testing or plugin overrides)
|
|
17
39
|
*
|
|
18
|
-
* @returns
|
|
40
|
+
* @returns A factory object containing:
|
|
19
41
|
* - `createDate`: Unified date creation function
|
|
20
42
|
* - `dayjs`: The underlying Dayjs instance used by the factory
|
|
21
43
|
*
|
|
@@ -23,17 +45,12 @@ type Dayjs = typeof defaultDayjs;
|
|
|
23
45
|
* ```ts
|
|
24
46
|
* const { createDate } = createDateFactory();
|
|
25
47
|
*
|
|
48
|
+
* const now = createDate();
|
|
26
49
|
* const date = createDate('2024-01-01');
|
|
27
50
|
* const utcDate = createDate('2024-01-01', undefined, { utc: true });
|
|
28
51
|
* const tzDate = createDate('2024-01-01', undefined, { timezone: 'Asia/Kolkata' });
|
|
29
52
|
* ```
|
|
30
53
|
*/
|
|
31
|
-
export declare function createDateFactory(customDayjs?: Dayjs):
|
|
32
|
-
createDate: {
|
|
33
|
-
(): ReturnType<Dayjs>;
|
|
34
|
-
(date: CreateDateInput, format?: CreateDateFormat, options?: CreateDateOptions): ReturnType<Dayjs>;
|
|
35
|
-
};
|
|
36
|
-
dayjs: typeof import("dayjs");
|
|
37
|
-
};
|
|
54
|
+
export declare function createDateFactory(customDayjs?: Dayjs): CreateDateFactoryReturn;
|
|
38
55
|
export {};
|
|
39
56
|
//# sourceMappingURL=createDateFactory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDateFactory.d.ts","sourceRoot":"","sources":["../../../src/date-creator/createDateFactory/createDateFactory.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,KAAK,KAAK,GAAG,OAAO,YAAY,CAAC;AAEjC
|
|
1
|
+
{"version":3,"file":"createDateFactory.d.ts","sourceRoot":"","sources":["../../../src/date-creator/createDateFactory/createDateFactory.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,KAAK,KAAK,GAAG,OAAO,YAAY,CAAC;AAEjC;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;;;;OAMG;IACH,UAAU,EAAE;QACV,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;QACtB,CACE,IAAI,EAAE,eAAe,EACrB,MAAM,CAAC,EAAE,gBAAgB,EACzB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,UAAU,CAAC,KAAK,CAAC,CAAC;KACtB,CAAC;IAEF;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,iBAAiB,CAC/B,WAAW,CAAC,EAAE,KAAK,GAClB,uBAAuB,CA4CzB"}
|
|
@@ -13,7 +13,7 @@ import defaultDayjs from './dayjs.js';
|
|
|
13
13
|
*
|
|
14
14
|
* @param customDayjs - Optional custom Dayjs instance (useful for testing or plugin overrides)
|
|
15
15
|
*
|
|
16
|
-
* @returns
|
|
16
|
+
* @returns A factory object containing:
|
|
17
17
|
* - `createDate`: Unified date creation function
|
|
18
18
|
* - `dayjs`: The underlying Dayjs instance used by the factory
|
|
19
19
|
*
|
|
@@ -21,6 +21,7 @@ import defaultDayjs from './dayjs.js';
|
|
|
21
21
|
* ```ts
|
|
22
22
|
* const { createDate } = createDateFactory();
|
|
23
23
|
*
|
|
24
|
+
* const now = createDate();
|
|
24
25
|
* const date = createDate('2024-01-01');
|
|
25
26
|
* const utcDate = createDate('2024-01-01', undefined, { utc: true });
|
|
26
27
|
* const tzDate = createDate('2024-01-01', undefined, { timezone: 'Asia/Kolkata' });
|
|
@@ -28,31 +29,6 @@ import defaultDayjs from './dayjs.js';
|
|
|
28
29
|
*/
|
|
29
30
|
export function createDateFactory(customDayjs) {
|
|
30
31
|
const d = customDayjs ?? defaultDayjs;
|
|
31
|
-
/**
|
|
32
|
-
* Creates a Dayjs date instance with optional parsing rules.
|
|
33
|
-
*
|
|
34
|
-
* Overloads:
|
|
35
|
-
* - `createDate()` → current date/time
|
|
36
|
-
* - `createDate(input, format?, options?)` → parsed date
|
|
37
|
-
*
|
|
38
|
-
* @param date - Date input (string, number, Date, Dayjs, etc.)
|
|
39
|
-
* @param format - Optional format string for parsing
|
|
40
|
-
* @param options - Parsing and behavior options
|
|
41
|
-
*
|
|
42
|
-
* @returns A Dayjs instance
|
|
43
|
-
*
|
|
44
|
-
* @throws Error if `throwOnInvalid` is true and the date is invalid
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```ts
|
|
48
|
-
* createDate(); // now
|
|
49
|
-
* createDate('2024-01-01');
|
|
50
|
-
* createDate('01-01-2024', 'DD-MM-YYYY');
|
|
51
|
-
*
|
|
52
|
-
* createDate('2024-01-01', undefined, { utc: true });
|
|
53
|
-
* createDate('2024-01-01', undefined, { timezone: 'UTC' });
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
32
|
function createDate(date, format, options = {}) {
|
|
57
33
|
const { timezone, utc, strict = false, throwOnInvalid = false } = options;
|
|
58
34
|
const input = date ?? undefined;
|
package/esm/mod.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { timeout } from './timeout/timeout.js';
|
|
2
2
|
export { createDate } from './date-creator/createDate/createDate.js';
|
|
3
|
-
export { createDateFactory } from './date-creator/createDateFactory/createDateFactory.js';
|
|
3
|
+
export { createDateFactory, type CreateDateFactoryReturn, } from './date-creator/createDateFactory/createDateFactory.js';
|
|
4
4
|
export type { CreateDateFormat, CreateDateInput, CreateDateOptions, } from './date-creator/createDateFactory/types.js';
|
|
5
5
|
//# sourceMappingURL=mod.d.ts.map
|
package/esm/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AAErE,OAAO,
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AAErE,OAAO,EACL,iBAAiB,EACjB,KAAK,uBAAuB,GAC7B,MAAM,uDAAuD,CAAC;AAE/D,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,iBAAiB,GAClB,MAAM,2CAA2C,CAAC"}
|
package/esm/mod.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { timeout } from './timeout/timeout.js';
|
|
2
2
|
export { createDate } from './date-creator/createDate/createDate.js';
|
|
3
|
-
export { createDateFactory } from './date-creator/createDateFactory/createDateFactory.js';
|
|
3
|
+
export { createDateFactory, } from './date-creator/createDateFactory/createDateFactory.js';
|
package/package.json
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
declare const createDate: {
|
|
2
|
-
(): ReturnType<typeof import("dayjs")>;
|
|
3
|
-
(date: import("../createDateFactory/types.js").CreateDateInput, format?: import("../createDateFactory/types.js").CreateDateFormat, options?: import("../createDateFactory/types.js").CreateDateOptions): ReturnType<typeof import("dayjs")>;
|
|
4
|
-
};
|
|
5
1
|
/**
|
|
6
|
-
* Default preconfigured
|
|
7
|
-
*
|
|
8
|
-
* Provides a ready-to-use API with UTC, timezone, and custom parsing support
|
|
9
|
-
* without requiring users to configure Dayjs manually.
|
|
2
|
+
* Default preconfigured createDate function.
|
|
10
3
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* createDate();
|
|
14
|
-
* createDate('2024-01-01');
|
|
15
|
-
* createDate('2024-01-01', undefined, { utc: true });
|
|
16
|
-
* ```
|
|
4
|
+
* This is a ready-to-use version of `createDate` that uses a shared,
|
|
5
|
+
* preconfigured Dayjs instance. No manual configuration is required.
|
|
17
6
|
*/
|
|
18
|
-
export
|
|
7
|
+
export declare const createDate: {
|
|
8
|
+
(): ReturnType<typeof import("dayjs")>;
|
|
9
|
+
(date: import("../createDateFactory/types.js").CreateDateInput, format?: import("../createDateFactory/types.js").CreateDateFormat, options?: import("../createDateFactory/types.js").CreateDateOptions): ReturnType<typeof import("dayjs")>;
|
|
10
|
+
};
|
|
19
11
|
//# sourceMappingURL=createDate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDate.d.ts","sourceRoot":"","sources":["../../../src/date-creator/createDate/createDate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createDate.d.ts","sourceRoot":"","sources":["../../../src/date-creator/createDate/createDate.ts"],"names":[],"mappings":"AAYA;;;;;GAKG;AACH,eAAO,MAAM,UAAU;;;CAAyB,CAAC"}
|
|
@@ -6,5 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.createDate = void 0;
|
|
7
7
|
const createDateFactory_js_1 = require("../createDateFactory/createDateFactory.js");
|
|
8
8
|
const dayjs_js_1 = __importDefault(require("../createDateFactory/dayjs.js"));
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Preconfigured date factory instance using the default Dayjs setup.
|
|
11
|
+
*
|
|
12
|
+
* This instance is shared internally to provide a consistent date API
|
|
13
|
+
* without requiring users to configure Dayjs manually.
|
|
14
|
+
*/
|
|
15
|
+
const dateFactory = (0, createDateFactory_js_1.createDateFactory)(dayjs_js_1.default);
|
|
16
|
+
/**
|
|
17
|
+
* Default preconfigured createDate function.
|
|
18
|
+
*
|
|
19
|
+
* This is a ready-to-use version of `createDate` that uses a shared,
|
|
20
|
+
* preconfigured Dayjs instance. No manual configuration is required.
|
|
21
|
+
*/
|
|
22
|
+
exports.createDate = dateFactory.createDate;
|
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import defaultDayjs from './dayjs.js';
|
|
2
2
|
import type { CreateDateFormat, CreateDateInput, CreateDateOptions } from './types.js';
|
|
3
3
|
type Dayjs = typeof defaultDayjs;
|
|
4
|
+
/**
|
|
5
|
+
* Return type of `createDateFactory`.
|
|
6
|
+
*
|
|
7
|
+
* Contains the unified date creation function and the underlying Dayjs instance.
|
|
8
|
+
*/
|
|
9
|
+
export type CreateDateFactoryReturn = {
|
|
10
|
+
/**
|
|
11
|
+
* Unified date creation function.
|
|
12
|
+
*
|
|
13
|
+
* Overloads:
|
|
14
|
+
* - `createDate()` → current date/time
|
|
15
|
+
* - `createDate(input, format?, options?)` → parsed date
|
|
16
|
+
*/
|
|
17
|
+
createDate: {
|
|
18
|
+
(): ReturnType<Dayjs>;
|
|
19
|
+
(date: CreateDateInput, format?: CreateDateFormat, options?: CreateDateOptions): ReturnType<Dayjs>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Underlying Dayjs instance used by this factory.
|
|
23
|
+
*/
|
|
24
|
+
dayjs: Dayjs;
|
|
25
|
+
};
|
|
4
26
|
/**
|
|
5
27
|
* Creates a date factory bound to a specific Dayjs instance.
|
|
6
28
|
*
|
|
@@ -15,7 +37,7 @@ type Dayjs = typeof defaultDayjs;
|
|
|
15
37
|
*
|
|
16
38
|
* @param customDayjs - Optional custom Dayjs instance (useful for testing or plugin overrides)
|
|
17
39
|
*
|
|
18
|
-
* @returns
|
|
40
|
+
* @returns A factory object containing:
|
|
19
41
|
* - `createDate`: Unified date creation function
|
|
20
42
|
* - `dayjs`: The underlying Dayjs instance used by the factory
|
|
21
43
|
*
|
|
@@ -23,17 +45,12 @@ type Dayjs = typeof defaultDayjs;
|
|
|
23
45
|
* ```ts
|
|
24
46
|
* const { createDate } = createDateFactory();
|
|
25
47
|
*
|
|
48
|
+
* const now = createDate();
|
|
26
49
|
* const date = createDate('2024-01-01');
|
|
27
50
|
* const utcDate = createDate('2024-01-01', undefined, { utc: true });
|
|
28
51
|
* const tzDate = createDate('2024-01-01', undefined, { timezone: 'Asia/Kolkata' });
|
|
29
52
|
* ```
|
|
30
53
|
*/
|
|
31
|
-
export declare function createDateFactory(customDayjs?: Dayjs):
|
|
32
|
-
createDate: {
|
|
33
|
-
(): ReturnType<Dayjs>;
|
|
34
|
-
(date: CreateDateInput, format?: CreateDateFormat, options?: CreateDateOptions): ReturnType<Dayjs>;
|
|
35
|
-
};
|
|
36
|
-
dayjs: typeof import("dayjs");
|
|
37
|
-
};
|
|
54
|
+
export declare function createDateFactory(customDayjs?: Dayjs): CreateDateFactoryReturn;
|
|
38
55
|
export {};
|
|
39
56
|
//# sourceMappingURL=createDateFactory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDateFactory.d.ts","sourceRoot":"","sources":["../../../src/date-creator/createDateFactory/createDateFactory.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,KAAK,KAAK,GAAG,OAAO,YAAY,CAAC;AAEjC
|
|
1
|
+
{"version":3,"file":"createDateFactory.d.ts","sourceRoot":"","sources":["../../../src/date-creator/createDateFactory/createDateFactory.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,KAAK,KAAK,GAAG,OAAO,YAAY,CAAC;AAEjC;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;;;;OAMG;IACH,UAAU,EAAE;QACV,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;QACtB,CACE,IAAI,EAAE,eAAe,EACrB,MAAM,CAAC,EAAE,gBAAgB,EACzB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,UAAU,CAAC,KAAK,CAAC,CAAC;KACtB,CAAC;IAEF;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,iBAAiB,CAC/B,WAAW,CAAC,EAAE,KAAK,GAClB,uBAAuB,CA4CzB"}
|
|
@@ -19,7 +19,7 @@ const dayjs_js_1 = __importDefault(require("./dayjs.js"));
|
|
|
19
19
|
*
|
|
20
20
|
* @param customDayjs - Optional custom Dayjs instance (useful for testing or plugin overrides)
|
|
21
21
|
*
|
|
22
|
-
* @returns
|
|
22
|
+
* @returns A factory object containing:
|
|
23
23
|
* - `createDate`: Unified date creation function
|
|
24
24
|
* - `dayjs`: The underlying Dayjs instance used by the factory
|
|
25
25
|
*
|
|
@@ -27,6 +27,7 @@ const dayjs_js_1 = __importDefault(require("./dayjs.js"));
|
|
|
27
27
|
* ```ts
|
|
28
28
|
* const { createDate } = createDateFactory();
|
|
29
29
|
*
|
|
30
|
+
* const now = createDate();
|
|
30
31
|
* const date = createDate('2024-01-01');
|
|
31
32
|
* const utcDate = createDate('2024-01-01', undefined, { utc: true });
|
|
32
33
|
* const tzDate = createDate('2024-01-01', undefined, { timezone: 'Asia/Kolkata' });
|
|
@@ -34,31 +35,6 @@ const dayjs_js_1 = __importDefault(require("./dayjs.js"));
|
|
|
34
35
|
*/
|
|
35
36
|
function createDateFactory(customDayjs) {
|
|
36
37
|
const d = customDayjs ?? dayjs_js_1.default;
|
|
37
|
-
/**
|
|
38
|
-
* Creates a Dayjs date instance with optional parsing rules.
|
|
39
|
-
*
|
|
40
|
-
* Overloads:
|
|
41
|
-
* - `createDate()` → current date/time
|
|
42
|
-
* - `createDate(input, format?, options?)` → parsed date
|
|
43
|
-
*
|
|
44
|
-
* @param date - Date input (string, number, Date, Dayjs, etc.)
|
|
45
|
-
* @param format - Optional format string for parsing
|
|
46
|
-
* @param options - Parsing and behavior options
|
|
47
|
-
*
|
|
48
|
-
* @returns A Dayjs instance
|
|
49
|
-
*
|
|
50
|
-
* @throws Error if `throwOnInvalid` is true and the date is invalid
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```ts
|
|
54
|
-
* createDate(); // now
|
|
55
|
-
* createDate('2024-01-01');
|
|
56
|
-
* createDate('01-01-2024', 'DD-MM-YYYY');
|
|
57
|
-
*
|
|
58
|
-
* createDate('2024-01-01', undefined, { utc: true });
|
|
59
|
-
* createDate('2024-01-01', undefined, { timezone: 'UTC' });
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
38
|
function createDate(date, format, options = {}) {
|
|
63
39
|
const { timezone, utc, strict = false, throwOnInvalid = false } = options;
|
|
64
40
|
const input = date ?? undefined;
|
package/script/mod.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { timeout } from './timeout/timeout.js';
|
|
2
2
|
export { createDate } from './date-creator/createDate/createDate.js';
|
|
3
|
-
export { createDateFactory } from './date-creator/createDateFactory/createDateFactory.js';
|
|
3
|
+
export { createDateFactory, type CreateDateFactoryReturn, } from './date-creator/createDateFactory/createDateFactory.js';
|
|
4
4
|
export type { CreateDateFormat, CreateDateInput, CreateDateOptions, } from './date-creator/createDateFactory/types.js';
|
|
5
5
|
//# sourceMappingURL=mod.d.ts.map
|
package/script/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AAErE,OAAO,
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AAErE,OAAO,EACL,iBAAiB,EACjB,KAAK,uBAAuB,GAC7B,MAAM,uDAAuD,CAAC;AAE/D,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,iBAAiB,GAClB,MAAM,2CAA2C,CAAC"}
|