nhb-toolbox 3.8.1 → 3.8.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/array/sort.d.ts.map +1 -1
- package/dist/array/sort.js +5 -4
- package/dist/array/types.d.ts +7 -0
- package/dist/array/types.d.ts.map +1 -1
- package/dist/array/utils.d.ts +14 -0
- package/dist/array/utils.d.ts.map +1 -0
- package/dist/array/utils.js +78 -0
- package/dist/date/Chronos.d.ts +36 -6
- package/dist/date/Chronos.d.ts.map +1 -1
- package/dist/date/Chronos.js +86 -18
- package/dist/date/constants.d.ts +5 -3
- package/dist/date/constants.d.ts.map +1 -1
- package/dist/date/constants.js +58 -2
- package/dist/date/types.d.ts +66 -3
- package/dist/date/types.d.ts.map +1 -1
- package/dist/date/utils.d.ts +7 -0
- package/dist/date/utils.d.ts.map +1 -1
- package/dist/date/utils.js +13 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/number/utilities.d.ts +12 -0
- package/dist/number/utilities.d.ts.map +1 -1
- package/dist/number/utilities.js +28 -0
- package/package.json +1 -1
package/dist/array/sort.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../../src/array/sort.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAe,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../../src/array/sort.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAe,MAAM,SAAS,CAAC;AAGtE;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,aAAa,EAClD,KAAK,EAAE,CAAC,EAAE,EACV,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GACtB,CAAC,EAAE,CAAC;AAEP;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,OAAO,EAC9D,KAAK,EAAE,CAAC,EAAE,EACV,OAAO,CAAC,EAAE,WAAW,GACnB,CAAC,EAAE,CAAC"}
|
package/dist/array/sort.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isArrayOfType, isObject, isValidArray, } from '../guards/non-primitives';
|
|
2
2
|
import { isBoolean, isNumber, isString } from '../guards/primitives';
|
|
3
|
+
import { naturalSort } from './utils';
|
|
3
4
|
/**
|
|
4
5
|
* * Sorts an array of strings, numbers, booleans, or objects based on the provided options.
|
|
5
6
|
*
|
|
@@ -18,8 +19,8 @@ export function sortAnArray(array, options) {
|
|
|
18
19
|
// Check if the array contains strings
|
|
19
20
|
if (isArrayOfType(array, isString)) {
|
|
20
21
|
return [...array].sort((a, b) => options?.sortOrder === 'desc' ?
|
|
21
|
-
b
|
|
22
|
-
: a
|
|
22
|
+
naturalSort(b, a)
|
|
23
|
+
: naturalSort(a, b));
|
|
23
24
|
}
|
|
24
25
|
// Check if the array contains numbers
|
|
25
26
|
if (isArrayOfType(array, isNumber)) {
|
|
@@ -46,8 +47,8 @@ export function sortAnArray(array, options) {
|
|
|
46
47
|
}
|
|
47
48
|
if (typeof keyA === 'string' && typeof keyB === 'string') {
|
|
48
49
|
return options?.sortOrder === 'desc' ?
|
|
49
|
-
keyB
|
|
50
|
-
: keyA
|
|
50
|
+
naturalSort(keyB, keyA)
|
|
51
|
+
: naturalSort(keyA, keyB);
|
|
51
52
|
}
|
|
52
53
|
if (typeof keyA === 'number' && typeof keyB === 'number') {
|
|
53
54
|
return options?.sortOrder === 'desc' ?
|
package/dist/array/types.d.ts
CHANGED
|
@@ -50,4 +50,11 @@ export interface SortByOption<T extends GenericObject> extends OrderOption {
|
|
|
50
50
|
}
|
|
51
51
|
/** * Options for sorting array. */
|
|
52
52
|
export type SortOptions<T> = T extends GenericObject ? SortByOption<T> : OrderOption;
|
|
53
|
+
/** Optional settings to configure comparison behavior. */
|
|
54
|
+
export interface SortNature {
|
|
55
|
+
/** If true, compares string chunks without case sensitivity. Defaults to `true`. */
|
|
56
|
+
caseInsensitive?: boolean;
|
|
57
|
+
/** If true, uses localeCompare for string chunk comparisons. Defaults to `false`. */
|
|
58
|
+
localeAware?: boolean;
|
|
59
|
+
}
|
|
53
60
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/array/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,uCAAuC;AACvC,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAEpE;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE;IACvC;;;OAGG;IACH,aAAa,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAE/B;;;OAGG;IACH,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAEhC;;;;OAIG;IACH,cAAc,CAAC,EAAE,EAAE,CAAC;IAEpB;;;;OAIG;IACH,eAAe,CAAC,EAAE,EAAE,CAAC;CACrB;AAED,kCAAkC;AAClC,MAAM,WAAW,WAAW;IAC3B;;;;OAIG;IACH,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;CAC3B;AAED,yEAAyE;AACzE,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,aAAa,CAA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CAAC,GAAG,WAAW,CAAC;AAEzD,0DAA0D;AAC1D,MAAM,WAAW,UAAU;IAC1B,oFAAoF;IACpF,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,qFAAqF;IACrF,WAAW,CAAC,EAAE,OAAO,CAAC;CACtB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SortNature } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* * Compare two strings using natural sorting (e.g., "file2" < "file10").
|
|
4
|
+
* Optionally supports case-insensitive and locale-aware string chunk comparisons.
|
|
5
|
+
*
|
|
6
|
+
* @param a - The first string to compare.
|
|
7
|
+
* @param b - The second string to compare.
|
|
8
|
+
* @param options - Optional settings to configure comparison behavior.
|
|
9
|
+
* @param options.caseInsensitive - If true, compares string chunks without case sensitivity. Defaults to `true`.
|
|
10
|
+
* @param options.localeAware - If true, uses localeCompare for string chunk comparisons. Defaults to `false`.
|
|
11
|
+
* @returns A negative number if `a` comes before `b`, a positive number if `a` comes after `b`, or 0 if equal.
|
|
12
|
+
*/
|
|
13
|
+
export declare function naturalSort(a: string, b: string, options?: SortNature): number;
|
|
14
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/array/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAC1B,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,OAAO,CAAC,EAAE,UAAU,GAClB,MAAM,CAgFR"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* * Compare two strings using natural sorting (e.g., "file2" < "file10").
|
|
3
|
+
* Optionally supports case-insensitive and locale-aware string chunk comparisons.
|
|
4
|
+
*
|
|
5
|
+
* @param a - The first string to compare.
|
|
6
|
+
* @param b - The second string to compare.
|
|
7
|
+
* @param options - Optional settings to configure comparison behavior.
|
|
8
|
+
* @param options.caseInsensitive - If true, compares string chunks without case sensitivity. Defaults to `true`.
|
|
9
|
+
* @param options.localeAware - If true, uses localeCompare for string chunk comparisons. Defaults to `false`.
|
|
10
|
+
* @returns A negative number if `a` comes before `b`, a positive number if `a` comes after `b`, or 0 if equal.
|
|
11
|
+
*/
|
|
12
|
+
export function naturalSort(a, b, options) {
|
|
13
|
+
const { caseInsensitive = true, localeAware = false } = options || {};
|
|
14
|
+
/**
|
|
15
|
+
* * Splits a string into an array of number and non-number chunks.
|
|
16
|
+
* @param str - The string to split.
|
|
17
|
+
* @returns An array of string and number parts.
|
|
18
|
+
*/
|
|
19
|
+
const _createChunks = (str) => {
|
|
20
|
+
const chunks = [];
|
|
21
|
+
let current = '';
|
|
22
|
+
let isNumeric = false;
|
|
23
|
+
for (const char of str) {
|
|
24
|
+
const charIsNum = !Number.isNaN(Number(char));
|
|
25
|
+
if (current.length === 0) {
|
|
26
|
+
current = char;
|
|
27
|
+
isNumeric = charIsNum;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (charIsNum === isNumeric) {
|
|
31
|
+
current += char;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
chunks.push(isNumeric ? Number(current) : current);
|
|
35
|
+
current = char;
|
|
36
|
+
isNumeric = charIsNum;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (current.length > 0) {
|
|
40
|
+
chunks.push(isNumeric ? Number(current) : current);
|
|
41
|
+
}
|
|
42
|
+
return chunks;
|
|
43
|
+
};
|
|
44
|
+
const aChunks = _createChunks(a);
|
|
45
|
+
const bChunks = _createChunks(b);
|
|
46
|
+
for (let i = 0; i < Math.min(aChunks.length, bChunks.length); i++) {
|
|
47
|
+
let aChunk = aChunks[i];
|
|
48
|
+
let bChunk = bChunks[i];
|
|
49
|
+
// Normalize string chunks if case-insensitive
|
|
50
|
+
if (caseInsensitive &&
|
|
51
|
+
typeof aChunk === 'string' &&
|
|
52
|
+
typeof bChunk === 'string') {
|
|
53
|
+
aChunk = aChunk.toLowerCase();
|
|
54
|
+
bChunk = bChunk.toLowerCase();
|
|
55
|
+
}
|
|
56
|
+
// Compare types: number vs string
|
|
57
|
+
if (typeof aChunk !== typeof bChunk) {
|
|
58
|
+
return typeof aChunk === 'string' ? 1 : -1;
|
|
59
|
+
}
|
|
60
|
+
// Compare same-type chunks
|
|
61
|
+
if (aChunk !== bChunk) {
|
|
62
|
+
if (typeof aChunk === 'number' && typeof bChunk === 'number') {
|
|
63
|
+
return aChunk - bChunk;
|
|
64
|
+
}
|
|
65
|
+
if (typeof aChunk === 'string' && typeof bChunk === 'string') {
|
|
66
|
+
if (localeAware) {
|
|
67
|
+
const cmp = aChunk.localeCompare(bChunk, undefined, {
|
|
68
|
+
sensitivity: caseInsensitive ? 'accent' : 'variant',
|
|
69
|
+
});
|
|
70
|
+
if (cmp !== 0)
|
|
71
|
+
return cmp;
|
|
72
|
+
}
|
|
73
|
+
return aChunk < bChunk ? -1 : 1;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return aChunks.length - bChunks.length;
|
|
78
|
+
}
|
package/dist/date/Chronos.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export declare class Chronos {
|
|
|
44
44
|
get isoMonth(): number;
|
|
45
45
|
/** Gets the time value in milliseconds since midnight, January 1, 1970 UTC. */
|
|
46
46
|
get unix(): number;
|
|
47
|
-
/** @public @instance Returns a debug-friendly string for console.log or util.inspect */
|
|
47
|
+
/** @public @instance Returns a debug-friendly string for `console.log` or `util.inspect`. */
|
|
48
48
|
inspect(): string;
|
|
49
49
|
/** @public @instance Clones and returns a new Chronos instance with the same date. */
|
|
50
50
|
clone(): Chronos;
|
|
@@ -72,7 +72,7 @@ export declare class Chronos {
|
|
|
72
72
|
getTimeStamp(): number;
|
|
73
73
|
/**
|
|
74
74
|
* @public @instance Returns the current date and time in a specified format in local time.
|
|
75
|
-
* @description Default format is dd, `
|
|
75
|
+
* @description Default format is dd, `mmm DD, YYYY HH:mm:ss` = `Sun, Apr 06, 2025 16:11:55:379`
|
|
76
76
|
*
|
|
77
77
|
* @param options - Configure format string and whether to format using utc offset.
|
|
78
78
|
* @returns Formatted date string in desired format.
|
|
@@ -81,14 +81,14 @@ export declare class Chronos {
|
|
|
81
81
|
/**
|
|
82
82
|
* @public @instance Formats the date into a custom string format (local time).
|
|
83
83
|
*
|
|
84
|
-
* @param format - The desired format (Default format is `dd,
|
|
84
|
+
* @param format - The desired format (Default format is `dd, mmm DD, YYYY HH:mm:ss:mss` = `Sun, Apr 06, 2025 16:11:55:379`).
|
|
85
85
|
* @param useUTC - Optional `useUTC` to get the formatted time using UTC Offset, defaults to `false`. Equivalent to `formatUTC()` method if set to `true`.
|
|
86
86
|
* @returns Formatted date string in desired format (in local time unless `useUTC` passed as `true`).
|
|
87
87
|
*/
|
|
88
88
|
format(format?: string, useUTC?: boolean): string;
|
|
89
89
|
/**
|
|
90
90
|
* @public @instance Formats the date into a strict custom string format (local time).
|
|
91
|
-
* @description Select from `
|
|
91
|
+
* @description Select from `21,000+` pre-defined formats.
|
|
92
92
|
*
|
|
93
93
|
* @param format - The desired format (Default format is `dd, mmm DD, YYYY HH:mm:ss` = `Sun, Apr 06, 2025 16:11:55`).
|
|
94
94
|
* @param useUTC - Optional `useUTC` to get the formatted time using UTC Offset, defaults to `false`. Equivalent to `formatUTC()` method if set to `true`.
|
|
@@ -98,7 +98,7 @@ export declare class Chronos {
|
|
|
98
98
|
/**
|
|
99
99
|
* @public @instance Formats the date into a custom string format (UTC time).
|
|
100
100
|
*
|
|
101
|
-
* @param format - The desired format (Default format is `dd,
|
|
101
|
+
* @param format - The desired format (Default format is `dd, mmm DD, YYYY HH:mm:ss:mss` = `Sun, Apr 06, 2025 16:11:55:379`).
|
|
102
102
|
* @returns Formatted date string in desired format (UTC time).
|
|
103
103
|
*/
|
|
104
104
|
formatUTC(format?: string): string;
|
|
@@ -322,7 +322,7 @@ export declare class Chronos {
|
|
|
322
322
|
toLocal(): Chronos;
|
|
323
323
|
/**
|
|
324
324
|
* @public @static Returns the current date and time in a specified format in local time.
|
|
325
|
-
* * Default format is dd, `
|
|
325
|
+
* * Default format is dd, `mmm DD, YYYY HH:mm:ss` = `Sun, Apr 06, 2025 16:11:55:379`
|
|
326
326
|
* @param options - Configure format string and whether to format using utc offset.
|
|
327
327
|
* @returns Formatted date string in desired format.
|
|
328
328
|
*/
|
|
@@ -350,5 +350,35 @@ export declare class Chronos {
|
|
|
350
350
|
* @param dates Date inputs.
|
|
351
351
|
*/
|
|
352
352
|
static max(...dates: (number | string | Date | Chronos)[]): Chronos;
|
|
353
|
+
/**
|
|
354
|
+
* @public @static Checks if the year in the date string is a leap year.
|
|
355
|
+
* - A year is a leap year if it is divisible by 4, but not divisible by 100, unless it is also divisible by 400.
|
|
356
|
+
* - For example, 2000 and 2400 are leap years, but 1900 and 2100 are not.
|
|
357
|
+
* @returns `true` if the year is a leap year, `false` otherwise.
|
|
358
|
+
*/
|
|
359
|
+
static isLeapYear(date: number | string | Date | Chronos): boolean;
|
|
360
|
+
/**
|
|
361
|
+
* @public @static Checks if the given value is a valid `Date` object.
|
|
362
|
+
* - A value is considered valid if it is an instance of the built-in `Date` class.
|
|
363
|
+
* - This does not check whether the date itself is valid (e.g., `new Date('invalid')`).
|
|
364
|
+
* @param value - The value to test.
|
|
365
|
+
* @returns `true` if the value is a valid Date object, otherwise `false`.
|
|
366
|
+
*/
|
|
367
|
+
static isValidDate(value: unknown): value is Date;
|
|
368
|
+
/**
|
|
369
|
+
* @public @static Checks if the given value is a valid date string.
|
|
370
|
+
* - A value is considered a valid date string if it is a string and can be parsed by `Date.parse()`.
|
|
371
|
+
* - This uses the native JavaScript date parser internally.
|
|
372
|
+
* @param value - The value to test.
|
|
373
|
+
* @returns `true` if the value is a valid date string, otherwise `false`.
|
|
374
|
+
*/
|
|
375
|
+
static isDateString(value: unknown): value is string;
|
|
376
|
+
/**
|
|
377
|
+
* @public @static Checks if the given value is an instance of `Chronos`.
|
|
378
|
+
* - Useful for verifying Chronos objects in type guards or validations.
|
|
379
|
+
* @param value - The value to test.
|
|
380
|
+
* @returns `true` if the value is an instance of `Chronos`, otherwise `false`.
|
|
381
|
+
*/
|
|
382
|
+
static isValidChronos(value: unknown): value is Chronos;
|
|
353
383
|
}
|
|
354
384
|
//# sourceMappingURL=Chronos.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chronos.d.ts","sourceRoot":"","sources":["../../src/date/Chronos.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Chronos.d.ts","sourceRoot":"","sources":["../../src/date/Chronos.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,EAGN,MAAM,EAIN,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAEX,cAAc,EACd,aAAa,EACb,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,MAAM,SAAS,CAAC;AAGjB,qBAAa,OAAO;;IAGnB,CAAC,MAAM,CAAC,CAAC,EAAE,cAAc,GAAG,MAAM,CAAC;IAEnC;;;;;;;;OAQG;gBACS,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO;IAQnD,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAaxD;;;;OAIG;IACH,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM;IAKnD,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAajC;IA0HD,sCAAsC;IACtC,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,yCAAyC;IACzC,IAAI,KAAK,IAAI,MAAM,CAElB;IA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AAM,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IA6CtD;;;OAGG;IACH,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,GAAG,OAAO;IAM/D;;;OAGG;IACH,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,EAAE,GAAG,OAAO;IAMnE;;;OAGG;IACH,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,EAAE,GAAG,OAAO;IAMnE;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,GAAG,OAAO;IAMlE;;;;;;OAMG;IACH,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,IAAI;IAIjD;;;;;;OAMG;IACH,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM;IAIpD;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO;CAGvD"}
|
package/dist/date/Chronos.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isString } from '../guards/primitives';
|
|
2
|
+
import { getOrdinal } from '../number/utilities';
|
|
3
|
+
import { DAYS, MONTHS, ORIGIN, sortedFormats, TIME_ZONE_LABELS, TIME_ZONES, } from './constants';
|
|
2
4
|
import { isValidUTCOffSet } from './guards';
|
|
3
|
-
import { extractMinutesFromUTC } from './utils';
|
|
5
|
+
import { extractMinutesFromUTC, formatUTCOffset } from './utils';
|
|
4
6
|
export class Chronos {
|
|
5
7
|
#date;
|
|
8
|
+
#offset;
|
|
6
9
|
[ORIGIN];
|
|
7
10
|
/**
|
|
8
11
|
* * Creates a new immutable `Chronos` instance.
|
|
@@ -17,6 +20,7 @@ export class Chronos {
|
|
|
17
20
|
const date = this.#toNewDate(value);
|
|
18
21
|
this.#date = date;
|
|
19
22
|
this[ORIGIN] = 'root';
|
|
23
|
+
this.#offset = `UTC${this.getUTCOffset()}`;
|
|
20
24
|
}
|
|
21
25
|
*[Symbol.iterator]() {
|
|
22
26
|
yield ['year', this.year];
|
|
@@ -42,6 +46,8 @@ export class Chronos {
|
|
|
42
46
|
}
|
|
43
47
|
get [Symbol.toStringTag]() {
|
|
44
48
|
switch (this[ORIGIN]) {
|
|
49
|
+
case 'timeZone':
|
|
50
|
+
return this.toISOString().replace('Z', this.#offset.slice(3));
|
|
45
51
|
case 'toUTC':
|
|
46
52
|
case 'utc':
|
|
47
53
|
return this.#toLocalISOString().replace(this.getUTCOffset(), 'Z');
|
|
@@ -50,9 +56,11 @@ export class Chronos {
|
|
|
50
56
|
}
|
|
51
57
|
}
|
|
52
58
|
/** @private @instance Method to tag origin of the `Chronos` instance. */
|
|
53
|
-
#withOrigin(origin) {
|
|
59
|
+
#withOrigin(origin, offset) {
|
|
54
60
|
const instance = new Chronos(this.#date);
|
|
55
61
|
instance[ORIGIN] = origin;
|
|
62
|
+
if (offset)
|
|
63
|
+
instance.#offset = offset;
|
|
56
64
|
return instance;
|
|
57
65
|
}
|
|
58
66
|
/**
|
|
@@ -95,8 +103,6 @@ export class Chronos {
|
|
|
95
103
|
yy: String(year).slice(-2),
|
|
96
104
|
M: String(month + 1),
|
|
97
105
|
MM: String(month + 1).padStart(2, '0'),
|
|
98
|
-
MMM: MONTHS[month].slice(0, 3),
|
|
99
|
-
MMMM: MONTHS[month],
|
|
100
106
|
mmm: MONTHS[month].slice(0, 3),
|
|
101
107
|
mmmm: MONTHS[month],
|
|
102
108
|
d: DAYS[day].slice(0, 2),
|
|
@@ -104,6 +110,7 @@ export class Chronos {
|
|
|
104
110
|
ddd: DAYS[day],
|
|
105
111
|
D: String(date),
|
|
106
112
|
DD: String(date).padStart(2, '0'),
|
|
113
|
+
Do: getOrdinal(date),
|
|
107
114
|
H: String(hours),
|
|
108
115
|
HH: String(hours).padStart(2, '0'),
|
|
109
116
|
h: String(hours % 12 || 12),
|
|
@@ -193,7 +200,7 @@ export class Chronos {
|
|
|
193
200
|
get unix() {
|
|
194
201
|
return this.#date.getTime();
|
|
195
202
|
}
|
|
196
|
-
/** @public @instance Returns a debug-friendly string for console.log or util.inspect */
|
|
203
|
+
/** @public @instance Returns a debug-friendly string for `console.log` or `util.inspect`. */
|
|
197
204
|
inspect() {
|
|
198
205
|
return `[Chronos ${this.toLocalISOString()}]`;
|
|
199
206
|
}
|
|
@@ -211,11 +218,27 @@ export class Chronos {
|
|
|
211
218
|
}
|
|
212
219
|
/** @public @instance Gets the native `Date` instance (read-only). */
|
|
213
220
|
toDate() {
|
|
214
|
-
|
|
221
|
+
switch (this[ORIGIN]) {
|
|
222
|
+
case 'toUTC':
|
|
223
|
+
case 'utc': {
|
|
224
|
+
const mins = extractMinutesFromUTC(`UTC${this.getUTCOffset()}`);
|
|
225
|
+
const date = this.addMinutes(mins);
|
|
226
|
+
return date.toDate();
|
|
227
|
+
}
|
|
228
|
+
default:
|
|
229
|
+
return new Date(this.#date);
|
|
230
|
+
}
|
|
215
231
|
}
|
|
216
232
|
/** @public @instance Returns a string representation of a date. The format of the string depends on the locale. */
|
|
217
233
|
toString() {
|
|
218
234
|
switch (this[ORIGIN]) {
|
|
235
|
+
case 'timeZone': {
|
|
236
|
+
const gmt = this.#offset.replace('UTC', 'GMT').replace(':', '');
|
|
237
|
+
const label = TIME_ZONE_LABELS[this.#offset] ?? this.#offset;
|
|
238
|
+
return this.#date
|
|
239
|
+
.toString()
|
|
240
|
+
.replace(/GMT[+-]\d{4} \([^)]+\)/, `${gmt} (${label})`);
|
|
241
|
+
}
|
|
219
242
|
case 'toUTC':
|
|
220
243
|
case 'utc': {
|
|
221
244
|
const mins = extractMinutesFromUTC(`UTC${this.getUTCOffset()}`);
|
|
@@ -229,6 +252,7 @@ export class Chronos {
|
|
|
229
252
|
/** @public @instance Returns ISO string with local time zone offset */
|
|
230
253
|
toLocalISOString() {
|
|
231
254
|
switch (this[ORIGIN]) {
|
|
255
|
+
case 'timeZone':
|
|
232
256
|
case 'toUTC':
|
|
233
257
|
case 'utc': {
|
|
234
258
|
const mins = extractMinutesFromUTC(`UTC${this.getUTCOffset()}`);
|
|
@@ -242,6 +266,8 @@ export class Chronos {
|
|
|
242
266
|
/** @public @instance Returns a date as a string value in ISO format. */
|
|
243
267
|
toISOString() {
|
|
244
268
|
switch (this[ORIGIN]) {
|
|
269
|
+
case 'timeZone':
|
|
270
|
+
return this.#toLocalISOString().replace(this.getUTCOffset(), this.#offset.slice(3));
|
|
245
271
|
case 'toUTC':
|
|
246
272
|
case 'utc':
|
|
247
273
|
return this.#toLocalISOString().replace(this.getUTCOffset(), 'Z');
|
|
@@ -265,44 +291,44 @@ export class Chronos {
|
|
|
265
291
|
}
|
|
266
292
|
/**
|
|
267
293
|
* @public @instance Returns the current date and time in a specified format in local time.
|
|
268
|
-
* @description Default format is dd, `
|
|
294
|
+
* @description Default format is dd, `mmm DD, YYYY HH:mm:ss` = `Sun, Apr 06, 2025 16:11:55:379`
|
|
269
295
|
*
|
|
270
296
|
* @param options - Configure format string and whether to format using utc offset.
|
|
271
297
|
* @returns Formatted date string in desired format.
|
|
272
298
|
*/
|
|
273
299
|
today(options) {
|
|
274
|
-
const { format = 'dd,
|
|
300
|
+
const { format = 'dd, mmm DD, YYYY HH:mm:ss', useUTC = false } = options || {};
|
|
275
301
|
const today = new Date();
|
|
276
302
|
return new Chronos(today).#format(format, useUTC);
|
|
277
303
|
}
|
|
278
304
|
/**
|
|
279
305
|
* @public @instance Formats the date into a custom string format (local time).
|
|
280
306
|
*
|
|
281
|
-
* @param format - The desired format (Default format is `dd,
|
|
307
|
+
* @param format - The desired format (Default format is `dd, mmm DD, YYYY HH:mm:ss:mss` = `Sun, Apr 06, 2025 16:11:55:379`).
|
|
282
308
|
* @param useUTC - Optional `useUTC` to get the formatted time using UTC Offset, defaults to `false`. Equivalent to `formatUTC()` method if set to `true`.
|
|
283
309
|
* @returns Formatted date string in desired format (in local time unless `useUTC` passed as `true`).
|
|
284
310
|
*/
|
|
285
|
-
format(format = 'dd,
|
|
311
|
+
format(format = 'dd, mmm DD, YYYY HH:mm:ss:mss', useUTC = false) {
|
|
286
312
|
return this.#format(format, useUTC);
|
|
287
313
|
}
|
|
288
314
|
/**
|
|
289
315
|
* @public @instance Formats the date into a strict custom string format (local time).
|
|
290
|
-
* @description Select from `
|
|
316
|
+
* @description Select from `21,000+` pre-defined formats.
|
|
291
317
|
*
|
|
292
318
|
* @param format - The desired format (Default format is `dd, mmm DD, YYYY HH:mm:ss` = `Sun, Apr 06, 2025 16:11:55`).
|
|
293
319
|
* @param useUTC - Optional `useUTC` to get the formatted time using UTC Offset, defaults to `false`. Equivalent to `formatUTC()` method if set to `true`.
|
|
294
320
|
* @returns Formatted date string in desired strict format (in local time unless `useUTC` passed as `true`).
|
|
295
321
|
*/
|
|
296
322
|
formatStrict(format = 'dd, mmm DD, YYYY HH:mm:ss', useUTC = false) {
|
|
297
|
-
return this
|
|
323
|
+
return this.#format(format, useUTC);
|
|
298
324
|
}
|
|
299
325
|
/**
|
|
300
326
|
* @public @instance Formats the date into a custom string format (UTC time).
|
|
301
327
|
*
|
|
302
|
-
* @param format - The desired format (Default format is `dd,
|
|
328
|
+
* @param format - The desired format (Default format is `dd, mmm DD, YYYY HH:mm:ss:mss` = `Sun, Apr 06, 2025 16:11:55:379`).
|
|
303
329
|
* @returns Formatted date string in desired format (UTC time).
|
|
304
330
|
*/
|
|
305
|
-
formatUTC(format = 'dd,
|
|
331
|
+
formatUTC(format = 'dd, mmm DD, YYYY HH:mm:ss:mss') {
|
|
306
332
|
switch (this[ORIGIN]) {
|
|
307
333
|
case 'toUTC':
|
|
308
334
|
case 'utc':
|
|
@@ -379,15 +405,18 @@ export class Chronos {
|
|
|
379
405
|
*/
|
|
380
406
|
timeZone(zone) {
|
|
381
407
|
let offset;
|
|
408
|
+
let stringOffset;
|
|
382
409
|
if (isValidUTCOffSet(zone)) {
|
|
383
410
|
offset = extractMinutesFromUTC(zone);
|
|
411
|
+
stringOffset = zone;
|
|
384
412
|
}
|
|
385
413
|
else {
|
|
386
414
|
offset = TIME_ZONES[zone] ?? TIME_ZONES['UTC'];
|
|
415
|
+
stringOffset = formatUTCOffset(offset);
|
|
387
416
|
}
|
|
388
417
|
const utc = this.#date.getTime() + this.#date.getTimezoneOffset() * 60 * 1000;
|
|
389
418
|
const adjusted = new Date(utc + offset * 60 * 1000);
|
|
390
|
-
return new Chronos(adjusted).#withOrigin('timeZone');
|
|
419
|
+
return new Chronos(adjusted).#withOrigin('timeZone', stringOffset);
|
|
391
420
|
}
|
|
392
421
|
/**
|
|
393
422
|
* @public @instance Checks if the year is a leap year.
|
|
@@ -951,12 +980,12 @@ export class Chronos {
|
|
|
951
980
|
}
|
|
952
981
|
/**
|
|
953
982
|
* @public @static Returns the current date and time in a specified format in local time.
|
|
954
|
-
* * Default format is dd, `
|
|
983
|
+
* * Default format is dd, `mmm DD, YYYY HH:mm:ss` = `Sun, Apr 06, 2025 16:11:55:379`
|
|
955
984
|
* @param options - Configure format string and whether to format using utc offset.
|
|
956
985
|
* @returns Formatted date string in desired format.
|
|
957
986
|
*/
|
|
958
987
|
static today(options) {
|
|
959
|
-
const { format = 'dd,
|
|
988
|
+
const { format = 'dd, mmm DD, YYYY HH:mm:ss', useUTC = false } = options || {};
|
|
960
989
|
const today = new Date();
|
|
961
990
|
return new Chronos(today).#format(format, useUTC);
|
|
962
991
|
}
|
|
@@ -1017,4 +1046,43 @@ export class Chronos {
|
|
|
1017
1046
|
static max(...dates) {
|
|
1018
1047
|
return new Chronos(Math.max(...dates.map((d) => new Chronos(d).valueOf()))).#withOrigin('max');
|
|
1019
1048
|
}
|
|
1049
|
+
/**
|
|
1050
|
+
* @public @static Checks if the year in the date string is a leap year.
|
|
1051
|
+
* - A year is a leap year if it is divisible by 4, but not divisible by 100, unless it is also divisible by 400.
|
|
1052
|
+
* - For example, 2000 and 2400 are leap years, but 1900 and 2100 are not.
|
|
1053
|
+
* @returns `true` if the year is a leap year, `false` otherwise.
|
|
1054
|
+
*/
|
|
1055
|
+
static isLeapYear(date) {
|
|
1056
|
+
const year = new Chronos(date).year;
|
|
1057
|
+
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
|
1058
|
+
}
|
|
1059
|
+
/**
|
|
1060
|
+
* @public @static Checks if the given value is a valid `Date` object.
|
|
1061
|
+
* - A value is considered valid if it is an instance of the built-in `Date` class.
|
|
1062
|
+
* - This does not check whether the date itself is valid (e.g., `new Date('invalid')`).
|
|
1063
|
+
* @param value - The value to test.
|
|
1064
|
+
* @returns `true` if the value is a valid Date object, otherwise `false`.
|
|
1065
|
+
*/
|
|
1066
|
+
static isValidDate(value) {
|
|
1067
|
+
return value instanceof Date;
|
|
1068
|
+
}
|
|
1069
|
+
/**
|
|
1070
|
+
* @public @static Checks if the given value is a valid date string.
|
|
1071
|
+
* - A value is considered a valid date string if it is a string and can be parsed by `Date.parse()`.
|
|
1072
|
+
* - This uses the native JavaScript date parser internally.
|
|
1073
|
+
* @param value - The value to test.
|
|
1074
|
+
* @returns `true` if the value is a valid date string, otherwise `false`.
|
|
1075
|
+
*/
|
|
1076
|
+
static isDateString(value) {
|
|
1077
|
+
return isString(value) && !isNaN(Date.parse(value));
|
|
1078
|
+
}
|
|
1079
|
+
/**
|
|
1080
|
+
* @public @static Checks if the given value is an instance of `Chronos`.
|
|
1081
|
+
* - Useful for verifying Chronos objects in type guards or validations.
|
|
1082
|
+
* @param value - The value to test.
|
|
1083
|
+
* @returns `true` if the value is an instance of `Chronos`, otherwise `false`.
|
|
1084
|
+
*/
|
|
1085
|
+
static isValidChronos(value) {
|
|
1086
|
+
return value instanceof Chronos;
|
|
1087
|
+
}
|
|
1020
1088
|
}
|
package/dist/date/constants.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
import type { UTCOffSet } from './types';
|
|
1
2
|
export declare const ORIGIN: unique symbol;
|
|
2
3
|
export declare const DAYS: readonly ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
3
4
|
export declare const MONTHS: readonly ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
4
5
|
export declare const YEAR_FORMATS: readonly ["YYYY", "YY", "yyyy", "yy"];
|
|
5
|
-
export declare const MONTH_FORMATS: readonly ["M", "MM", "
|
|
6
|
-
export declare const DATE_FORMATS: readonly ["DD", "D"];
|
|
6
|
+
export declare const MONTH_FORMATS: readonly ["M", "MM", "mmm", "mmmm"];
|
|
7
|
+
export declare const DATE_FORMATS: readonly ["DD", "D", "Do"];
|
|
7
8
|
export declare const DAY_FORMATS: readonly ["d", "dd", "ddd"];
|
|
8
9
|
export declare const HOUR_FORMATS: readonly ["H", "HH", "hh", "h"];
|
|
9
10
|
export declare const MINUTE_FORMATS: readonly ["mm", "m"];
|
|
10
11
|
export declare const SECOND_FORMATS: readonly ["ss", "s"];
|
|
11
12
|
export declare const MILLISECOND_FORMATS: readonly ["ms", "mss"];
|
|
12
13
|
export declare const TIME_FORMATS: readonly ["a", "A"];
|
|
13
|
-
export declare const sortedFormats: ("a" | "M" | "D" | "A" | "YYYY" | "YY" | "yyyy" | "yy" | "MM" | "
|
|
14
|
+
export declare const sortedFormats: ("a" | "M" | "D" | "A" | "YYYY" | "YY" | "yyyy" | "yy" | "MM" | "mmm" | "mmmm" | "DD" | "Do" | "d" | "dd" | "ddd" | "H" | "HH" | "hh" | "h" | "mm" | "m" | "ss" | "s" | "ms" | "mss")[];
|
|
14
15
|
export declare const TIME_ZONES: {
|
|
15
16
|
/** International Date Line West (Baker Island, Howland Island) */
|
|
16
17
|
readonly IDLW: number;
|
|
@@ -289,4 +290,5 @@ export declare const TIME_ZONES: {
|
|
|
289
290
|
/** Petropavlovsk-Kamchatsky Time (Russia) */
|
|
290
291
|
readonly PETT: number;
|
|
291
292
|
};
|
|
293
|
+
export declare const TIME_ZONE_LABELS: Record<UTCOffSet, string>;
|
|
292
294
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/date/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM,eAAmB,CAAC;AAEvC,eAAO,MAAM,IAAI,yFAQP,CAAC;AAEX,eAAO,MAAM,MAAM,qIAaT,CAAC;AAEX,eAAO,MAAM,YAAY,uCAAwC,CAAC;AAClE,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/date/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,eAAO,MAAM,MAAM,eAAmB,CAAC;AAEvC,eAAO,MAAM,IAAI,yFAQP,CAAC;AAEX,eAAO,MAAM,MAAM,qIAaT,CAAC;AAEX,eAAO,MAAM,YAAY,uCAAwC,CAAC;AAClE,eAAO,MAAM,aAAa,qCAAsC,CAAC;AACjE,eAAO,MAAM,YAAY,4BAA6B,CAAC;AACvD,eAAO,MAAM,WAAW,6BAA8B,CAAC;AACvD,eAAO,MAAM,YAAY,iCAAkC,CAAC;AAC5D,eAAO,MAAM,cAAc,sBAAuB,CAAC;AACnD,eAAO,MAAM,cAAc,sBAAuB,CAAC;AACnD,eAAO,MAAM,mBAAmB,wBAAyB,CAAC;AAC1D,eAAO,MAAM,YAAY,qBAAsB,CAAC;AAEhD,eAAO,MAAM,aAAa,yLAUW,CAAC;AAEtC,eAAO,MAAM,UAAU;IAEtB,kEAAkE;;IAElE,sCAAsC;;IAEtC,mDAAmD;;IAEnD,gBAAgB;;IAEhB,iDAAiD;;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export const MONTH_FORMATS = ['M', 'MM', '
|
|
27
|
-
export const DATE_FORMATS = ['DD', 'D'];
|
|
26
|
+
export const MONTH_FORMATS = ['M', 'MM', 'mmm', 'mmmm'];
|
|
27
|
+
export const DATE_FORMATS = ['DD', 'D', 'Do'];
|
|
28
28
|
export const DAY_FORMATS = ['d', 'dd', 'ddd'];
|
|
29
29
|
export const HOUR_FORMATS = ['H', 'HH', 'hh', 'h'];
|
|
30
30
|
export const MINUTE_FORMATS = ['mm', 'm'];
|
|
@@ -326,3 +326,59 @@ export const TIME_ZONES = {
|
|
|
326
326
|
/** Petropavlovsk-Kamchatsky Time (Russia) */
|
|
327
327
|
PETT: 12 * 60,
|
|
328
328
|
};
|
|
329
|
+
export const TIME_ZONE_LABELS = {
|
|
330
|
+
'UTC-12:00': 'Baker Island Time',
|
|
331
|
+
'UTC-11:30': 'Niue Time',
|
|
332
|
+
'UTC-11:00': 'Samoa Standard Time',
|
|
333
|
+
'UTC-10:30': 'Marquesas Time',
|
|
334
|
+
'UTC-10:00': 'Hawaii-Aleutian Standard Time',
|
|
335
|
+
'UTC-09:30': 'Marquesas Time',
|
|
336
|
+
'UTC-09:00': 'Alaska Standard Time',
|
|
337
|
+
'UTC-08:30': 'Pitcairn Standard Time',
|
|
338
|
+
'UTC-08:00': 'Pacific Standard Time',
|
|
339
|
+
'UTC-07:30': 'Mountain Standard Time (Unofficial)',
|
|
340
|
+
'UTC-07:00': 'Mountain Standard Time',
|
|
341
|
+
'UTC-06:30': 'Central America Time (Unofficial)',
|
|
342
|
+
'UTC-06:00': 'Central Standard Time',
|
|
343
|
+
'UTC-05:30': 'Venezuelan Standard Time (Historical)',
|
|
344
|
+
'UTC-05:00': 'Eastern Standard Time',
|
|
345
|
+
'UTC-04:30': 'Venezuelan Standard Time',
|
|
346
|
+
'UTC-04:00': 'Atlantic Standard Time',
|
|
347
|
+
'UTC-03:30': 'Newfoundland Standard Time',
|
|
348
|
+
'UTC-03:00': 'Argentina Standard Time',
|
|
349
|
+
'UTC-02:30': 'Mid-Atlantic Time (Unofficial)',
|
|
350
|
+
'UTC-02:00': 'South Georgia Time',
|
|
351
|
+
'UTC-01:30': 'Azores Time (Unofficial)',
|
|
352
|
+
'UTC-01:00': 'Cape Verde Time',
|
|
353
|
+
'UTC+00:00': 'Greenwich Mean Time',
|
|
354
|
+
'UTC+00:30': 'British Summer Time (Historical)',
|
|
355
|
+
'UTC+01:00': 'Central European Time',
|
|
356
|
+
'UTC+01:30': 'Central Africa Time (Unofficial)',
|
|
357
|
+
'UTC+02:00': 'Eastern European Time',
|
|
358
|
+
'UTC+02:30': 'Israel Standard Time (Historical)',
|
|
359
|
+
'UTC+03:00': 'Arabian Standard Time',
|
|
360
|
+
'UTC+03:30': 'Iran Standard Time',
|
|
361
|
+
'UTC+04:00': 'Gulf Standard Time',
|
|
362
|
+
'UTC+04:30': 'Afghanistan Time',
|
|
363
|
+
'UTC+05:00': 'Pakistan Standard Time',
|
|
364
|
+
'UTC+05:30': 'Indian Standard Time',
|
|
365
|
+
'UTC+05:45': 'Nepal Time',
|
|
366
|
+
'UTC+06:00': 'Bangladesh Standard Time',
|
|
367
|
+
'UTC+06:30': 'Cocos Islands Time',
|
|
368
|
+
'UTC+07:00': 'Indochina Time',
|
|
369
|
+
'UTC+07:30': 'Western Indonesia Time (Unofficial)',
|
|
370
|
+
'UTC+08:00': 'China Standard Time',
|
|
371
|
+
'UTC+08:30': 'North Korea Standard Time',
|
|
372
|
+
'UTC+08:45': 'Australian Central Western Standard Time',
|
|
373
|
+
'UTC+09:00': 'Japan Standard Time',
|
|
374
|
+
'UTC+09:30': 'Australian Central Standard Time',
|
|
375
|
+
'UTC+10:00': 'Australian Eastern Standard Time',
|
|
376
|
+
'UTC+10:30': 'Lord Howe Standard Time',
|
|
377
|
+
'UTC+11:00': 'Solomon Islands Time',
|
|
378
|
+
'UTC+11:30': 'Norfolk Island Time',
|
|
379
|
+
'UTC+12:00': 'New Zealand Standard Time',
|
|
380
|
+
'UTC+12:45': 'Chatham Islands Time',
|
|
381
|
+
'UTC+13:00': 'Phoenix Island Time',
|
|
382
|
+
'UTC+13:45': 'Tokelau Time (Unofficial)',
|
|
383
|
+
'UTC+14:00': 'Line Islands Time',
|
|
384
|
+
};
|
package/dist/date/types.d.ts
CHANGED
|
@@ -48,9 +48,9 @@ export type Second = (typeof SECOND_FORMATS)[number];
|
|
|
48
48
|
export type Millisecond = (typeof MILLISECOND_FORMATS)[number];
|
|
49
49
|
export type TimeFormats = (typeof TIME_FORMATS)[number];
|
|
50
50
|
export type ChronosFormat = Year | Month | Day | Date | Hour | Minute | Second | Millisecond | TimeFormats;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
/** Standard date formats. */
|
|
52
|
+
export type DateParts = `${Date} ${Exclude<Month, 'M' | 'MM'>}` | `${Exclude<Month, 'M' | 'MM'>} ${Date}` | `${Day}, ${Date} ${Exclude<Month, 'M' | 'MM'>}` | `${Day}, ${Exclude<Month, 'M' | 'MM'>} ${Date}` | `${Exclude<Month, 'M' | 'MM'>} ${Date}, ${Year}` | `${Date} ${Exclude<Month, 'M' | 'MM'>}, ${Year}` | `${Exclude<Month, 'M' | 'MM'>} ${Date} ${Year}` | `${Date} ${Exclude<Month, 'M' | 'MM'>} ${Year}` | `${Day}, ${Exclude<Month, 'M' | 'MM'>} ${Date}, ${Year}` | `${Day}, ${Date} ${Exclude<Month, 'M' | 'MM'>}, ${Year}` | `${Day}, ${Exclude<Month, 'M' | 'MM'>} ${Date} ${Year}` | `${Day}, ${Date} ${Exclude<Month, 'M' | 'MM'>} ${Year}` | `${Exclude<Date, 'Do'>}.${Exclude<Month, 'mmm' | 'mmmm'>}.${Year}` | `${Year}.${Exclude<Month, 'mmm' | 'mmmm'>}.${Exclude<Date, 'Do'>}` | `${Exclude<Date, 'Do'>}/${Exclude<Month, 'mmm' | 'mmmm'>}/${Year}` | `${Exclude<Date, 'Do'>}-${Exclude<Month, 'mmm' | 'mmmm'>}-${Year}` | `${Exclude<Month, 'mmm' | 'mmmm'>}/${Exclude<Date, 'Do'>}/${Year}` | `${Exclude<Month, 'mmm' | 'mmmm'>}-${Exclude<Date, 'Do'>}-${Year}` | `${Year}-${Exclude<Month, 'mmm' | 'mmmm'>}-${Exclude<Date, 'Do'>}` | `${Year}/${Exclude<Month, 'mmm' | 'mmmm'>}/${Exclude<Date, 'Do'>}` | `${Year}-${Exclude<Date, 'Do'>}-${Exclude<Month, 'mmm' | 'mmmm'>}` | `${Year}/${Exclude<Date, 'Do'>}/${Exclude<Month, 'mmm' | 'mmmm'>}`;
|
|
53
|
+
/** Standard Time Formats */
|
|
54
54
|
export type TimeParts = `${Exclude<Hour, 'h' | 'hh' | 'H'>}:${Exclude<Minute, 'm'>}` | `${Exclude<Hour, 'H' | 'HH' | 'h'>}:${Exclude<Minute, 'm'>} ${TimeFormats}` | `${Exclude<Hour, 'h' | 'hh' | 'H'>}:${Exclude<Minute, 'm'>}:${Exclude<Second, 's'>}` | `${Exclude<Hour, 'H' | 'HH' | 'h'>}:${Exclude<Minute, 'm'>}:${Exclude<Second, 's'>} ${TimeFormats}` | `${Exclude<Hour, 'h' | 'hh' | 'H'>}:${Exclude<Minute, 'm'>}:${Exclude<Second, 's'>}:${Exclude<Millisecond, 'ms'>}` | `${Exclude<Hour, 'H' | 'HH' | 'h'>}:${Exclude<Minute, 'm'>}:${Exclude<Second, 's'>}:${Exclude<Millisecond, 'ms'>} ${TimeFormats}`;
|
|
55
55
|
type DateTimeConnector = ' ' | ', ' | '; ' | ' - ';
|
|
56
56
|
/** Strict pre-defined types for formatting date and time. */
|
|
@@ -78,6 +78,69 @@ export type ChronosMethods = {
|
|
|
78
78
|
[key in K]: (...args: any[]) => Chronos;
|
|
79
79
|
} ? K : never;
|
|
80
80
|
}[keyof typeof Chronos];
|
|
81
|
+
export interface ChronosStatics {
|
|
82
|
+
(date?: number | string | Date | Chronos): Chronos;
|
|
83
|
+
/**
|
|
84
|
+
* * Returns the current date and time in a specified format in local time.
|
|
85
|
+
* * Default format is dd, `MMM DD, YYYY HH:mm:ss` = `Sun, Apr 06, 2025 16:11:55:379`
|
|
86
|
+
* @param options - Configure format string and whether to format using utc offset.
|
|
87
|
+
* @returns Formatted date string in desired format.
|
|
88
|
+
*/
|
|
89
|
+
today(options?: FormatOptions): string;
|
|
90
|
+
/**
|
|
91
|
+
* * Returns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC).
|
|
92
|
+
* * It basically calls `Date.now()`.
|
|
93
|
+
* @returns The number of milliseconds elapsed since the Unix epoch.
|
|
94
|
+
*/
|
|
95
|
+
now(): number;
|
|
96
|
+
/** * Parses a date string with a given format (partial support) */
|
|
97
|
+
parse(dateStr: string, format: string): Chronos;
|
|
98
|
+
/**
|
|
99
|
+
* * Creates UTC Chronos
|
|
100
|
+
* @param dateLike Date input to create utc time.
|
|
101
|
+
*/
|
|
102
|
+
utc(dateLike: number | string | Date | Chronos): Chronos;
|
|
103
|
+
/**
|
|
104
|
+
* * Returns earliest Chronos
|
|
105
|
+
* @param dates Date inputs.
|
|
106
|
+
*/
|
|
107
|
+
min(...dates: (number | string | Date | Chronos)[]): Chronos;
|
|
108
|
+
/**
|
|
109
|
+
* * Returns latest Chronos
|
|
110
|
+
* @param dates Date inputs.
|
|
111
|
+
*/
|
|
112
|
+
max(...dates: (number | string | Date | Chronos)[]): Chronos;
|
|
113
|
+
/**
|
|
114
|
+
* * Checks if the year in the date string is a leap year.
|
|
115
|
+
* - A year is a leap year if it is divisible by 4, but not divisible by 100, unless it is also divisible by 400.
|
|
116
|
+
* - For example, 2000 and 2400 are leap years, but 1900 and 2100 are not.
|
|
117
|
+
* @returns `true` if the year is a leap year, `false` otherwise.
|
|
118
|
+
*/
|
|
119
|
+
isLeapYear(date: number | string | Date | Chronos): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* * Checks if the given value is a valid `Date` object.
|
|
122
|
+
* - A value is considered valid if it is an instance of the built-in `Date` class.
|
|
123
|
+
* - This does not check whether the date itself is valid (e.g., `new Date('invalid')`).
|
|
124
|
+
* @param value - The value to test.
|
|
125
|
+
* @returns `true` if the value is a valid Date object, otherwise `false`.
|
|
126
|
+
*/
|
|
127
|
+
isValidDate(value: unknown): value is Date;
|
|
128
|
+
/**
|
|
129
|
+
* * Checks if the given value is a valid date string.
|
|
130
|
+
* - A value is considered a valid date string if it is a string and can be parsed by `Date.parse()`.
|
|
131
|
+
* - This uses the native JavaScript date parser internally.
|
|
132
|
+
* @param value - The value to test.
|
|
133
|
+
* @returns `true` if the value is a valid date string, otherwise `false`.
|
|
134
|
+
*/
|
|
135
|
+
isDateString(value: unknown): value is string;
|
|
136
|
+
/**
|
|
137
|
+
* * Checks if the given value is an instance of `Chronos`.
|
|
138
|
+
* - Useful for verifying Chronos objects in type guards or validations.
|
|
139
|
+
* @param value - The value to test.
|
|
140
|
+
* @returns `true` if the value is an instance of `Chronos`, otherwise `false`.
|
|
141
|
+
*/
|
|
142
|
+
isValidChronos(value: unknown): value is Chronos;
|
|
143
|
+
}
|
|
81
144
|
export type TimeZone = keyof typeof TIME_ZONES;
|
|
82
145
|
export type PositiveUTCHour = '+00' | '+01' | '+02' | '+03' | '+04' | '+05' | '+06' | '+07' | '+08' | '+09' | '+10' | '+11' | '+12' | '+13' | '+14';
|
|
83
146
|
export type NegativeUTCHour = '-00' | '-01' | '-02' | '-03' | '-04' | '-05' | '-06' | '-07' | '-08' | '-09' | '-10' | '-11' | '-12' | '-13' | '-14';
|
package/dist/date/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/date/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EACX,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,MAAM,EACN,cAAc,EACd,YAAY,EACZ,UAAU,E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/G,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sDAAsD;IACtD,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB"}
|
package/dist/date/utils.d.ts
CHANGED
|
@@ -46,4 +46,11 @@ export declare function extractTimeFromUTC(utc: UTCOffSet): `-${Time}` | Time;
|
|
|
46
46
|
* @returns The total minutes elapsed since `00:00`.
|
|
47
47
|
*/
|
|
48
48
|
export declare function extractMinutesFromUTC(utc: UTCOffSet): number;
|
|
49
|
+
/**
|
|
50
|
+
* * Converts a minute-based offset to a UTC offset string in the format `UTC±HH:MM`.
|
|
51
|
+
*
|
|
52
|
+
* @param minutes - The offset in minutes (positive or negative).
|
|
53
|
+
* @returns A formatted UTC offset string like `UTC+05:30` or `UTC-04:00`.
|
|
54
|
+
*/
|
|
55
|
+
export declare function formatUTCOffset(minutes: number): UTCOffSet;
|
|
49
56
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/date/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/date/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAE/C;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,GAAG,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAI3E;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,GAAG,IAAI,GAAG,MAAM,CAU/D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAED;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,WAE9D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,IAAI,EAAE,GAAG,IAAI,CAEpE;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,SAAS,GAAG,MAAM,CAE5D"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/date/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAE/C;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,GAAG,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAI3E;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,GAAG,IAAI,GAAG,MAAM,CAU/D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAED;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,WAE9D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,IAAI,EAAE,GAAG,IAAI,CAEpE;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,SAAS,GAAG,MAAM,CAE5D;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAM1D"}
|
package/dist/date/utils.js
CHANGED
|
@@ -61,3 +61,16 @@ export function extractTimeFromUTC(utc) {
|
|
|
61
61
|
export function extractMinutesFromUTC(utc) {
|
|
62
62
|
return getTotalMinutes(extractTimeFromUTC(utc));
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* * Converts a minute-based offset to a UTC offset string in the format `UTC±HH:MM`.
|
|
66
|
+
*
|
|
67
|
+
* @param minutes - The offset in minutes (positive or negative).
|
|
68
|
+
* @returns A formatted UTC offset string like `UTC+05:30` or `UTC-04:00`.
|
|
69
|
+
*/
|
|
70
|
+
export function formatUTCOffset(minutes) {
|
|
71
|
+
const sign = minutes < 0 ? '-' : '+';
|
|
72
|
+
const abs = Math.abs(minutes);
|
|
73
|
+
const hours = String(Math.floor(abs / 60)).padStart(2, '0');
|
|
74
|
+
const mins = String(abs % 60).padStart(2, '0');
|
|
75
|
+
return `UTC${sign}${hours}:${mins}`;
|
|
76
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { calculateHCF as calculateGCD, calculateHCF, calculateLCM as calculateLC
|
|
|
7
7
|
export { isEven, isEven as isEvenNumber, isFibonacci, isMultiple, isOdd, isOdd as isOddNumber, isFibonacci as isParOfFibonacci, isFibonacci as isParOfFibonacciSeries, isPerfectSquare, } from './number/guards';
|
|
8
8
|
export { numberToWords as convertNumberToWords, convertToRomanNumerals, numberToWords, } from './number/convert';
|
|
9
9
|
export { findPrimeNumbers, findPrimeNumbers as getPrimeNumbers, isPrime, isPrime as isPrimeNumber, } from './number/prime';
|
|
10
|
-
export { clampNumber, formatCurrency as convertNumberToCurrency, formatCurrency, getRandomFloat as getRandomDecimal, getRandomFloat, roundToNearest as roundNumber, roundToNearest as roundNumberToNearestInterval, roundToNearest, roundToNearest as roundToNearestInterval, } from './number/utilities';
|
|
10
|
+
export { getOrdinal as cardinalToOrdinal, clampNumber, formatCurrency as convertNumberToCurrency, getOrdinal as convertNumberToOrdinal, getOrdinal as convertToOrdinal, formatCurrency, getOrdinal, getOrdinal as getOrdinalNumber, getRandomFloat as getRandomDecimal, getRandomFloat, getOrdinal as numberToOrdinal, roundToNearest as roundNumber, roundToNearest as roundNumberToNearestInterval, roundToNearest, roundToNearest as roundToNearestInterval, } from './number/utilities';
|
|
11
11
|
export { getNumbersInRange } from './number/range';
|
|
12
12
|
export { getColorForInitial } from './colors/initials';
|
|
13
13
|
export { generateRandomColorInHexRGB, generateRandomHSLColor, } from './colors/random';
|
|
@@ -16,10 +16,11 @@ export { Color, Color as Colour } from './colors/Color';
|
|
|
16
16
|
export { getGreeting as generateGreeting, getGreeting, getGreeting as greet, } from './date/greet';
|
|
17
17
|
export { isLeapYear, isValidTime, isValidTime as isValidTimeString, isValidUTCOffSet as isValidUTC, isValidUTCOffSet, } from './date/guards';
|
|
18
18
|
export { Chronos, Chronos as Chronus } from './date/Chronos';
|
|
19
|
-
export { chronos, chronos as chronosjs, chronos as chronosts, chronos as chronus, chronos as chronusjs, chronos as chronusts, extractHourMinute, extractMinutesFromUTC, extractTimeFromUTC, extractTimeFromUTC as extractTimeStringFromUTC, getTotalMinutes as extractTotalMinutesFromTime, getCurrentDateTime, getCurrentDateTime as getCurrentTime, extractMinutesFromUTC as getMinutesFromUTC, extractTimeFromUTC as getTimeStringFromUTC, getTotalMinutes, getTotalMinutes as getTotalMinutesFromTime, extractMinutesFromUTC as getTotalMinutesFromUTC, } from './date/utils';
|
|
19
|
+
export { chronos, chronos as chronosjs, chronos as chronosts, chronos as chronus, chronos as chronusjs, chronos as chronusts, formatUTCOffset as convertMinutesToUTCOffset, extractHourMinute, extractMinutesFromUTC, extractTimeFromUTC, extractTimeFromUTC as extractTimeStringFromUTC, getTotalMinutes as extractTotalMinutesFromTime, formatUTCOffset, getCurrentDateTime, getCurrentDateTime as getCurrentTime, extractMinutesFromUTC as getMinutesFromUTC, extractTimeFromUTC as getTimeStringFromUTC, getTotalMinutes, getTotalMinutes as getTotalMinutesFromTime, extractMinutesFromUTC as getTotalMinutesFromUTC, formatUTCOffset as minutesToUTCOffset, } from './date/utils';
|
|
20
20
|
export { filterArrayOfObjects, flattenArray, getLastArrayElement, isInvalidOrEmptyArray, isInvalidOrEmptyArray as isValidEmptyArray, shuffleArray, } from './array/basics';
|
|
21
21
|
export { sortAnArray } from './array/sort';
|
|
22
22
|
export { createOptionsArray, moveArrayElement, removeDuplicatesFromArray, rotateArray, splitArray, } from './array/transform';
|
|
23
|
+
export { naturalSort as compareNaturally, naturalSort as compareSorter, naturalSort, naturalSort as naturalSortForString, } from './array/utils';
|
|
23
24
|
export { createControlledFormData as convertIntoFormData, createControlledFormData, createControlledFormData as createFormData, } from './form/convert';
|
|
24
25
|
export { isCustomFile, isCustomFileArray, isFileArray, isFileList, isFileUpload, isOriginFileObj, isValidFormData, } from './form/guards';
|
|
25
26
|
export { cloneObject, countObjectFields } from './object/basics';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,cAAc,GACd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EACN,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,GACX,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,aAAa,GACb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,IAAI,mBAAmB,GAC7C,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACN,YAAY,IAAI,YAAY,EAC5B,YAAY,EACZ,YAAY,IAAI,YAAY,EAC5B,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,IAAI,YAAY,EAClC,kBAAkB,IAAI,mBAAmB,EACzC,kBAAkB,EAClB,eAAe,EACf,UAAU,IAAI,eAAe,EAC7B,aAAa,EACb,SAAS,EACT,UAAU,EACV,UAAU,IAAI,YAAY,GAC1B,MAAM,iBAAiB,CAAC;AAEzB,O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B,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,WAAW,GACX,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACN,kBAAkB,IAAI,iBAAiB,EACvC,OAAO,EACP,aAAa,EACb,YAAY,IAAI,iBAAiB,EACjC,QAAQ,EACR,MAAM,EACN,aAAa,EACb,aAAa,IAAI,kBAAkB,EACnC,OAAO,EACP,UAAU,EACV,MAAM,EACN,MAAM,IAAI,YAAY,EACtB,KAAK,EACL,gBAAgB,EAChB,QAAQ,EACR,aAAa,IAAI,aAAa,EAC9B,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,QAAQ,IAAI,mBAAmB,EAC/B,kBAAkB,EAClB,KAAK,EACL,YAAY,EACZ,MAAM,IAAI,WAAW,EACrB,KAAK,IAAI,UAAU,EACnB,gBAAgB,IAAI,aAAa,EACjC,KAAK,IAAI,UAAU,GACnB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACN,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,aAAa,EACb,aAAa,IAAI,iBAAiB,EAClC,WAAW,EACX,MAAM,EACN,aAAa,IAAI,SAAS,EAC1B,aAAa,IAAI,iBAAiB,EAClC,eAAe,EACf,aAAa,EACb,KAAK,EACL,MAAM,EACN,OAAO,IAAI,YAAY,EACvB,KAAK,IAAI,UAAU,GACnB,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ export { calculateHCF as calculateGCD, calculateHCF, calculateLCM as calculateLC
|
|
|
9
9
|
export { isEven, isEven as isEvenNumber, isFibonacci, isMultiple, isOdd, isOdd as isOddNumber, isFibonacci as isParOfFibonacci, isFibonacci as isParOfFibonacciSeries, isPerfectSquare, } from './number/guards';
|
|
10
10
|
export { numberToWords as convertNumberToWords, convertToRomanNumerals, numberToWords, } from './number/convert';
|
|
11
11
|
export { findPrimeNumbers, findPrimeNumbers as getPrimeNumbers, isPrime, isPrime as isPrimeNumber, } from './number/prime';
|
|
12
|
-
export { clampNumber, formatCurrency as convertNumberToCurrency, formatCurrency, getRandomFloat as getRandomDecimal, getRandomFloat, roundToNearest as roundNumber, roundToNearest as roundNumberToNearestInterval, roundToNearest, roundToNearest as roundToNearestInterval, } from './number/utilities';
|
|
12
|
+
export { getOrdinal as cardinalToOrdinal, clampNumber, formatCurrency as convertNumberToCurrency, getOrdinal as convertNumberToOrdinal, getOrdinal as convertToOrdinal, formatCurrency, getOrdinal, getOrdinal as getOrdinalNumber, getRandomFloat as getRandomDecimal, getRandomFloat, getOrdinal as numberToOrdinal, roundToNearest as roundNumber, roundToNearest as roundNumberToNearestInterval, roundToNearest, roundToNearest as roundToNearestInterval, } from './number/utilities';
|
|
13
13
|
export { getNumbersInRange } from './number/range';
|
|
14
14
|
// ! Color Utilities
|
|
15
15
|
export { getColorForInitial } from './colors/initials';
|
|
@@ -20,11 +20,12 @@ export { Color, Color as Colour } from './colors/Color';
|
|
|
20
20
|
export { getGreeting as generateGreeting, getGreeting, getGreeting as greet, } from './date/greet';
|
|
21
21
|
export { isLeapYear, isValidTime, isValidTime as isValidTimeString, isValidUTCOffSet as isValidUTC, isValidUTCOffSet, } from './date/guards';
|
|
22
22
|
export { Chronos, Chronos as Chronus } from './date/Chronos';
|
|
23
|
-
export { chronos, chronos as chronosjs, chronos as chronosts, chronos as chronus, chronos as chronusjs, chronos as chronusts, extractHourMinute, extractMinutesFromUTC, extractTimeFromUTC, extractTimeFromUTC as extractTimeStringFromUTC, getTotalMinutes as extractTotalMinutesFromTime, getCurrentDateTime, getCurrentDateTime as getCurrentTime, extractMinutesFromUTC as getMinutesFromUTC, extractTimeFromUTC as getTimeStringFromUTC, getTotalMinutes, getTotalMinutes as getTotalMinutesFromTime, extractMinutesFromUTC as getTotalMinutesFromUTC, } from './date/utils';
|
|
23
|
+
export { chronos, chronos as chronosjs, chronos as chronosts, chronos as chronus, chronos as chronusjs, chronos as chronusts, formatUTCOffset as convertMinutesToUTCOffset, extractHourMinute, extractMinutesFromUTC, extractTimeFromUTC, extractTimeFromUTC as extractTimeStringFromUTC, getTotalMinutes as extractTotalMinutesFromTime, formatUTCOffset, getCurrentDateTime, getCurrentDateTime as getCurrentTime, extractMinutesFromUTC as getMinutesFromUTC, extractTimeFromUTC as getTimeStringFromUTC, getTotalMinutes, getTotalMinutes as getTotalMinutesFromTime, extractMinutesFromUTC as getTotalMinutesFromUTC, formatUTCOffset as minutesToUTCOffset, } from './date/utils';
|
|
24
24
|
// ! Array Utilities
|
|
25
25
|
export { filterArrayOfObjects, flattenArray, getLastArrayElement, isInvalidOrEmptyArray, isInvalidOrEmptyArray as isValidEmptyArray, shuffleArray, } from './array/basics';
|
|
26
26
|
export { sortAnArray } from './array/sort';
|
|
27
27
|
export { createOptionsArray, moveArrayElement, removeDuplicatesFromArray, rotateArray, splitArray, } from './array/transform';
|
|
28
|
+
export { naturalSort as compareNaturally, naturalSort as compareSorter, naturalSort, naturalSort as naturalSortForString, } from './array/utils';
|
|
28
29
|
// ! Form Utilities
|
|
29
30
|
export { createControlledFormData as convertIntoFormData, createControlledFormData, createControlledFormData as createFormData, } from './form/convert';
|
|
30
31
|
export { isCustomFile, isCustomFileArray, isFileArray, isFileList, isFileUpload, isOriginFileObj, isValidFormData, } from './form/guards';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Numeric } from '../types';
|
|
1
2
|
import type { CurrencyCode, LocaleCode } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* * Rounds a number to the nearest specified interval.
|
|
@@ -37,4 +38,15 @@ export declare const clampNumber: (value: number, min: number, max: number) => n
|
|
|
37
38
|
* @example randomFloat(1.5, 3.5) → 2.84623
|
|
38
39
|
*/
|
|
39
40
|
export declare const getRandomFloat: (min: number, max: number) => number;
|
|
41
|
+
/**
|
|
42
|
+
* * Returns the ordinal suffix for a given number (e.g., 1 -> 'st', 2 -> 'nd', 3 -> 'rd', 4 -> 'th' etc.).
|
|
43
|
+
* @description The function handles special cases for 11, 12, and 13, which all use 'th' despite the last digit.
|
|
44
|
+
* If the `withNumber` parameter is `true`, the function returns the number along with its ordinal suffix (e.g., "1st").
|
|
45
|
+
* Otherwise, it returns only the ordinal suffix (e.g., "st").
|
|
46
|
+
*
|
|
47
|
+
* @param n - The number or number string to get the ordinal suffix for.
|
|
48
|
+
* @param withNumber - Whether to include the number along with its ordinal suffix (defaults to `true`).
|
|
49
|
+
* @returns The appropriate ordinal suffix, optionally with the number (e.g., '1st' or 'st`, '2nd' or 'nd' and so on.).
|
|
50
|
+
*/
|
|
51
|
+
export declare const getOrdinal: (n: Numeric, withNumber?: boolean) => string;
|
|
40
52
|
//# sourceMappingURL=utilities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../src/number/utilities.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../src/number/utilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAExD;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,UAAW,MAAM,wBAAiB,MACrB,CAAC;AAEzC;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,UACnB,MAAM,GAAG,GAAG,MAAM,EAAE,aACjB,YAAY,WACb,UAAU,KACjB,MAQF,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,UAAW,MAAM,OAAO,MAAM,OAAO,MAAM,KAAG,MAClC,CAAC;AAErC;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,QAAS,MAAM,OAAO,MAAM,KAAG,MAEzD,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,MAAO,OAAO,2BAAsB,MAiB1D,CAAC"}
|
package/dist/number/utilities.js
CHANGED
|
@@ -45,3 +45,31 @@ export const clampNumber = (value, min, max) => Math.max(min, Math.min(value, ma
|
|
|
45
45
|
export const getRandomFloat = (min, max) => {
|
|
46
46
|
return Math.random() * (max - min) + min;
|
|
47
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* * Returns the ordinal suffix for a given number (e.g., 1 -> 'st', 2 -> 'nd', 3 -> 'rd', 4 -> 'th' etc.).
|
|
50
|
+
* @description The function handles special cases for 11, 12, and 13, which all use 'th' despite the last digit.
|
|
51
|
+
* If the `withNumber` parameter is `true`, the function returns the number along with its ordinal suffix (e.g., "1st").
|
|
52
|
+
* Otherwise, it returns only the ordinal suffix (e.g., "st").
|
|
53
|
+
*
|
|
54
|
+
* @param n - The number or number string to get the ordinal suffix for.
|
|
55
|
+
* @param withNumber - Whether to include the number along with its ordinal suffix (defaults to `true`).
|
|
56
|
+
* @returns The appropriate ordinal suffix, optionally with the number (e.g., '1st' or 'st`, '2nd' or 'nd' and so on.).
|
|
57
|
+
*/
|
|
58
|
+
export const getOrdinal = (n, withNumber = true) => {
|
|
59
|
+
const remainder10 = Number(n) % 10;
|
|
60
|
+
const remainder100 = Number(n) % 100;
|
|
61
|
+
let suffix;
|
|
62
|
+
if (remainder10 === 1 && remainder100 !== 11) {
|
|
63
|
+
suffix = 'st';
|
|
64
|
+
}
|
|
65
|
+
else if (remainder10 === 2 && remainder100 !== 12) {
|
|
66
|
+
suffix = 'nd';
|
|
67
|
+
}
|
|
68
|
+
else if (remainder10 === 3 && remainder100 !== 13) {
|
|
69
|
+
suffix = 'rd';
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
suffix = 'th';
|
|
73
|
+
}
|
|
74
|
+
return withNumber ? String(n).concat(suffix) : suffix;
|
|
75
|
+
};
|
package/package.json
CHANGED