nhb-toolbox 3.9.25 → 3.9.39
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/colors/Color.d.ts +38 -15
- package/dist/colors/Color.d.ts.map +1 -1
- package/dist/colors/Color.js +39 -16
- package/dist/date/Chronos.d.ts +35 -3
- package/dist/date/Chronos.d.ts.map +1 -1
- package/dist/date/Chronos.js +124 -14
- package/dist/date/chronos-fn.d.ts +2 -1
- package/dist/date/chronos-fn.d.ts.map +1 -1
- package/dist/date/chronos-fn.js +4 -3
- package/dist/date/types.d.ts +20 -10
- package/dist/date/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/string/convert.d.ts +9 -0
- package/dist/string/convert.d.ts.map +1 -1
- package/dist/string/convert.js +13 -0
- package/package.json +1 -1
package/dist/colors/Color.d.ts
CHANGED
|
@@ -10,19 +10,6 @@ import type { AlphaColors, ColorType, Hex6, Hex8, HSL, HSLA, OpacityValue, RGB,
|
|
|
10
10
|
* @property {RGBA} rgba - The color in `RGBA` format.
|
|
11
11
|
* @property {HSL} hsl - The color in `HSL` format.
|
|
12
12
|
* @property {HSLA} hsla - The color in `HSLA` format.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* const color = new Color("#ff5733"); // Accepts a color in `Hex`, `Hex8` `RGB`, `RGBA`, `HSL` or `HSLA` format.
|
|
16
|
-
* console.log(color.hex); // Get Hex equivalent
|
|
17
|
-
* console.log(color.hex8); // Get Hex8 equivalent
|
|
18
|
-
* console.log(color.rgb); // Get RGB equivalent
|
|
19
|
-
* console.log(color.rgba); // Get RGBA equivalent
|
|
20
|
-
* console.log(color.hsl); // Get HSL equivalent
|
|
21
|
-
* console.log(color.hsla); // Get HSLA equivalent
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* const randomColor = new Color(); // Generate a random color
|
|
25
|
-
* console.log(randomColor.hex, randomColor.rgb, randomColor.hsl, randomColor.hex8, randomColor.rgba, randomColor.hsla); // Get RGBA and HSLA equivalent
|
|
26
13
|
*/
|
|
27
14
|
export declare class Color {
|
|
28
15
|
hex: Hex6;
|
|
@@ -34,9 +21,45 @@ export declare class Color {
|
|
|
34
21
|
/** - Iterates over the color representations (Hex, RGB, HSL). */
|
|
35
22
|
[Symbol.iterator](): Generator<Hex6 | RGB | HSL | Hex8 | RGBA | HSLA, void, unknown>;
|
|
36
23
|
/**
|
|
37
|
-
* * Creates a new `Color` instance
|
|
24
|
+
* * Creates a new `Color` instance and automatically converts the input color to all other supported formats: `Hex`, `Hex8`, `RGB`, `RGBA`, `HSL`, and `HSLA`.
|
|
25
|
+
*
|
|
26
|
+
* @description
|
|
27
|
+
* The `Color` class allows seamless transformation between six common color representations:
|
|
28
|
+
* - `Hex` (e.g., `#ff5733`)
|
|
29
|
+
* - `Hex8` (Hex with opacity, e.g., `#ff573380`)
|
|
30
|
+
* - `RGB` (e.g., `rgb(255, 87, 51)`)
|
|
31
|
+
* - `RGBA` (e.g., `rgba(255, 87, 51, 1)`)
|
|
32
|
+
* - `HSL` (e.g., `hsl(14, 100%, 60%)`)
|
|
33
|
+
* - `HSLA` (e.g., `hsla(14, 100%, 60%, 1)`)
|
|
34
|
+
*
|
|
35
|
+
* You can create a color from any of these formats, and the class will populate the rest.
|
|
36
|
+
* If no color is passed, a random color will be generated.
|
|
37
|
+
*
|
|
38
|
+
* Additionally:
|
|
39
|
+
* - Use `.applyOpacity(opacity)` to modify or add opacity to the color.
|
|
40
|
+
* - Use static methods like `Color.isHex6(color)` to validate color strings.
|
|
41
|
+
*
|
|
42
|
+
* @param toConvert - An optional input color string in any supported format (`Hex`, `Hex8`, `RGB`, `RGBA`, `HSL`, or `HSLA`) to convert in all other (includes the current format) formats.
|
|
38
43
|
*
|
|
39
|
-
* @
|
|
44
|
+
* @example
|
|
45
|
+
* // Convert an existing Hex color to all other formats
|
|
46
|
+
* const color = new Color("#ff5733");
|
|
47
|
+
* console.log(color.rgb); // 'rgb(255, 87, 51)'
|
|
48
|
+
* console.log(color.hsl); // 'hsl(14, 100%, 60%)'
|
|
49
|
+
* console.log(color.rgba); // 'rgba(255, 87, 51, 1)'
|
|
50
|
+
* console.log(color.hsla); // 'hsla(14, 100%, 60%, 1)'
|
|
51
|
+
* console.log(color.hex8); // '#FF5733FF'
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* // Handle a color with alpha
|
|
55
|
+
* const alphaColor = new Color("rgba(255, 0, 0, 0.5)");
|
|
56
|
+
* console.log(alphaColor.hex8); // '#FF000080'
|
|
57
|
+
* console.log(alphaColor.hsla); // 'hsla(0, 100%, 50%, 0.5)'
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* // Generate a random color
|
|
61
|
+
* const randomColor = new Color();
|
|
62
|
+
* console.log(randomColor.hex, randomColor.rgb, randomColor.hsl);
|
|
40
63
|
*/
|
|
41
64
|
constructor(toConvert?: ColorType);
|
|
42
65
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Color.d.ts","sourceRoot":"","sources":["../../src/colors/Color.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACX,WAAW,EACX,SAAS,EACT,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,YAAY,EACZ,GAAG,EACH,IAAI,EACJ,WAAW,EACX,MAAM,SAAS,CAAC;AAKjB
|
|
1
|
+
{"version":3,"file":"Color.d.ts","sourceRoot":"","sources":["../../src/colors/Color.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACX,WAAW,EACX,SAAS,EACT,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,YAAY,EACZ,GAAG,EACH,IAAI,EACJ,WAAW,EACX,MAAM,SAAS,CAAC;AAKjB;;;;;;;;;;;GAWG;AACH,qBAAa,KAAK;IACV,GAAG,EAAE,IAAI,CAAC;IACV,IAAI,EAAE,IAAI,CAAC;IACX,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,IAAI,CAAC;IACX,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,IAAI,CAAC;IAElB,iEAAiE;IAChE,CAAC,MAAM,CAAC,QAAQ,CAAC;IASlB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;gBAES,SAAS,CAAC,EAAE,SAAS;IA2CjC;;;;;;;;;;;;;;;;;OAiBG;IACH,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,WAAW,GAAG,WAAW;IAkB9D;;;;;OAKG;WACW,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI;IAIlD;;;;;OAKG;WACW,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI;IAIlD;;;;;OAKG;WACW,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,GAAG;IAIhD;;;;;OAKG;WACW,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI;IAMlD;;;;;OAKG;WACW,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,GAAG;IAIhD;;;;;OAKG;WACW,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI;IAMlD;;;;;OAKG;IACH,OAAO,CAAC,qBAAqB;CAuB7B"}
|
package/dist/colors/Color.js
CHANGED
|
@@ -14,19 +14,6 @@ const { hex, rgb } = convertColorCode(hsl);
|
|
|
14
14
|
* @property {RGBA} rgba - The color in `RGBA` format.
|
|
15
15
|
* @property {HSL} hsl - The color in `HSL` format.
|
|
16
16
|
* @property {HSLA} hsla - The color in `HSLA` format.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* const color = new Color("#ff5733"); // Accepts a color in `Hex`, `Hex8` `RGB`, `RGBA`, `HSL` or `HSLA` format.
|
|
20
|
-
* console.log(color.hex); // Get Hex equivalent
|
|
21
|
-
* console.log(color.hex8); // Get Hex8 equivalent
|
|
22
|
-
* console.log(color.rgb); // Get RGB equivalent
|
|
23
|
-
* console.log(color.rgba); // Get RGBA equivalent
|
|
24
|
-
* console.log(color.hsl); // Get HSL equivalent
|
|
25
|
-
* console.log(color.hsla); // Get HSLA equivalent
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* const randomColor = new Color(); // Generate a random color
|
|
29
|
-
* console.log(randomColor.hex, randomColor.rgb, randomColor.hsl, randomColor.hex8, randomColor.rgba, randomColor.hsla); // Get RGBA and HSLA equivalent
|
|
30
17
|
*/
|
|
31
18
|
export class Color {
|
|
32
19
|
hex;
|
|
@@ -45,9 +32,45 @@ export class Color {
|
|
|
45
32
|
yield this.hsla;
|
|
46
33
|
}
|
|
47
34
|
/**
|
|
48
|
-
* * Creates a new `Color` instance
|
|
35
|
+
* * Creates a new `Color` instance and automatically converts the input color to all other supported formats: `Hex`, `Hex8`, `RGB`, `RGBA`, `HSL`, and `HSLA`.
|
|
36
|
+
*
|
|
37
|
+
* @description
|
|
38
|
+
* The `Color` class allows seamless transformation between six common color representations:
|
|
39
|
+
* - `Hex` (e.g., `#ff5733`)
|
|
40
|
+
* - `Hex8` (Hex with opacity, e.g., `#ff573380`)
|
|
41
|
+
* - `RGB` (e.g., `rgb(255, 87, 51)`)
|
|
42
|
+
* - `RGBA` (e.g., `rgba(255, 87, 51, 1)`)
|
|
43
|
+
* - `HSL` (e.g., `hsl(14, 100%, 60%)`)
|
|
44
|
+
* - `HSLA` (e.g., `hsla(14, 100%, 60%, 1)`)
|
|
45
|
+
*
|
|
46
|
+
* You can create a color from any of these formats, and the class will populate the rest.
|
|
47
|
+
* If no color is passed, a random color will be generated.
|
|
48
|
+
*
|
|
49
|
+
* Additionally:
|
|
50
|
+
* - Use `.applyOpacity(opacity)` to modify or add opacity to the color.
|
|
51
|
+
* - Use static methods like `Color.isHex6(color)` to validate color strings.
|
|
52
|
+
*
|
|
53
|
+
* @param toConvert - An optional input color string in any supported format (`Hex`, `Hex8`, `RGB`, `RGBA`, `HSL`, or `HSLA`) to convert in all other (includes the current format) formats.
|
|
49
54
|
*
|
|
50
|
-
* @
|
|
55
|
+
* @example
|
|
56
|
+
* // Convert an existing Hex color to all other formats
|
|
57
|
+
* const color = new Color("#ff5733");
|
|
58
|
+
* console.log(color.rgb); // 'rgb(255, 87, 51)'
|
|
59
|
+
* console.log(color.hsl); // 'hsl(14, 100%, 60%)'
|
|
60
|
+
* console.log(color.rgba); // 'rgba(255, 87, 51, 1)'
|
|
61
|
+
* console.log(color.hsla); // 'hsla(14, 100%, 60%, 1)'
|
|
62
|
+
* console.log(color.hex8); // '#FF5733FF'
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* // Handle a color with alpha
|
|
66
|
+
* const alphaColor = new Color("rgba(255, 0, 0, 0.5)");
|
|
67
|
+
* console.log(alphaColor.hex8); // '#FF000080'
|
|
68
|
+
* console.log(alphaColor.hsla); // 'hsla(0, 100%, 50%, 0.5)'
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* // Generate a random color
|
|
72
|
+
* const randomColor = new Color();
|
|
73
|
+
* console.log(randomColor.hex, randomColor.rgb, randomColor.hsl);
|
|
51
74
|
*/
|
|
52
75
|
constructor(toConvert) {
|
|
53
76
|
if (toConvert) {
|
|
@@ -207,6 +230,6 @@ export class Color {
|
|
|
207
230
|
const { hex8, rgba } = convertColorCode(color);
|
|
208
231
|
return { hex8, rgba, hsla: color };
|
|
209
232
|
}
|
|
210
|
-
throw new Error(`Unrecognized
|
|
233
|
+
throw new Error(`Unrecognized color format: ${color}`);
|
|
211
234
|
}
|
|
212
235
|
}
|
package/dist/date/Chronos.d.ts
CHANGED
|
@@ -129,6 +129,12 @@ export declare class Chronos {
|
|
|
129
129
|
* @returns A new `Chronos` instance with the updated date.
|
|
130
130
|
*/
|
|
131
131
|
addDays(days: number): Chronos;
|
|
132
|
+
/**
|
|
133
|
+
* @public @instance Adds weeks and returns a new immutable instance.
|
|
134
|
+
* @param weeks - Number of weeks to add.
|
|
135
|
+
* @returns A new `Chronos` instance with the updated date.
|
|
136
|
+
*/
|
|
137
|
+
addWeeks(weeks: number): Chronos;
|
|
132
138
|
/**
|
|
133
139
|
* @public @instance Adds months and returns a new immutable instance.
|
|
134
140
|
* @param months - Number of months to add.
|
|
@@ -227,6 +233,12 @@ export declare class Chronos {
|
|
|
227
233
|
* - Other positive or negative numbers for other relative days (e.g., `-2` for two days ago, `2` for two days ahead).
|
|
228
234
|
*/
|
|
229
235
|
getRelativeDay(time?: number | string | Date | Chronos): number;
|
|
236
|
+
/**
|
|
237
|
+
* @public @instance Determines how many full weeks apart the input date is from the `Chronos` instance.
|
|
238
|
+
* @param time Optional time to compare with the `Chronos` date/time.
|
|
239
|
+
* @returns Difference in weeks; negative if past, positive if future.
|
|
240
|
+
*/
|
|
241
|
+
getRelativeWeek(time?: number | string | Date | Chronos): number;
|
|
230
242
|
/**
|
|
231
243
|
* @public @instance Returns the number of full hours between the input date and now.
|
|
232
244
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
@@ -263,7 +275,7 @@ export declare class Chronos {
|
|
|
263
275
|
* @public @instance Returns a new Chronos instance at the start of a given unit.
|
|
264
276
|
* @param unit The unit to reset (e.g., year, month, day).
|
|
265
277
|
*/
|
|
266
|
-
startOf(unit: TimeUnit
|
|
278
|
+
startOf(unit: TimeUnit): Chronos;
|
|
267
279
|
/**
|
|
268
280
|
* @public @instance Returns a new Chronos instance at the end of a given unit.
|
|
269
281
|
* @param unit The unit to adjust (e.g., year, month, day).
|
|
@@ -305,7 +317,18 @@ export declare class Chronos {
|
|
|
305
317
|
calendar(baseDate?: number | string | Date | Chronos): string;
|
|
306
318
|
/** @public @instance Returns a short human-readable string like "2h ago", "in 5m" */
|
|
307
319
|
fromNowShort(): string;
|
|
308
|
-
/**
|
|
320
|
+
/**
|
|
321
|
+
* @public @instance Sets the date to the Monday of the specified ISO week number within the current year.
|
|
322
|
+
* This method assumes ISO week logic, where week 1 is the week containing January 4th.
|
|
323
|
+
*
|
|
324
|
+
* @param week The ISO week number (1–53) to set the date to.
|
|
325
|
+
* @returns A new Chronos instance set to the start (Monday) of the specified week.
|
|
326
|
+
*/
|
|
327
|
+
setWeek(week: number): Chronos;
|
|
328
|
+
/**
|
|
329
|
+
* @public @instance Calculates the ISO week number of the year.
|
|
330
|
+
* @returns Week number (1-53).
|
|
331
|
+
*/
|
|
309
332
|
getWeek(): number;
|
|
310
333
|
/** @public @instance Returns ISO week year */
|
|
311
334
|
getWeekYear(): number;
|
|
@@ -376,9 +399,18 @@ export declare class Chronos {
|
|
|
376
399
|
*/
|
|
377
400
|
static max(...dates: (number | string | Date | Chronos)[]): Chronos;
|
|
378
401
|
/**
|
|
379
|
-
* @public @static Checks if the year in the date string is a leap year.
|
|
402
|
+
* @public @static Checks if the year in the date string or year (from 0 - 9999) is a leap year.
|
|
380
403
|
* - A year is a leap year if it is divisible by 4, but not divisible by 100, unless it is also divisible by 400.
|
|
381
404
|
* - For example, 2000 and 2400 are leap years, but 1900 and 2100 are not.
|
|
405
|
+
*
|
|
406
|
+
* @description
|
|
407
|
+
* This method accepts different types of date inputs and extracts the year to check if it's a leap year.
|
|
408
|
+
* If the provided date is a `number`, it will be treated as a year (must be a valid year from 0 to 9999).
|
|
409
|
+
* If the year is out of this range (negative or larger than 9999), it will be treated as a Unix timestamp.
|
|
410
|
+
* If the provided date is a string or a `Date` object, it will be parsed and the year will be extracted.
|
|
411
|
+
* If a `Chronos` instance is passed, the year will be directly accessed from the instance.
|
|
412
|
+
*
|
|
413
|
+
* @param date - A `number` (year or Unix timestamp), `string`, `Date`, or `Chronos` instance representing a date.
|
|
382
414
|
* @returns `true` if the year is a leap year, `false` otherwise.
|
|
383
415
|
*/
|
|
384
416
|
static isLeapYear(date: number | string | Date | Chronos): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chronos.d.ts","sourceRoot":"","sources":["../../src/date/Chronos.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"Chronos.d.ts","sourceRoot":"","sources":["../../src/date/Chronos.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,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,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM;IAuB7D,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAqBvC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;IAqBxC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAajC;IAgID,sCAAsC;IACtC,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,yCAAyC;IACzC,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,wCAAwC;IACxC,IAAI,IAAI,IAAI,MAAM,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ACnE,OAAO,IAAI,OAAO;IAMlB;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM;IAO7C;;;;OAIG;IACH,MAAM,CAAC,GAAG,IAAI,MAAM;IAIpB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IAoDtD;;;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;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,GAAG,OAAO;IAgBlE;;;;;;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,7 +1,8 @@
|
|
|
1
1
|
import { isString } from '../guards/primitives';
|
|
2
2
|
import { getOrdinal } from '../number/utilities';
|
|
3
|
+
import { formatUnitWithPlural } from '../string/convert';
|
|
3
4
|
import { DAYS, MONTHS, ORIGIN, sortedFormats, TIME_ZONE_LABELS, TIME_ZONES, } from './constants';
|
|
4
|
-
import { isValidUTCOffSet } from './guards';
|
|
5
|
+
import { isLeapYear, isValidUTCOffSet } from './guards';
|
|
5
6
|
import { extractMinutesFromUTC, formatUTCOffset } from './utils';
|
|
6
7
|
export class Chronos {
|
|
7
8
|
#date;
|
|
@@ -413,6 +414,16 @@ export class Chronos {
|
|
|
413
414
|
newDate.setDate(newDate.getDate() + days);
|
|
414
415
|
return new Chronos(newDate).#withOrigin('addDays');
|
|
415
416
|
}
|
|
417
|
+
/**
|
|
418
|
+
* @public @instance Adds weeks and returns a new immutable instance.
|
|
419
|
+
* @param weeks - Number of weeks to add.
|
|
420
|
+
* @returns A new `Chronos` instance with the updated date.
|
|
421
|
+
*/
|
|
422
|
+
addWeeks(weeks) {
|
|
423
|
+
const newDate = new Date(this.#date);
|
|
424
|
+
newDate.setDate(newDate.getDate() + weeks * 7);
|
|
425
|
+
return new Chronos(newDate).#withOrigin('addWeeks');
|
|
426
|
+
}
|
|
416
427
|
/**
|
|
417
428
|
* @public @instance Adds months and returns a new immutable instance.
|
|
418
429
|
* @param months - Number of months to add.
|
|
@@ -462,7 +473,7 @@ export class Chronos {
|
|
|
462
473
|
*/
|
|
463
474
|
isLeapYear() {
|
|
464
475
|
const year = this.#date.getFullYear();
|
|
465
|
-
return (year
|
|
476
|
+
return isLeapYear(year);
|
|
466
477
|
}
|
|
467
478
|
/** @public @instance Checks if the current date is today. */
|
|
468
479
|
isToday() {
|
|
@@ -558,6 +569,7 @@ export class Chronos {
|
|
|
558
569
|
let years = to.getFullYear() - from.getFullYear();
|
|
559
570
|
let months = to.getMonth() - from.getMonth();
|
|
560
571
|
let days = to.getDate() - from.getDate();
|
|
572
|
+
let weeks = 0;
|
|
561
573
|
let hours = to.getHours() - from.getHours();
|
|
562
574
|
let minutes = to.getMinutes() - from.getMinutes();
|
|
563
575
|
let seconds = to.getSeconds() - from.getSeconds();
|
|
@@ -574,6 +586,10 @@ export class Chronos {
|
|
|
574
586
|
hours += 24;
|
|
575
587
|
days--;
|
|
576
588
|
}
|
|
589
|
+
if (level === 'week' || level === 'day') {
|
|
590
|
+
weeks = Math.floor(days / 7);
|
|
591
|
+
days = days % 7;
|
|
592
|
+
}
|
|
577
593
|
if (days < 0) {
|
|
578
594
|
const prevMonth = new Date(to.getFullYear(), to.getMonth(), 0);
|
|
579
595
|
days += prevMonth.getDate();
|
|
@@ -586,6 +602,7 @@ export class Chronos {
|
|
|
586
602
|
const unitOrder = [
|
|
587
603
|
'year',
|
|
588
604
|
'month',
|
|
605
|
+
'week',
|
|
589
606
|
'day',
|
|
590
607
|
'hour',
|
|
591
608
|
'minute',
|
|
@@ -594,23 +611,26 @@ export class Chronos {
|
|
|
594
611
|
const lvlIdx = unitOrder.indexOf(level);
|
|
595
612
|
const parts = [];
|
|
596
613
|
if (lvlIdx >= 0 && years > 0 && lvlIdx >= unitOrder.indexOf('year')) {
|
|
597
|
-
parts.push(
|
|
614
|
+
parts.push(formatUnitWithPlural(years, 'year'));
|
|
598
615
|
}
|
|
599
616
|
if (lvlIdx >= unitOrder.indexOf('month') && months > 0) {
|
|
600
|
-
parts.push(
|
|
617
|
+
parts.push(formatUnitWithPlural(months, 'month'));
|
|
618
|
+
}
|
|
619
|
+
if (lvlIdx >= unitOrder.indexOf('week') && weeks > 0) {
|
|
620
|
+
parts.push(formatUnitWithPlural(weeks, 'week'));
|
|
601
621
|
}
|
|
602
622
|
if (lvlIdx >= unitOrder.indexOf('day') && days > 0) {
|
|
603
|
-
parts.push(
|
|
623
|
+
parts.push(formatUnitWithPlural(days, 'day'));
|
|
604
624
|
}
|
|
605
625
|
if (lvlIdx >= unitOrder.indexOf('hour') && hours > 0) {
|
|
606
|
-
parts.push(
|
|
626
|
+
parts.push(formatUnitWithPlural(hours, 'hour'));
|
|
607
627
|
}
|
|
608
628
|
if (lvlIdx >= unitOrder.indexOf('minute') && minutes > 0) {
|
|
609
|
-
parts.push(
|
|
629
|
+
parts.push(formatUnitWithPlural(minutes, 'minute'));
|
|
610
630
|
}
|
|
611
631
|
if (lvlIdx >= unitOrder.indexOf('second') &&
|
|
612
632
|
(seconds > 0 || parts.length === 0)) {
|
|
613
|
-
parts.push(
|
|
633
|
+
parts.push(formatUnitWithPlural(seconds, 'second'));
|
|
614
634
|
}
|
|
615
635
|
let prefix = '';
|
|
616
636
|
let suffix = '';
|
|
@@ -676,6 +696,15 @@ export class Chronos {
|
|
|
676
696
|
const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));
|
|
677
697
|
return diffDays;
|
|
678
698
|
}
|
|
699
|
+
/**
|
|
700
|
+
* @public @instance Determines how many full weeks apart the input date is from the `Chronos` instance.
|
|
701
|
+
* @param time Optional time to compare with the `Chronos` date/time.
|
|
702
|
+
* @returns Difference in weeks; negative if past, positive if future.
|
|
703
|
+
*/
|
|
704
|
+
getRelativeWeek(time) {
|
|
705
|
+
const relativeDays = this.getRelativeDay(time);
|
|
706
|
+
return Math.floor(relativeDays / 7);
|
|
707
|
+
}
|
|
679
708
|
/**
|
|
680
709
|
* @public @instance Returns the number of full hours between the input date and now.
|
|
681
710
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
@@ -726,6 +755,8 @@ export class Chronos {
|
|
|
726
755
|
return this.getRelativeMonth(time);
|
|
727
756
|
case 'day':
|
|
728
757
|
return this.getRelativeDay(time);
|
|
758
|
+
case 'week':
|
|
759
|
+
return this.getRelativeWeek(time);
|
|
729
760
|
case 'hour':
|
|
730
761
|
return this.getRelativeHour(time);
|
|
731
762
|
case 'minute':
|
|
@@ -810,6 +841,9 @@ export class Chronos {
|
|
|
810
841
|
case 'day':
|
|
811
842
|
d.setDate(d.getDate() + amount);
|
|
812
843
|
break;
|
|
844
|
+
case 'week':
|
|
845
|
+
d.setDate(d.getDate() + amount * 7);
|
|
846
|
+
break;
|
|
813
847
|
case 'month':
|
|
814
848
|
d.setMonth(d.getMonth() + amount);
|
|
815
849
|
break;
|
|
@@ -839,6 +873,8 @@ export class Chronos {
|
|
|
839
873
|
return this.#date.getMonth();
|
|
840
874
|
case 'day':
|
|
841
875
|
return this.#date.getDate();
|
|
876
|
+
case 'week':
|
|
877
|
+
return this.getWeek();
|
|
842
878
|
case 'hour':
|
|
843
879
|
return this.#date.getHours();
|
|
844
880
|
case 'minute':
|
|
@@ -866,6 +902,8 @@ export class Chronos {
|
|
|
866
902
|
case 'day':
|
|
867
903
|
d.setDate(value);
|
|
868
904
|
break;
|
|
905
|
+
case 'week':
|
|
906
|
+
return this.setWeek(value);
|
|
869
907
|
case 'hour':
|
|
870
908
|
d.setHours(value);
|
|
871
909
|
break;
|
|
@@ -900,6 +938,8 @@ export class Chronos {
|
|
|
900
938
|
return msDiff / 3.6e6;
|
|
901
939
|
case 'day':
|
|
902
940
|
return msDiff / 8.64e7;
|
|
941
|
+
case 'week':
|
|
942
|
+
return msDiff / 6.048e8;
|
|
903
943
|
case 'month':
|
|
904
944
|
return ((this.get('year') - time.get('year')) * 12 +
|
|
905
945
|
(this.get('month') - time.get('month')));
|
|
@@ -961,15 +1001,56 @@ export class Chronos {
|
|
|
961
1001
|
return `${suffix}${Math.floor(abs / 31536000)}y${postfix}`;
|
|
962
1002
|
}
|
|
963
1003
|
}
|
|
964
|
-
/**
|
|
1004
|
+
/**
|
|
1005
|
+
* @public @instance Sets the date to the Monday of the specified ISO week number within the current year.
|
|
1006
|
+
* This method assumes ISO week logic, where week 1 is the week containing January 4th.
|
|
1007
|
+
*
|
|
1008
|
+
* @param week The ISO week number (1–53) to set the date to.
|
|
1009
|
+
* @returns A new Chronos instance set to the start (Monday) of the specified week.
|
|
1010
|
+
*/
|
|
1011
|
+
setWeek(week) {
|
|
1012
|
+
const d = new Date(this.#date);
|
|
1013
|
+
const year = d.getFullYear();
|
|
1014
|
+
const jan4 = new Date(year, 0, 4);
|
|
1015
|
+
const dayOfWeek = jan4.getDay() || 7; // Make Sunday (0) into 7
|
|
1016
|
+
const weekStart = new Date(jan4);
|
|
1017
|
+
weekStart.setDate(jan4.getDate() - (dayOfWeek - 1)); // Move to Monday
|
|
1018
|
+
weekStart.setDate(weekStart.getDate() + (week - 1) * 7); // Move to target week
|
|
1019
|
+
d.setFullYear(weekStart.getFullYear());
|
|
1020
|
+
d.setMonth(weekStart.getMonth());
|
|
1021
|
+
d.setDate(weekStart.getDate());
|
|
1022
|
+
return new Chronos(d).#withOrigin('setWeek');
|
|
1023
|
+
}
|
|
1024
|
+
// /**
|
|
1025
|
+
// * @public @instance Sets the date to the Monday of the specified ISO week number and year.
|
|
1026
|
+
// * @param week ISO week number (1–53)
|
|
1027
|
+
// * @param isoYear Optional ISO week year. Defaults to the current ISO week year.
|
|
1028
|
+
// * @returns New Chronos instance set to the start of the specified ISO week.
|
|
1029
|
+
// */
|
|
1030
|
+
// setISOWeek(week: number, isoYear?: number): Chronos {
|
|
1031
|
+
// // ❗ Use calendar year instead of ISO week year unless explicitly provided
|
|
1032
|
+
// const targetISOYear = isoYear ?? this.#date.getFullYear();
|
|
1033
|
+
// const jan4 = new Date(Date.UTC(targetISOYear, 0, 4));
|
|
1034
|
+
// const dayOfWeek = jan4.getUTCDay();
|
|
1035
|
+
// const offset = (dayOfWeek + 6) % 7;
|
|
1036
|
+
// const firstISOWeekStart = new Date(jan4);
|
|
1037
|
+
// firstISOWeekStart.setUTCDate(jan4.getUTCDate() - offset);
|
|
1038
|
+
// firstISOWeekStart.setUTCDate(
|
|
1039
|
+
// firstISOWeekStart.getUTCDate() + (week - 1) * 7,
|
|
1040
|
+
// );
|
|
1041
|
+
// return new Chronos(firstISOWeekStart).#withOrigin('setISOWeek');
|
|
1042
|
+
// }
|
|
1043
|
+
/**
|
|
1044
|
+
* @public @instance Calculates the ISO week number of the year.
|
|
1045
|
+
* @returns Week number (1-53).
|
|
1046
|
+
*/
|
|
965
1047
|
getWeek() {
|
|
966
1048
|
// ISO week starts on Monday
|
|
967
1049
|
const target = this.startOf('week').add(3, 'day');
|
|
968
1050
|
const firstThursday = new Chronos(new Date(target.year, 0, 4))
|
|
969
1051
|
.startOf('week')
|
|
970
1052
|
.add(3, 'day');
|
|
971
|
-
const
|
|
972
|
-
const week = Math.floor(daysDiff / 7) + 1;
|
|
1053
|
+
const week = target.diff(firstThursday, 'week');
|
|
973
1054
|
return week;
|
|
974
1055
|
}
|
|
975
1056
|
/** @public @instance Returns ISO week year */
|
|
@@ -977,6 +1058,15 @@ export class Chronos {
|
|
|
977
1058
|
const d = this.startOf('week').add(3, 'day'); // Thursday of current ISO week
|
|
978
1059
|
return d.year;
|
|
979
1060
|
}
|
|
1061
|
+
// /**
|
|
1062
|
+
// * @private @instance Gets the ISO week-numbering year.
|
|
1063
|
+
// * @returns The ISO year (can differ from calendar year).
|
|
1064
|
+
// */
|
|
1065
|
+
// getISOWeekYear(): number {
|
|
1066
|
+
// const date = new Date(this.#date);
|
|
1067
|
+
// date.setDate(date.getDate() + 4 - (date.getDay() || 7)); // Thursday of the week
|
|
1068
|
+
// return date.getFullYear();
|
|
1069
|
+
// }
|
|
980
1070
|
/** @public @instance Returns day of year (1 - 366) */
|
|
981
1071
|
getDayOfYear() {
|
|
982
1072
|
const start = new Date(this.year, 0, 1);
|
|
@@ -1111,14 +1201,34 @@ export class Chronos {
|
|
|
1111
1201
|
return new Chronos(Math.max(...dates.map((d) => new Chronos(d).valueOf()))).#withOrigin('max');
|
|
1112
1202
|
}
|
|
1113
1203
|
/**
|
|
1114
|
-
* @public @static Checks if the year in the date string is a leap year.
|
|
1204
|
+
* @public @static Checks if the year in the date string or year (from 0 - 9999) is a leap year.
|
|
1115
1205
|
* - A year is a leap year if it is divisible by 4, but not divisible by 100, unless it is also divisible by 400.
|
|
1116
1206
|
* - For example, 2000 and 2400 are leap years, but 1900 and 2100 are not.
|
|
1207
|
+
*
|
|
1208
|
+
* @description
|
|
1209
|
+
* This method accepts different types of date inputs and extracts the year to check if it's a leap year.
|
|
1210
|
+
* If the provided date is a `number`, it will be treated as a year (must be a valid year from 0 to 9999).
|
|
1211
|
+
* If the year is out of this range (negative or larger than 9999), it will be treated as a Unix timestamp.
|
|
1212
|
+
* If the provided date is a string or a `Date` object, it will be parsed and the year will be extracted.
|
|
1213
|
+
* If a `Chronos` instance is passed, the year will be directly accessed from the instance.
|
|
1214
|
+
*
|
|
1215
|
+
* @param date - A `number` (year or Unix timestamp), `string`, `Date`, or `Chronos` instance representing a date.
|
|
1117
1216
|
* @returns `true` if the year is a leap year, `false` otherwise.
|
|
1118
1217
|
*/
|
|
1119
1218
|
static isLeapYear(date) {
|
|
1120
|
-
|
|
1121
|
-
|
|
1219
|
+
let year;
|
|
1220
|
+
if (typeof date === 'number') {
|
|
1221
|
+
if (date > 0 && date <= 9999) {
|
|
1222
|
+
year = date;
|
|
1223
|
+
}
|
|
1224
|
+
else {
|
|
1225
|
+
year = new Chronos(date).year;
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
else {
|
|
1229
|
+
year = date instanceof Chronos ? date.year : new Chronos(date).year;
|
|
1230
|
+
}
|
|
1231
|
+
return isLeapYear(year);
|
|
1122
1232
|
}
|
|
1123
1233
|
/**
|
|
1124
1234
|
* @public @static Checks if the given value is a valid `Date` object.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ChronosStatics } from './types';
|
|
2
2
|
/**
|
|
3
|
-
* * Converts a date into a Chronos object.
|
|
3
|
+
* * Converts a date into a Chronos object and access to all `Chronos` methods.
|
|
4
|
+
*
|
|
4
5
|
* @description
|
|
5
6
|
* This function serves as a wrapper around the `Chronos` class constructor and allows you to create a new `Chronos` instance from various types of date representations.
|
|
6
7
|
* The following types of input are supported:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chronos-fn.d.ts","sourceRoot":"","sources":["../../src/date/chronos-fn.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C
|
|
1
|
+
{"version":3,"file":"chronos-fn.d.ts","sourceRoot":"","sources":["../../src/date/chronos-fn.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,QAAA,MAAM,OAAO,EAEP,cAAc,CAAC;AAsBrB,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
package/dist/date/chronos-fn.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Chronos } from '..';
|
|
2
2
|
/**
|
|
3
|
-
* * Converts a date into a Chronos object.
|
|
3
|
+
* * Converts a date into a Chronos object and access to all `Chronos` methods.
|
|
4
|
+
*
|
|
4
5
|
* @description
|
|
5
6
|
* This function serves as a wrapper around the `Chronos` class constructor and allows you to create a new `Chronos` instance from various types of date representations.
|
|
6
7
|
* The following types of input are supported:
|
|
@@ -41,14 +42,14 @@ import { Chronos } from '..';
|
|
|
41
42
|
const chronos = ((date) => {
|
|
42
43
|
return new Chronos(date);
|
|
43
44
|
});
|
|
44
|
-
// Add static methods from Chronos class to the chronos function
|
|
45
|
+
// ? Add static methods from Chronos class to the chronos function
|
|
45
46
|
Object.getOwnPropertyNames(Chronos).forEach((method) => {
|
|
46
47
|
// Exclude non-method properties like `length`, `name`, `prototype`
|
|
47
48
|
if (method !== 'prototype' && method !== 'name' && method !== 'length') {
|
|
48
49
|
chronos[method] = Chronos[method];
|
|
49
50
|
}
|
|
50
51
|
});
|
|
51
|
-
// Add instance methods from Chronos prototype to chronos function
|
|
52
|
+
// ? Add instance methods from Chronos prototype to chronos function
|
|
52
53
|
// Object.getOwnPropertyNames(Chronos.prototype).forEach((method) => {
|
|
53
54
|
// // Skip the constructor method
|
|
54
55
|
// if (method !== 'constructor') {
|
package/dist/date/types.d.ts
CHANGED
|
@@ -37,19 +37,19 @@ export interface GreetingConfigs {
|
|
|
37
37
|
/** Default greeting message if no period matches. */
|
|
38
38
|
defaultMessage?: string;
|
|
39
39
|
}
|
|
40
|
-
export type TimeUnit = 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond';
|
|
40
|
+
export type TimeUnit = 'year' | 'month' | 'day' | 'week' | 'hour' | 'minute' | 'second' | 'millisecond';
|
|
41
41
|
export type Year = (typeof YEAR_FORMATS)[number];
|
|
42
42
|
export type Month = (typeof MONTH_FORMATS)[number];
|
|
43
43
|
export type Day = (typeof DAY_FORMATS)[number];
|
|
44
|
-
export type
|
|
44
|
+
export type MonthDate = (typeof DATE_FORMATS)[number];
|
|
45
45
|
export type Hour = (typeof HOUR_FORMATS)[number];
|
|
46
46
|
export type Minute = (typeof MINUTE_FORMATS)[number];
|
|
47
47
|
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
|
-
export type ChronosFormat = Year | Month | Day |
|
|
50
|
+
export type ChronosFormat = Year | Month | Day | MonthDate | Hour | Minute | Second | Millisecond | TimeFormats;
|
|
51
51
|
/** Standard date formats. */
|
|
52
|
-
export type DateParts = `${
|
|
52
|
+
export type DateParts = `${MonthDate} ${Exclude<Month, 'M' | 'MM'>}` | `${Exclude<Month, 'M' | 'MM'>} ${MonthDate}` | `${Day}, ${MonthDate} ${Exclude<Month, 'M' | 'MM'>}` | `${Day}, ${Exclude<Month, 'M' | 'MM'>} ${MonthDate}` | `${Exclude<Month, 'M' | 'MM'>} ${MonthDate}, ${Year}` | `${MonthDate} ${Exclude<Month, 'M' | 'MM'>}, ${Year}` | `${Exclude<Month, 'M' | 'MM'>} ${MonthDate} ${Year}` | `${MonthDate} ${Exclude<Month, 'M' | 'MM'>} ${Year}` | `${Day}, ${Exclude<Month, 'M' | 'MM'>} ${MonthDate}, ${Year}` | `${Day}, ${MonthDate} ${Exclude<Month, 'M' | 'MM'>}, ${Year}` | `${Day}, ${Exclude<Month, 'M' | 'MM'>} ${MonthDate} ${Year}` | `${Day}, ${MonthDate} ${Exclude<Month, 'M' | 'MM'>} ${Year}` | `${Exclude<MonthDate, 'Do'>}.${Exclude<Month, 'mmm' | 'mmmm'>}.${Year}` | `${Year}.${Exclude<Month, 'mmm' | 'mmmm'>}.${Exclude<MonthDate, 'Do'>}` | `${Exclude<MonthDate, 'Do'>}/${Exclude<Month, 'mmm' | 'mmmm'>}/${Year}` | `${Exclude<MonthDate, 'Do'>}-${Exclude<Month, 'mmm' | 'mmmm'>}-${Year}` | `${Exclude<Month, 'mmm' | 'mmmm'>}/${Exclude<MonthDate, 'Do'>}/${Year}` | `${Exclude<Month, 'mmm' | 'mmmm'>}-${Exclude<MonthDate, 'Do'>}-${Year}` | `${Year}-${Exclude<Month, 'mmm' | 'mmmm'>}-${Exclude<MonthDate, 'Do'>}` | `${Year}/${Exclude<Month, 'mmm' | 'mmmm'>}/${Exclude<MonthDate, 'Do'>}` | `${Year}-${Exclude<MonthDate, 'Do'>}-${Exclude<Month, 'mmm' | 'mmmm'>}` | `${Year}/${Exclude<MonthDate, 'Do'>}/${Exclude<Month, 'mmm' | 'mmmm'>}`;
|
|
53
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 = ' ' | ', ' | '; ' | ' - ';
|
|
@@ -78,6 +78,7 @@ export type ChronosMethods = {
|
|
|
78
78
|
[key in K]: (...args: any[]) => Chronos;
|
|
79
79
|
} ? K : never;
|
|
80
80
|
}[keyof typeof Chronos];
|
|
81
|
+
/** All the statics methods in `Chronos` class */
|
|
81
82
|
export interface ChronosStatics {
|
|
82
83
|
(date?: number | string | Date | Chronos): Chronos;
|
|
83
84
|
/**
|
|
@@ -121,24 +122,33 @@ export interface ChronosStatics {
|
|
|
121
122
|
* * Creates UTC Chronos
|
|
122
123
|
* @param dateLike Date input to create utc time.
|
|
123
124
|
*/
|
|
124
|
-
utc(dateLike: number | string |
|
|
125
|
+
utc(dateLike: number | string | MonthDate | Chronos): Chronos;
|
|
125
126
|
/**
|
|
126
127
|
* * Returns earliest Chronos
|
|
127
128
|
* @param dates Date inputs.
|
|
128
129
|
*/
|
|
129
|
-
min(...dates: (number | string |
|
|
130
|
+
min(...dates: (number | string | MonthDate | Chronos)[]): Chronos;
|
|
130
131
|
/**
|
|
131
132
|
* * Returns latest Chronos
|
|
132
133
|
* @param dates Date inputs.
|
|
133
134
|
*/
|
|
134
|
-
max(...dates: (number | string |
|
|
135
|
+
max(...dates: (number | string | MonthDate | Chronos)[]): Chronos;
|
|
135
136
|
/**
|
|
136
|
-
* * Checks if the year in the date string is a leap year.
|
|
137
|
+
* * Checks if the year in the date string or year (from 0 - 9999) is a leap year.
|
|
137
138
|
* - A year is a leap year if it is divisible by 4, but not divisible by 100, unless it is also divisible by 400.
|
|
138
139
|
* - For example, 2000 and 2400 are leap years, but 1900 and 2100 are not.
|
|
140
|
+
*
|
|
141
|
+
* @description
|
|
142
|
+
* This method accepts different types of date inputs and extracts the year to check if it's a leap year.
|
|
143
|
+
* If the provided date is a `number`, it will be treated as a year (must be a valid year from 0 to 9999).
|
|
144
|
+
* If the year is out of this range (negative or larger than 9999), it will be treated as a Unix timestamp.
|
|
145
|
+
* If the provided date is a string or a `Date` object, it will be parsed and the year will be extracted.
|
|
146
|
+
* If a `Chronos` instance is passed, the year will be directly accessed from the instance.
|
|
147
|
+
*
|
|
148
|
+
* @param date - A `number` (year or Unix timestamp), `string`, `Date`, or `Chronos` instance representing a date.
|
|
139
149
|
* @returns `true` if the year is a leap year, `false` otherwise.
|
|
140
150
|
*/
|
|
141
|
-
isLeapYear(date: number | string |
|
|
151
|
+
isLeapYear(date: number | string | MonthDate | Chronos): boolean;
|
|
142
152
|
/**
|
|
143
153
|
* * Checks if the given value is a valid `Date` object.
|
|
144
154
|
* - A value is considered valid if it is an instance of the built-in `Date` class.
|
|
@@ -146,7 +156,7 @@ export interface ChronosStatics {
|
|
|
146
156
|
* @param value - The value to test.
|
|
147
157
|
* @returns `true` if the value is a valid Date object, otherwise `false`.
|
|
148
158
|
*/
|
|
149
|
-
isValidDate(value: unknown): value is
|
|
159
|
+
isValidDate(value: unknown): value is MonthDate;
|
|
150
160
|
/**
|
|
151
161
|
* * Checks if the given value is a valid date string.
|
|
152
162
|
* - A value is considered a valid date string if it is a string and can be parsed by `Date.parse()`.
|
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,EACV,YAAY,EACZ,MAAM,aAAa,CAAC;AAErB,mDAAmD;AACnD,MAAM,MAAM,KAAK,GACd,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ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L,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,CAAC;AAET,MAAM,MAAM,eAAe,GACxB,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,CAAC;AAET,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAElD,MAAM,MAAM,SAAS,GAAG,MAAM,eAAe,GAAG,eAAe,IAAI,SAAS,EAAE,CAAC;AAE/E,uBAAuB;AACvB,MAAM,WAAW,aAAa;IAC7B,+GAA+G;IAC/G,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sDAAsD;IACtD,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { capitalizeString, generateRandomID, trimString, truncateString, } from './string/basics';
|
|
2
2
|
export { generateAnagrams } from './string/anagram';
|
|
3
3
|
export { isCamelCase, isEmojiOnly, isKebabCase, isPalindrome, isPascalCase, isSnakeCase, } from './string/guards';
|
|
4
|
-
export { convertStringCase, extractEmails, extractURLs, maskString, normalizeString, replaceAllInString, reverseString, slugifyString, } from './string/convert';
|
|
4
|
+
export { convertStringCase, extractEmails, extractURLs, maskString, normalizeString, replaceAllInString, reverseString, slugifyString, formatUnitWithPlural, formatUnitWithPlural as formatWithPlural, formatUnitWithPlural as formatNumberWithPluralUnit, } from './string/convert';
|
|
5
5
|
export { extractNumbersFromString, getLevenshteinDistance, getLevenshteinDistance as levenshteinDistance, } from './string/utilities';
|
|
6
6
|
export { calculateHCF as calculateGCD, calculateHCF, calculateLCM as calculateLCD, calculateLCM, convertToDecimal, getFibonacciSeries as getFibonacci, getFibonacciSeries as getFibonacciNumbers, getFibonacciSeries, getRandomNumber, sumNumbers as getSumOfNumbers, reverseNumber, sumDigits, sumNumbers, sumNumbers as sumOfNumbers, } from './number/basics';
|
|
7
7
|
export { isEven, isEven as isEvenNumber, isFibonacci, isMultiple, isOdd, isOdd as isOddNumber, isFibonacci as isParOfFibonacci, isFibonacci as isParOfFibonacciSeries, isPerfectSquare, } from './number/guards';
|
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,
|
|
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,EACb,oBAAoB,EACpB,oBAAoB,IAAI,gBAAgB,EACxC,oBAAoB,IAAI,0BAA0B,GAClD,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,wBAAwB,EACxB,sB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B,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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export { capitalizeString, generateRandomID, trimString, truncateString, } from './string/basics';
|
|
3
3
|
export { generateAnagrams } from './string/anagram';
|
|
4
4
|
export { isCamelCase, isEmojiOnly, isKebabCase, isPalindrome, isPascalCase, isSnakeCase, } from './string/guards';
|
|
5
|
-
export { convertStringCase, extractEmails, extractURLs, maskString, normalizeString, replaceAllInString, reverseString, slugifyString, } from './string/convert';
|
|
5
|
+
export { convertStringCase, extractEmails, extractURLs, maskString, normalizeString, replaceAllInString, reverseString, slugifyString, formatUnitWithPlural, formatUnitWithPlural as formatWithPlural, formatUnitWithPlural as formatNumberWithPluralUnit, } from './string/convert';
|
|
6
6
|
export { extractNumbersFromString, getLevenshteinDistance, getLevenshteinDistance as levenshteinDistance, } from './string/utilities';
|
|
7
7
|
// ! Number Utilities
|
|
8
8
|
export { calculateHCF as calculateGCD, calculateHCF, calculateLCM as calculateLCD, calculateLCM, convertToDecimal, getFibonacciSeries as getFibonacci, getFibonacciSeries as getFibonacciNumbers, getFibonacciSeries, getRandomNumber, sumNumbers as getSumOfNumbers, reverseNumber, sumDigits, sumNumbers, sumNumbers as sumOfNumbers, } from './number/basics';
|
package/dist/string/convert.d.ts
CHANGED
|
@@ -74,4 +74,13 @@ export declare function extractEmails(str: string): string[];
|
|
|
74
74
|
* @returns An array of extracted URLs.
|
|
75
75
|
*/
|
|
76
76
|
export declare function extractURLs(str: string): string[];
|
|
77
|
+
/**
|
|
78
|
+
* * Returns a grammatically correct unit string, optionally prefixed with the number.
|
|
79
|
+
*
|
|
80
|
+
* @param count The numeric value to determine singular or plural.
|
|
81
|
+
* @param unit The unit name (e.g., "day", "hour").
|
|
82
|
+
* @param withNumber Whether to prefix the count before the unit. Defaults to `true`.
|
|
83
|
+
* @returns Formatted unit string like `"1 day"`, `"2 months"`, or `"hour"`.
|
|
84
|
+
*/
|
|
85
|
+
export declare function formatUnitWithPlural(count: number, unit: string, withNumber?: boolean): string;
|
|
77
86
|
//# sourceMappingURL=convert.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/string/convert.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,MAAM,CAqF5E;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,UACvB,MAAM,QACP,MAAM,GAAG,MAAM,WACZ,MAAM,KACb,MAYF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,UAAW,MAAM,KAAG,SAAS,CAAC,MAAM,CAK7D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,UAAW,MAAM,YAAY,WAAW,KAAG,MAcjE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,UAAW,MAAM,KAAG,MAI7C,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAEjD"}
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/string/convert.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,MAAM,CAqF5E;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,UACvB,MAAM,QACP,MAAM,GAAG,MAAM,WACZ,MAAM,KACb,MAYF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,UAAW,MAAM,KAAG,SAAS,CAAC,MAAM,CAK7D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,UAAW,MAAM,YAAY,WAAW,KAAG,MAcjE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,UAAW,MAAM,KAAG,MAI7C,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAEjD;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,UAAU,UAAO,GACf,MAAM,CAKR"}
|
package/dist/string/convert.js
CHANGED
|
@@ -162,3 +162,16 @@ export function extractEmails(str) {
|
|
|
162
162
|
export function extractURLs(str) {
|
|
163
163
|
return str.match(/https?:\/\/[^\s/$.?#].[^\s]*/g) || [];
|
|
164
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* * Returns a grammatically correct unit string, optionally prefixed with the number.
|
|
167
|
+
*
|
|
168
|
+
* @param count The numeric value to determine singular or plural.
|
|
169
|
+
* @param unit The unit name (e.g., "day", "hour").
|
|
170
|
+
* @param withNumber Whether to prefix the count before the unit. Defaults to `true`.
|
|
171
|
+
* @returns Formatted unit string like `"1 day"`, `"2 months"`, or `"hour"`.
|
|
172
|
+
*/
|
|
173
|
+
export function formatUnitWithPlural(count, unit, withNumber = true) {
|
|
174
|
+
const abs = Math.abs(count);
|
|
175
|
+
const pluralized = abs === 1 ? unit : `${unit}s`;
|
|
176
|
+
return withNumber ? `${count} ${pluralized}` : pluralized;
|
|
177
|
+
}
|
package/package.json
CHANGED