@kikiutils/shared 18.1.0 → 18.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/enhanced-date.d.ts +32 -0
- package/dist/classes/enhanced-date.d.ts.map +1 -1
- package/dist/classes/enhanced-date.js +44 -0
- package/dist/classes/enhanced-date.js.map +1 -1
- package/dist/classes/path.d.ts +1 -0
- package/dist/classes/path.d.ts.map +1 -1
- package/dist/classes/path.js +7 -2
- package/dist/classes/path.js.map +1 -1
- package/dist/classes/ssh-client.d.ts +1 -0
- package/dist/clipboard.d.ts +1 -0
- package/dist/file.d.ts +27 -0
- package/dist/file.d.ts.map +1 -0
- package/dist/file.js +31 -0
- package/dist/file.js.map +1 -0
- package/dist/math.d.ts +1 -0
- package/dist/pino.d.ts +3 -2
- package/dist/pino.d.ts.map +1 -1
- package/dist/storages/lru/keyed-store.d.ts +2 -0
- package/dist/storages/lru/keyed-store.d.ts.map +1 -1
- package/dist/storages/lru/keyed-store.js +5 -1
- package/dist/storages/lru/keyed-store.js.map +1 -1
- package/dist/types/filtered-key-path.d.ts +1 -0
- package/package.json +17 -12
- package/src/classes/enhanced-date.ts +50 -0
- package/src/classes/path.ts +13 -2
- package/src/file.ts +37 -0
- package/src/storages/lru/keyed-store.ts +4 -0
|
@@ -34,6 +34,14 @@ export declare class EnhancedDate extends Date {
|
|
|
34
34
|
* Returns a new instance at the end of today in the system time zone.
|
|
35
35
|
*/
|
|
36
36
|
static endOfToday(): EnhancedDate;
|
|
37
|
+
/**
|
|
38
|
+
* Returns a new instance at the end of tomorrow in the system time zone.
|
|
39
|
+
*/
|
|
40
|
+
static endOfTomorrow(): EnhancedDate;
|
|
41
|
+
/**
|
|
42
|
+
* Returns a new instance at the end of yesterday in the system time zone.
|
|
43
|
+
*/
|
|
44
|
+
static endOfYesterday(): EnhancedDate;
|
|
37
45
|
/**
|
|
38
46
|
* Parses a date using date-fns and an explicit reference for missing fields.
|
|
39
47
|
*
|
|
@@ -60,10 +68,34 @@ export declare class EnhancedDate extends Date {
|
|
|
60
68
|
* @param seconds - Seconds since the Unix epoch.
|
|
61
69
|
*/
|
|
62
70
|
static fromUnixSeconds(seconds: number): EnhancedDate;
|
|
71
|
+
/**
|
|
72
|
+
* Returns the latest date as a new independent instance.
|
|
73
|
+
*
|
|
74
|
+
* @param dates - Dates or millisecond timestamps to compare.
|
|
75
|
+
*
|
|
76
|
+
* @returns A new `EnhancedDate`, or `Invalid Date` if the array is empty or contains an invalid date.
|
|
77
|
+
*/
|
|
78
|
+
static max(dates: (Date | number)[]): EnhancedDate;
|
|
79
|
+
/**
|
|
80
|
+
* Returns the earliest date as a new independent instance.
|
|
81
|
+
*
|
|
82
|
+
* @param dates - Dates or millisecond timestamps to compare.
|
|
83
|
+
*
|
|
84
|
+
* @returns A new `EnhancedDate`, or `Invalid Date` if the array is empty or contains an invalid date.
|
|
85
|
+
*/
|
|
86
|
+
static min(dates: (Date | number)[]): EnhancedDate;
|
|
63
87
|
/**
|
|
64
88
|
* Returns a new instance at the start of today in the system time zone.
|
|
65
89
|
*/
|
|
66
90
|
static startOfToday(): EnhancedDate;
|
|
91
|
+
/**
|
|
92
|
+
* Returns a new instance at the start of tomorrow in the system time zone.
|
|
93
|
+
*/
|
|
94
|
+
static startOfTomorrow(): EnhancedDate;
|
|
95
|
+
/**
|
|
96
|
+
* Returns a new instance at the start of yesterday in the system time zone.
|
|
97
|
+
*/
|
|
98
|
+
static startOfYesterday(): EnhancedDate;
|
|
67
99
|
/**
|
|
68
100
|
* Adds the specified number of days in place using date-fns.
|
|
69
101
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enhanced-date.d.ts","names":[],"sources":["../../src/classes/enhanced-date.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA+Ba,qBAAqB;;;;SAMvB,cAAU;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"enhanced-date.d.ts","names":[],"sources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;;EAY9B,QAAQ;;;;;;;;EAYR,SAAS;;;;;;;;EAYT,gBAAgB;;;;;;;;EAYhB,WAAW;;;;;;;;EAYX,UAAU;;;;;;;;EAYV,WAAW;;;;;;;;EAYX,SAAS;;;;;;;;EAYT,SAAS;;;;EAQT,UAAU,iBAAc;;;;EAOxB,WAAW,iBAAc;;;;EAOzB,kBAAkB,iBAAc;;;;EAOhC,aAAa,iBAAc;;;;EAO3B,YAAY,iBAAc;;;;EAO1B,aAAa,iBAAc;;;;EAO3B,WAAW,iBAAc;;;;EAOzB,WAAW,iBAAc;;;;EAOzB,UAAM;;;;EAON,cAAU;;;;EAOV,iBAAa;;;;EAOb,gBAAY;;;;EAOZ,YAAY,UAAU,QAAQ,mBAAgB;;;;EAO9C,gBAAY;;;;EAOZ,mBAAe;;;;EAOf,kBAAc;;;;EAOd,cAAc,UAAU,QAAQ,qBAAkB;;;;EAOlD,UAAU,iBAAc;;;;EAOxB,WAAW,iBAAc;;;;EAOzB,kBAAkB,iBAAc;;;;EAOhC,aAAa,iBAAc;;;;EAO3B,YAAY,iBAAc;;;;EAO1B,aAAa,iBAAc;;;;EAO3B,WAAW,iBAAc;;;;EAOzB,WAAW,iBAAc"}
|
|
@@ -37,6 +37,18 @@ var EnhancedDate = class EnhancedDate extends Date {
|
|
|
37
37
|
return new EnhancedDate(dateFns.endOfToday());
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
|
+
* Returns a new instance at the end of tomorrow in the system time zone.
|
|
41
|
+
*/
|
|
42
|
+
static endOfTomorrow() {
|
|
43
|
+
return new EnhancedDate(dateFns.endOfTomorrow());
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns a new instance at the end of yesterday in the system time zone.
|
|
47
|
+
*/
|
|
48
|
+
static endOfYesterday() {
|
|
49
|
+
return new EnhancedDate(dateFns.endOfYesterday());
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
40
52
|
* Parses a date using date-fns and an explicit reference for missing fields.
|
|
41
53
|
*
|
|
42
54
|
* @param value - Date string to parse.
|
|
@@ -69,12 +81,44 @@ var EnhancedDate = class EnhancedDate extends Date {
|
|
|
69
81
|
return new EnhancedDate(seconds * 1e3);
|
|
70
82
|
}
|
|
71
83
|
/**
|
|
84
|
+
* Returns the latest date as a new independent instance.
|
|
85
|
+
*
|
|
86
|
+
* @param dates - Dates or millisecond timestamps to compare.
|
|
87
|
+
*
|
|
88
|
+
* @returns A new `EnhancedDate`, or `Invalid Date` if the array is empty or contains an invalid date.
|
|
89
|
+
*/
|
|
90
|
+
static max(dates) {
|
|
91
|
+
return new EnhancedDate(dateFns.max(dates));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Returns the earliest date as a new independent instance.
|
|
95
|
+
*
|
|
96
|
+
* @param dates - Dates or millisecond timestamps to compare.
|
|
97
|
+
*
|
|
98
|
+
* @returns A new `EnhancedDate`, or `Invalid Date` if the array is empty or contains an invalid date.
|
|
99
|
+
*/
|
|
100
|
+
static min(dates) {
|
|
101
|
+
return new EnhancedDate(dateFns.min(dates));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
72
104
|
* Returns a new instance at the start of today in the system time zone.
|
|
73
105
|
*/
|
|
74
106
|
static startOfToday() {
|
|
75
107
|
return new EnhancedDate(dateFns.startOfToday());
|
|
76
108
|
}
|
|
77
109
|
/**
|
|
110
|
+
* Returns a new instance at the start of tomorrow in the system time zone.
|
|
111
|
+
*/
|
|
112
|
+
static startOfTomorrow() {
|
|
113
|
+
return new EnhancedDate(dateFns.startOfTomorrow());
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Returns a new instance at the start of yesterday in the system time zone.
|
|
117
|
+
*/
|
|
118
|
+
static startOfYesterday() {
|
|
119
|
+
return new EnhancedDate(dateFns.startOfYesterday());
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
78
122
|
* Adds the specified number of days in place using date-fns.
|
|
79
123
|
*
|
|
80
124
|
* @param amount - Number of days.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enhanced-date.js","names":[],"sources":["../../src/classes/enhanced-date.ts"],"sourcesContent":["import * as dateFns from 'date-fns';\n\n/**\n * A mutable calendar date with chainable date-fns operations.\n *\n * @remarks\n * Inherits the native constructor, including zero-based month arguments and millisecond timestamps.\n * Native methods retain their original behavior.\n * Mutating arithmetic and boundary methods update this instance and return `this`;\n * their `to`-prefixed counterparts return a new `EnhancedDate` instead.\n * Invalid dates, parsing, rounding, and week defaults follow date-fns semantics.\n * Operations use the system time zone unless configured through date-fns options.\n * Day and week arithmetic uses calendar days, preserving local wall-clock time across daylight saving changes.\n * Hour, minute, second, and millisecond arithmetic uses elapsed durations. Month and year arithmetic clamps\n * to the last valid day of the destination month. Native setters retain their native overflow behavior.\n * Exceptions from date-fns propagate unchanged, and operations can preserve or produce `Invalid Date`.\n *\n * When used in Vue state, prefer replacing the value with a `to`-prefixed result:\n * mutating a Date's internal timestamp does not trigger reactive updates.\n *\n * @example\n *\n * ```ts\n * import { EnhancedDate } from '@kikiutils/shared/classes/enhanced-date';\n *\n * const date = new EnhancedDate('2026-01-31T12:00:00Z');\n * const nextMonth = date.toAddMonths(1); // Original date is unchanged.\n * date.addDays(1).startOfDay(); // Mutates the original date.\n * nextMonth.isAfter(date);\n * ```\n */\nexport class EnhancedDate extends Date {\n // Public static methods\n\n /**\n * Returns a new instance at the end of today in the system time zone.\n */\n static endOfToday() {\n return new EnhancedDate(dateFns.endOfToday());\n }\n\n /**\n * Parses a date using date-fns and an explicit reference for missing fields.\n *\n * @param value - Date string to parse.\n * @param pattern - date-fns parsing pattern.\n * @param referenceDate - Reference for fields absent from the pattern.\n * @param options - Options passed to `date-fns/parse`.\n *\n * @returns A new `EnhancedDate`, including `Invalid Date` for invalid values.\n */\n static fromFormat(\n value: string,\n pattern: string,\n referenceDate: dateFns.DateArg<Date>,\n options?: dateFns.ParseOptions,\n ) {\n return new EnhancedDate(dateFns.parse(value, pattern, referenceDate, options));\n }\n\n /**\n * Parses an ISO 8601 string using date-fns, including its partial-date support.\n *\n * @param value - ISO date string.\n * @param options - Options passed to `date-fns/parseISO`.\n *\n * @returns A new `EnhancedDate`, or `Invalid Date` when parsing fails.\n */\n static fromISO(value: string, options?: dateFns.ParseISOOptions) {\n return new EnhancedDate(dateFns.parseISO(value, options));\n }\n\n /**\n * Creates a date from Unix seconds; native constructor numbers remain milliseconds.\n *\n * @param seconds - Seconds since the Unix epoch.\n */\n static fromUnixSeconds(seconds: number) {\n return new EnhancedDate(seconds * 1000);\n }\n\n /**\n * Returns a new instance at the start of today in the system time zone.\n */\n static startOfToday() {\n return new EnhancedDate(dateFns.startOfToday());\n }\n\n // Public instance methods\n\n /**\n * Adds the specified number of days in place using date-fns.\n *\n * @param amount - Number of days.\n *\n * @returns This instance for chaining.\n */\n addDays(amount: number) {\n this.setTime(dateFns.addDays(this, amount).getTime());\n return this;\n }\n\n /**\n * Adds the specified number of hours in place using date-fns.\n *\n * @param amount - Number of hours.\n *\n * @returns This instance for chaining.\n */\n addHours(amount: number) {\n this.setTime(dateFns.addHours(this, amount).getTime());\n return this;\n }\n\n /**\n * Adds the specified number of milliseconds in place using date-fns.\n *\n * @param amount - Number of milliseconds.\n *\n * @returns This instance for chaining.\n */\n addMilliseconds(amount: number) {\n this.setTime(dateFns.addMilliseconds(this, amount).getTime());\n return this;\n }\n\n /**\n * Adds the specified number of minutes in place using date-fns.\n *\n * @param amount - Number of minutes.\n *\n * @returns This instance for chaining.\n */\n addMinutes(amount: number) {\n this.setTime(dateFns.addMinutes(this, amount).getTime());\n return this;\n }\n\n /**\n * Adds the specified number of months in place using date-fns.\n *\n * @param amount - Number of months.\n *\n * @returns This instance for chaining.\n */\n addMonths(amount: number) {\n this.setTime(dateFns.addMonths(this, amount).getTime());\n return this;\n }\n\n /**\n * Adds the specified number of seconds in place using date-fns.\n *\n * @param amount - Number of seconds.\n *\n * @returns This instance for chaining.\n */\n addSeconds(amount: number) {\n this.setTime(dateFns.addSeconds(this, amount).getTime());\n return this;\n }\n\n /**\n * Adds the specified number of weeks in place using date-fns.\n *\n * @param amount - Number of weeks.\n *\n * @returns This instance for chaining.\n */\n addWeeks(amount: number) {\n this.setTime(dateFns.addWeeks(this, amount).getTime());\n return this;\n }\n\n /**\n * Adds the specified number of years in place using date-fns.\n *\n * @param amount - Number of years.\n *\n * @returns This instance for chaining.\n */\n addYears(amount: number) {\n this.setTime(dateFns.addYears(this, amount).getTime());\n return this;\n }\n\n /**\n * Returns a new `EnhancedDate` with the same timestamp, including `Invalid Date`.\n */\n clone() {\n return new EnhancedDate(this.getTime());\n }\n\n /**\n * Returns the signed difference in calendar days: this date minus the other date.\n *\n * @remarks\n * Defaults and rounding follow date-fns.\n */\n differenceInCalendarDays(other: dateFns.DateArg<Date>) {\n return dateFns.differenceInCalendarDays(this, other);\n }\n\n /**\n * Returns the signed difference in calendar weeks: this date minus the other date.\n *\n * @remarks\n * Defaults and rounding follow date-fns.\n */\n differenceInCalendarWeeks(other: dateFns.DateArg<Date>, options?: dateFns.DifferenceInCalendarWeeksOptions) {\n return dateFns.differenceInCalendarWeeks(this, other, options);\n }\n\n /**\n * Returns the signed difference in full minutes: this date minus the other date.\n *\n * @remarks\n * Defaults and rounding follow date-fns.\n */\n differenceInMinutes(other: dateFns.DateArg<Date>, options?: dateFns.DifferenceInMinutesOptions) {\n return dateFns.differenceInMinutes(this, other, options);\n }\n\n /**\n * Moves this date to the end of its day in place.\n *\n * @returns This instance for chaining.\n */\n endOfDay() {\n this.setTime(dateFns.endOfDay(this).getTime());\n return this;\n }\n\n /**\n * Moves this date to the end of its minute in place.\n *\n * @returns This instance for chaining.\n */\n endOfMinute() {\n this.setTime(dateFns.endOfMinute(this).getTime());\n return this;\n }\n\n /**\n * Moves this date to the end of its month in place.\n *\n * @returns This instance for chaining.\n */\n endOfMonth() {\n this.setTime(dateFns.endOfMonth(this).getTime());\n return this;\n }\n\n /**\n * Moves this date to the end of its week in place.\n *\n * @param options - date-fns week options; defaults are unchanged.\n *\n * @returns This instance for chaining.\n */\n endOfWeek(options?: dateFns.EndOfWeekOptions) {\n this.setTime(dateFns.endOfWeek(this, options).getTime());\n return this;\n }\n\n /**\n * Formats this date using a date-fns pattern (default: `yyyy-MM-dd HH:mm:ss`) and optional locale/options.\n *\n * @remarks\n * Invalid dates and invalid patterns retain date-fns error behavior.\n */\n format(pattern: string = 'yyyy-MM-dd HH:mm:ss', options?: dateFns.FormatOptions) {\n return dateFns.format(this, pattern, options);\n }\n\n /**\n * Formats the distance from this date to now using date-fns.\n */\n formatDistanceToNow(options?: dateFns.FormatDistanceToNowOptions) {\n return dateFns.formatDistanceToNow(this, options);\n }\n\n /**\n * Returns Unix seconds using date-fns; `getTime()` returns milliseconds.\n */\n getUnixTime() {\n return dateFns.getUnixTime(this);\n }\n\n /**\n * Checks whether this date occurs after the other date.\n */\n isAfter(other: dateFns.DateArg<Date>) {\n return dateFns.isAfter(this, other);\n }\n\n /**\n * Checks whether this date occurs before the other date.\n */\n isBefore(other: dateFns.DateArg<Date>) {\n return dateFns.isBefore(this, other);\n }\n\n /**\n * Checks whether this date has the same timestamp as the other date.\n */\n isEqual(other: dateFns.DateArg<Date>) {\n return dateFns.isEqual(this, other);\n }\n\n /**\n * Checks whether this date is after the current time.\n */\n isFuture() {\n return dateFns.isFuture(this);\n }\n\n /**\n * Checks whether this date falls on the same calendar day as the other date.\n */\n isSameDay(other: dateFns.DateArg<Date>) {\n return dateFns.isSameDay(this, other);\n }\n\n /**\n * Checks whether this date falls in the same calendar minute as the other date.\n */\n isSameMinute(other: dateFns.DateArg<Date>) {\n return dateFns.isSameMinute(this, other);\n }\n\n /**\n * Checks whether this date falls on today.\n */\n isToday() {\n return dateFns.isToday(this);\n }\n\n /**\n * Checks whether this date falls on tomorrow.\n */\n isTomorrow() {\n return dateFns.isTomorrow(this);\n }\n\n /**\n * Checks whether this date has a valid timestamp.\n */\n isValid() {\n return dateFns.isValid(this);\n }\n\n /**\n * Moves this date to the start of its day in place.\n *\n * @returns This instance for chaining.\n */\n startOfDay() {\n this.setTime(dateFns.startOfDay(this).getTime());\n return this;\n }\n\n /**\n * Moves this date to the start of its minute in place.\n *\n * @returns This instance for chaining.\n */\n startOfMinute() {\n this.setTime(dateFns.startOfMinute(this).getTime());\n return this;\n }\n\n /**\n * Moves this date to the start of its month in place.\n *\n * @returns This instance for chaining.\n */\n startOfMonth() {\n this.setTime(dateFns.startOfMonth(this).getTime());\n return this;\n }\n\n /**\n * Moves this date to the start of its week in place.\n *\n * @param options - date-fns week options; defaults are unchanged.\n *\n * @returns This instance for chaining.\n */\n startOfWeek(options?: dateFns.StartOfWeekOptions) {\n this.setTime(dateFns.startOfWeek(this, options).getTime());\n return this;\n }\n\n /**\n * Subtracts the specified number of days in place using date-fns.\n *\n * @param amount - Number of days.\n *\n * @returns This instance for chaining.\n */\n subDays(amount: number) {\n this.setTime(dateFns.subDays(this, amount).getTime());\n return this;\n }\n\n /**\n * Subtracts the specified number of hours in place using date-fns.\n *\n * @param amount - Number of hours.\n *\n * @returns This instance for chaining.\n */\n subHours(amount: number) {\n this.setTime(dateFns.subHours(this, amount).getTime());\n return this;\n }\n\n /**\n * Subtracts the specified number of milliseconds in place using date-fns.\n *\n * @param amount - Number of milliseconds.\n *\n * @returns This instance for chaining.\n */\n subMilliseconds(amount: number) {\n this.setTime(dateFns.subMilliseconds(this, amount).getTime());\n return this;\n }\n\n /**\n * Subtracts the specified number of minutes in place using date-fns.\n *\n * @param amount - Number of minutes.\n *\n * @returns This instance for chaining.\n */\n subMinutes(amount: number) {\n this.setTime(dateFns.subMinutes(this, amount).getTime());\n return this;\n }\n\n /**\n * Subtracts the specified number of months in place using date-fns.\n *\n * @param amount - Number of months.\n *\n * @returns This instance for chaining.\n */\n subMonths(amount: number) {\n this.setTime(dateFns.subMonths(this, amount).getTime());\n return this;\n }\n\n /**\n * Subtracts the specified number of seconds in place using date-fns.\n *\n * @param amount - Number of seconds.\n *\n * @returns This instance for chaining.\n */\n subSeconds(amount: number) {\n this.setTime(dateFns.subSeconds(this, amount).getTime());\n return this;\n }\n\n /**\n * Subtracts the specified number of weeks in place using date-fns.\n *\n * @param amount - Number of weeks.\n *\n * @returns This instance for chaining.\n */\n subWeeks(amount: number) {\n this.setTime(dateFns.subWeeks(this, amount).getTime());\n return this;\n }\n\n /**\n * Subtracts the specified number of years in place using date-fns.\n *\n * @param amount - Number of years.\n *\n * @returns This instance for chaining.\n */\n subYears(amount: number) {\n this.setTime(dateFns.subYears(this, amount).getTime());\n return this;\n }\n\n /**\n * Returns a new instance with days added, leaving this date unchanged.\n */\n toAddDays(amount: number) {\n return this.clone().addDays(amount);\n }\n\n /**\n * Returns a new instance with hours added, leaving this date unchanged.\n */\n toAddHours(amount: number) {\n return this.clone().addHours(amount);\n }\n\n /**\n * Returns a new instance with milliseconds added, leaving this date unchanged.\n */\n toAddMilliseconds(amount: number) {\n return this.clone().addMilliseconds(amount);\n }\n\n /**\n * Returns a new instance with minutes added, leaving this date unchanged.\n */\n toAddMinutes(amount: number) {\n return this.clone().addMinutes(amount);\n }\n\n /**\n * Returns a new instance with months added, leaving this date unchanged.\n */\n toAddMonths(amount: number) {\n return this.clone().addMonths(amount);\n }\n\n /**\n * Returns a new instance with seconds added, leaving this date unchanged.\n */\n toAddSeconds(amount: number) {\n return this.clone().addSeconds(amount);\n }\n\n /**\n * Returns a new instance with weeks added, leaving this date unchanged.\n */\n toAddWeeks(amount: number) {\n return this.clone().addWeeks(amount);\n }\n\n /**\n * Returns a new instance with years added, leaving this date unchanged.\n */\n toAddYears(amount: number) {\n return this.clone().addYears(amount);\n }\n\n /**\n * Returns a new plain native Date; mutations are not shared with this instance.\n */\n toDate() {\n return new Date(this.getTime());\n }\n\n /**\n * Returns a new instance at the end of this day, leaving this date unchanged.\n */\n toEndOfDay() {\n return this.clone().endOfDay();\n }\n\n /**\n * Returns a new instance at the end of this minute, leaving this date unchanged.\n */\n toEndOfMinute() {\n return this.clone().endOfMinute();\n }\n\n /**\n * Returns a new instance at the end of this month, leaving this date unchanged.\n */\n toEndOfMonth() {\n return this.clone().endOfMonth();\n }\n\n /**\n * Returns a new instance at the end of this week, leaving this date unchanged.\n */\n toEndOfWeek(options?: dateFns.EndOfWeekOptions) {\n return this.clone().endOfWeek(options);\n }\n\n /**\n * Returns a new instance at the start of this day, leaving this date unchanged.\n */\n toStartOfDay() {\n return this.clone().startOfDay();\n }\n\n /**\n * Returns a new instance at the start of this minute, leaving this date unchanged.\n */\n toStartOfMinute() {\n return this.clone().startOfMinute();\n }\n\n /**\n * Returns a new instance at the start of this month, leaving this date unchanged.\n */\n toStartOfMonth() {\n return this.clone().startOfMonth();\n }\n\n /**\n * Returns a new instance at the start of this week, leaving this date unchanged.\n */\n toStartOfWeek(options?: dateFns.StartOfWeekOptions) {\n return this.clone().startOfWeek(options);\n }\n\n /**\n * Returns a new instance with days subtracted, leaving this date unchanged.\n */\n toSubDays(amount: number) {\n return this.clone().subDays(amount);\n }\n\n /**\n * Returns a new instance with hours subtracted, leaving this date unchanged.\n */\n toSubHours(amount: number) {\n return this.clone().subHours(amount);\n }\n\n /**\n * Returns a new instance with milliseconds subtracted, leaving this date unchanged.\n */\n toSubMilliseconds(amount: number) {\n return this.clone().subMilliseconds(amount);\n }\n\n /**\n * Returns a new instance with minutes subtracted, leaving this date unchanged.\n */\n toSubMinutes(amount: number) {\n return this.clone().subMinutes(amount);\n }\n\n /**\n * Returns a new instance with months subtracted, leaving this date unchanged.\n */\n toSubMonths(amount: number) {\n return this.clone().subMonths(amount);\n }\n\n /**\n * Returns a new instance with seconds subtracted, leaving this date unchanged.\n */\n toSubSeconds(amount: number) {\n return this.clone().subSeconds(amount);\n }\n\n /**\n * Returns a new instance with weeks subtracted, leaving this date unchanged.\n */\n toSubWeeks(amount: number) {\n return this.clone().subWeeks(amount);\n }\n\n /**\n * Returns a new instance with years subtracted, leaving this date unchanged.\n */\n toSubYears(amount: number) {\n return this.clone().subYears(amount);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;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anced-date.ts"],"sourcesContent":["import * as dateFns from 'date-fns';\n\n/**\n * A mutable calendar date with chainable date-fns operations.\n *\n * @remarks\n * Inherits the native constructor, including zero-based month arguments and millisecond timestamps.\n * Native methods retain their original behavior.\n * Mutating arithmetic and boundary methods update this instance and return `this`;\n * their `to`-prefixed counterparts return a new `EnhancedDate` instead.\n * Invalid dates, parsing, rounding, and week defaults follow date-fns semantics.\n * Operations use the system time zone unless configured through date-fns options.\n * Day and week arithmetic uses calendar days, preserving local wall-clock time across daylight saving changes.\n * Hour, minute, second, and millisecond arithmetic uses elapsed durations. Month and year arithmetic clamps\n * to the last valid day of the destination month. Native setters retain their native overflow behavior.\n * Exceptions from date-fns propagate unchanged, and operations can preserve or produce `Invalid Date`.\n *\n * When used in Vue state, prefer replacing the value with a `to`-prefixed result:\n * mutating a Date's internal timestamp does not trigger reactive updates.\n *\n * @example\n *\n * ```ts\n * import { EnhancedDate } from '@kikiutils/shared/classes/enhanced-date';\n *\n * const date = new EnhancedDate('2026-01-31T12:00:00Z');\n * const nextMonth = date.toAddMonths(1); // Original date is unchanged.\n * date.addDays(1).startOfDay(); // Mutates the original date.\n * nextMonth.isAfter(date);\n * ```\n */\nexport class EnhancedDate extends Date {\n // Public static methods\n\n /**\n * Returns a new instance at the end of today in the system time zone.\n */\n static endOfToday() {\n return new EnhancedDate(dateFns.endOfToday());\n }\n\n /**\n * Returns a new instance at the end of tomorrow in the system time zone.\n */\n static endOfTomorrow() {\n return new EnhancedDate(dateFns.endOfTomorrow());\n }\n\n /**\n * Returns a new instance at the end of yesterday in the system time zone.\n */\n static endOfYesterday() {\n return new EnhancedDate(dateFns.endOfYesterday());\n }\n\n /**\n * Parses a date using date-fns and an explicit reference for missing fields.\n *\n * @param value - Date string to parse.\n * @param pattern - date-fns parsing pattern.\n * @param referenceDate - Reference for fields absent from the pattern.\n * @param options - Options passed to `date-fns/parse`.\n *\n * @returns A new `EnhancedDate`, including `Invalid Date` for invalid values.\n */\n static fromFormat(\n value: string,\n pattern: string,\n referenceDate: dateFns.DateArg<Date>,\n options?: dateFns.ParseOptions,\n ) {\n return new EnhancedDate(dateFns.parse(value, pattern, referenceDate, options));\n }\n\n /**\n * Parses an ISO 8601 string using date-fns, including its partial-date support.\n *\n * @param value - ISO date string.\n * @param options - Options passed to `date-fns/parseISO`.\n *\n * @returns A new `EnhancedDate`, or `Invalid Date` when parsing fails.\n */\n static fromISO(value: string, options?: dateFns.ParseISOOptions) {\n return new EnhancedDate(dateFns.parseISO(value, options));\n }\n\n /**\n * Creates a date from Unix seconds; native constructor numbers remain milliseconds.\n *\n * @param seconds - Seconds since the Unix epoch.\n */\n static fromUnixSeconds(seconds: number) {\n return new EnhancedDate(seconds * 1000);\n }\n\n /**\n * Returns the latest date as a new independent instance.\n *\n * @param dates - Dates or millisecond timestamps to compare.\n *\n * @returns A new `EnhancedDate`, or `Invalid Date` if the array is empty or contains an invalid date.\n */\n static max(dates: (Date | number)[]) {\n return new EnhancedDate(dateFns.max(dates));\n }\n\n /**\n * Returns the earliest date as a new independent instance.\n *\n * @param dates - Dates or millisecond timestamps to compare.\n *\n * @returns A new `EnhancedDate`, or `Invalid Date` if the array is empty or contains an invalid date.\n */\n static min(dates: (Date | number)[]) {\n return new EnhancedDate(dateFns.min(dates));\n }\n\n /**\n * Returns a new instance at the start of today in the system time zone.\n */\n static startOfToday() {\n return new EnhancedDate(dateFns.startOfToday());\n }\n\n /**\n * Returns a new instance at the start of tomorrow in the system time zone.\n */\n static startOfTomorrow() {\n return new EnhancedDate(dateFns.startOfTomorrow());\n }\n\n /**\n * Returns a new instance at the start of yesterday in the system time zone.\n */\n static startOfYesterday() {\n return new EnhancedDate(dateFns.startOfYesterday());\n }\n\n // Public instance methods\n\n /**\n * Adds the specified number of days in place using date-fns.\n *\n * @param amount - Number of days.\n *\n * @returns This instance for chaining.\n */\n addDays(amount: number) {\n this.setTime(dateFns.addDays(this, amount).getTime());\n return this;\n }\n\n /**\n * Adds the specified number of hours in place using date-fns.\n *\n * @param amount - Number of hours.\n *\n * @returns This instance for chaining.\n */\n addHours(amount: number) {\n this.setTime(dateFns.addHours(this, amount).getTime());\n return this;\n }\n\n /**\n * Adds the specified number of milliseconds in place using date-fns.\n *\n * @param amount - Number of milliseconds.\n *\n * @returns This instance for chaining.\n */\n addMilliseconds(amount: number) {\n this.setTime(dateFns.addMilliseconds(this, amount).getTime());\n return this;\n }\n\n /**\n * Adds the specified number of minutes in place using date-fns.\n *\n * @param amount - Number of minutes.\n *\n * @returns This instance for chaining.\n */\n addMinutes(amount: number) {\n this.setTime(dateFns.addMinutes(this, amount).getTime());\n return this;\n }\n\n /**\n * Adds the specified number of months in place using date-fns.\n *\n * @param amount - Number of months.\n *\n * @returns This instance for chaining.\n */\n addMonths(amount: number) {\n this.setTime(dateFns.addMonths(this, amount).getTime());\n return this;\n }\n\n /**\n * Adds the specified number of seconds in place using date-fns.\n *\n * @param amount - Number of seconds.\n *\n * @returns This instance for chaining.\n */\n addSeconds(amount: number) {\n this.setTime(dateFns.addSeconds(this, amount).getTime());\n return this;\n }\n\n /**\n * Adds the specified number of weeks in place using date-fns.\n *\n * @param amount - Number of weeks.\n *\n * @returns This instance for chaining.\n */\n addWeeks(amount: number) {\n this.setTime(dateFns.addWeeks(this, amount).getTime());\n return this;\n }\n\n /**\n * Adds the specified number of years in place using date-fns.\n *\n * @param amount - Number of years.\n *\n * @returns This instance for chaining.\n */\n addYears(amount: number) {\n this.setTime(dateFns.addYears(this, amount).getTime());\n return this;\n }\n\n /**\n * Returns a new `EnhancedDate` with the same timestamp, including `Invalid Date`.\n */\n clone() {\n return new EnhancedDate(this.getTime());\n }\n\n /**\n * Returns the signed difference in calendar days: this date minus the other date.\n *\n * @remarks\n * Defaults and rounding follow date-fns.\n */\n differenceInCalendarDays(other: dateFns.DateArg<Date>) {\n return dateFns.differenceInCalendarDays(this, other);\n }\n\n /**\n * Returns the signed difference in calendar weeks: this date minus the other date.\n *\n * @remarks\n * Defaults and rounding follow date-fns.\n */\n differenceInCalendarWeeks(other: dateFns.DateArg<Date>, options?: dateFns.DifferenceInCalendarWeeksOptions) {\n return dateFns.differenceInCalendarWeeks(this, other, options);\n }\n\n /**\n * Returns the signed difference in full minutes: this date minus the other date.\n *\n * @remarks\n * Defaults and rounding follow date-fns.\n */\n differenceInMinutes(other: dateFns.DateArg<Date>, options?: dateFns.DifferenceInMinutesOptions) {\n return dateFns.differenceInMinutes(this, other, options);\n }\n\n /**\n * Moves this date to the end of its day in place.\n *\n * @returns This instance for chaining.\n */\n endOfDay() {\n this.setTime(dateFns.endOfDay(this).getTime());\n return this;\n }\n\n /**\n * Moves this date to the end of its minute in place.\n *\n * @returns This instance for chaining.\n */\n endOfMinute() {\n this.setTime(dateFns.endOfMinute(this).getTime());\n return this;\n }\n\n /**\n * Moves this date to the end of its month in place.\n *\n * @returns This instance for chaining.\n */\n endOfMonth() {\n this.setTime(dateFns.endOfMonth(this).getTime());\n return this;\n }\n\n /**\n * Moves this date to the end of its week in place.\n *\n * @param options - date-fns week options; defaults are unchanged.\n *\n * @returns This instance for chaining.\n */\n endOfWeek(options?: dateFns.EndOfWeekOptions) {\n this.setTime(dateFns.endOfWeek(this, options).getTime());\n return this;\n }\n\n /**\n * Formats this date using a date-fns pattern (default: `yyyy-MM-dd HH:mm:ss`) and optional locale/options.\n *\n * @remarks\n * Invalid dates and invalid patterns retain date-fns error behavior.\n */\n format(pattern: string = 'yyyy-MM-dd HH:mm:ss', options?: dateFns.FormatOptions) {\n return dateFns.format(this, pattern, options);\n }\n\n /**\n * Formats the distance from this date to now using date-fns.\n */\n formatDistanceToNow(options?: dateFns.FormatDistanceToNowOptions) {\n return dateFns.formatDistanceToNow(this, options);\n }\n\n /**\n * Returns Unix seconds using date-fns; `getTime()` returns milliseconds.\n */\n getUnixTime() {\n return dateFns.getUnixTime(this);\n }\n\n /**\n * Checks whether this date occurs after the other date.\n */\n isAfter(other: dateFns.DateArg<Date>) {\n return dateFns.isAfter(this, other);\n }\n\n /**\n * Checks whether this date occurs before the other date.\n */\n isBefore(other: dateFns.DateArg<Date>) {\n return dateFns.isBefore(this, other);\n }\n\n /**\n * Checks whether this date has the same timestamp as the other date.\n */\n isEqual(other: dateFns.DateArg<Date>) {\n return dateFns.isEqual(this, other);\n }\n\n /**\n * Checks whether this date is after the current time.\n */\n isFuture() {\n return dateFns.isFuture(this);\n }\n\n /**\n * Checks whether this date falls on the same calendar day as the other date.\n */\n isSameDay(other: dateFns.DateArg<Date>) {\n return dateFns.isSameDay(this, other);\n }\n\n /**\n * Checks whether this date falls in the same calendar minute as the other date.\n */\n isSameMinute(other: dateFns.DateArg<Date>) {\n return dateFns.isSameMinute(this, other);\n }\n\n /**\n * Checks whether this date falls on today.\n */\n isToday() {\n return dateFns.isToday(this);\n }\n\n /**\n * Checks whether this date falls on tomorrow.\n */\n isTomorrow() {\n return dateFns.isTomorrow(this);\n }\n\n /**\n * Checks whether this date has a valid timestamp.\n */\n isValid() {\n return dateFns.isValid(this);\n }\n\n /**\n * Moves this date to the start of its day in place.\n *\n * @returns This instance for chaining.\n */\n startOfDay() {\n this.setTime(dateFns.startOfDay(this).getTime());\n return this;\n }\n\n /**\n * Moves this date to the start of its minute in place.\n *\n * @returns This instance for chaining.\n */\n startOfMinute() {\n this.setTime(dateFns.startOfMinute(this).getTime());\n return this;\n }\n\n /**\n * Moves this date to the start of its month in place.\n *\n * @returns This instance for chaining.\n */\n startOfMonth() {\n this.setTime(dateFns.startOfMonth(this).getTime());\n return this;\n }\n\n /**\n * Moves this date to the start of its week in place.\n *\n * @param options - date-fns week options; defaults are unchanged.\n *\n * @returns This instance for chaining.\n */\n startOfWeek(options?: dateFns.StartOfWeekOptions) {\n this.setTime(dateFns.startOfWeek(this, options).getTime());\n return this;\n }\n\n /**\n * Subtracts the specified number of days in place using date-fns.\n *\n * @param amount - Number of days.\n *\n * @returns This instance for chaining.\n */\n subDays(amount: number) {\n this.setTime(dateFns.subDays(this, amount).getTime());\n return this;\n }\n\n /**\n * Subtracts the specified number of hours in place using date-fns.\n *\n * @param amount - Number of hours.\n *\n * @returns This instance for chaining.\n */\n subHours(amount: number) {\n this.setTime(dateFns.subHours(this, amount).getTime());\n return this;\n }\n\n /**\n * Subtracts the specified number of milliseconds in place using date-fns.\n *\n * @param amount - Number of milliseconds.\n *\n * @returns This instance for chaining.\n */\n subMilliseconds(amount: number) {\n this.setTime(dateFns.subMilliseconds(this, amount).getTime());\n return this;\n }\n\n /**\n * Subtracts the specified number of minutes in place using date-fns.\n *\n * @param amount - Number of minutes.\n *\n * @returns This instance for chaining.\n */\n subMinutes(amount: number) {\n this.setTime(dateFns.subMinutes(this, amount).getTime());\n return this;\n }\n\n /**\n * Subtracts the specified number of months in place using date-fns.\n *\n * @param amount - Number of months.\n *\n * @returns This instance for chaining.\n */\n subMonths(amount: number) {\n this.setTime(dateFns.subMonths(this, amount).getTime());\n return this;\n }\n\n /**\n * Subtracts the specified number of seconds in place using date-fns.\n *\n * @param amount - Number of seconds.\n *\n * @returns This instance for chaining.\n */\n subSeconds(amount: number) {\n this.setTime(dateFns.subSeconds(this, amount).getTime());\n return this;\n }\n\n /**\n * Subtracts the specified number of weeks in place using date-fns.\n *\n * @param amount - Number of weeks.\n *\n * @returns This instance for chaining.\n */\n subWeeks(amount: number) {\n this.setTime(dateFns.subWeeks(this, amount).getTime());\n return this;\n }\n\n /**\n * Subtracts the specified number of years in place using date-fns.\n *\n * @param amount - Number of years.\n *\n * @returns This instance for chaining.\n */\n subYears(amount: number) {\n this.setTime(dateFns.subYears(this, amount).getTime());\n return this;\n }\n\n /**\n * Returns a new instance with days added, leaving this date unchanged.\n */\n toAddDays(amount: number) {\n return this.clone().addDays(amount);\n }\n\n /**\n * Returns a new instance with hours added, leaving this date unchanged.\n */\n toAddHours(amount: number) {\n return this.clone().addHours(amount);\n }\n\n /**\n * Returns a new instance with milliseconds added, leaving this date unchanged.\n */\n toAddMilliseconds(amount: number) {\n return this.clone().addMilliseconds(amount);\n }\n\n /**\n * Returns a new instance with minutes added, leaving this date unchanged.\n */\n toAddMinutes(amount: number) {\n return this.clone().addMinutes(amount);\n }\n\n /**\n * Returns a new instance with months added, leaving this date unchanged.\n */\n toAddMonths(amount: number) {\n return this.clone().addMonths(amount);\n }\n\n /**\n * Returns a new instance with seconds added, leaving this date unchanged.\n */\n toAddSeconds(amount: number) {\n return this.clone().addSeconds(amount);\n }\n\n /**\n * Returns a new instance with weeks added, leaving this date unchanged.\n */\n toAddWeeks(amount: number) {\n return this.clone().addWeeks(amount);\n }\n\n /**\n * Returns a new instance with years added, leaving this date unchanged.\n */\n toAddYears(amount: number) {\n return this.clone().addYears(amount);\n }\n\n /**\n * Returns a new plain native Date; mutations are not shared with this instance.\n */\n toDate() {\n return new Date(this.getTime());\n }\n\n /**\n * Returns a new instance at the end of this day, leaving this date unchanged.\n */\n toEndOfDay() {\n return this.clone().endOfDay();\n }\n\n /**\n * Returns a new instance at the end of this minute, leaving this date unchanged.\n */\n toEndOfMinute() {\n return this.clone().endOfMinute();\n }\n\n /**\n * Returns a new instance at the end of this month, leaving this date unchanged.\n */\n toEndOfMonth() {\n return this.clone().endOfMonth();\n }\n\n /**\n * Returns a new instance at the end of this week, leaving this date unchanged.\n */\n toEndOfWeek(options?: dateFns.EndOfWeekOptions) {\n return this.clone().endOfWeek(options);\n }\n\n /**\n * Returns a new instance at the start of this day, leaving this date unchanged.\n */\n toStartOfDay() {\n return this.clone().startOfDay();\n }\n\n /**\n * Returns a new instance at the start of this minute, leaving this date unchanged.\n */\n toStartOfMinute() {\n return this.clone().startOfMinute();\n }\n\n /**\n * Returns a new instance at the start of this month, leaving this date unchanged.\n */\n toStartOfMonth() {\n return this.clone().startOfMonth();\n }\n\n /**\n * Returns a new instance at the start of this week, leaving this date unchanged.\n */\n toStartOfWeek(options?: dateFns.StartOfWeekOptions) {\n return this.clone().startOfWeek(options);\n }\n\n /**\n * Returns a new instance with days subtracted, leaving this date unchanged.\n */\n toSubDays(amount: number) {\n return this.clone().subDays(amount);\n }\n\n /**\n * Returns a new instance with hours subtracted, leaving this date unchanged.\n */\n toSubHours(amount: number) {\n return this.clone().subHours(amount);\n }\n\n /**\n * Returns a new instance with milliseconds subtracted, leaving this date unchanged.\n */\n toSubMilliseconds(amount: number) {\n return this.clone().subMilliseconds(amount);\n }\n\n /**\n * Returns a new instance with minutes subtracted, leaving this date unchanged.\n */\n toSubMinutes(amount: number) {\n return this.clone().subMinutes(amount);\n }\n\n /**\n * Returns a new instance with months subtracted, leaving this date unchanged.\n */\n toSubMonths(amount: number) {\n return this.clone().subMonths(amount);\n }\n\n /**\n * Returns a new instance with seconds subtracted, leaving this date unchanged.\n */\n toSubSeconds(amount: number) {\n return this.clone().subSeconds(amount);\n }\n\n /**\n * Returns a new instance with weeks subtracted, leaving this date unchanged.\n */\n toSubWeeks(amount: number) {\n return this.clone().subWeeks(amount);\n }\n\n /**\n * Returns a new instance with years subtracted, leaving this date unchanged.\n */\n toSubYears(amount: number) {\n return this.clone().subYears(amount);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,IAAa,eAAb,MAAa,qBAAqB,KAAK;;;;CAMnC,OAAO,aAAa;EAChB,OAAO,IAAI,aAAa,QAAQ,WAAW,CAAC;CAChD;;;;CAKA,OAAO,gBAAgB;EACnB,OAAO,IAAI,aAAa,QAAQ,cAAc,CAAC;CACnD;;;;CAKA,OAAO,iBAAiB;EACpB,OAAO,IAAI,aAAa,QAAQ,eAAe,CAAC;CACpD;;;;;;;;;;;CAYA,OAAO,WACH,OACA,SACA,eACA,SACF;EACE,OAAO,IAAI,aAAa,QAAQ,MAAM,OAAO,SAAS,eAAe,OAAO,CAAC;CACjF;;;;;;;;;CAUA,OAAO,QAAQ,OAAe,SAAmC;EAC7D,OAAO,IAAI,aAAa,QAAQ,SAAS,OAAO,OAAO,CAAC;CAC5D;;;;;;CAOA,OAAO,gBAAgB,SAAiB;EACpC,OAAO,IAAI,aAAa,UAAU,GAAI;CAC1C;;;;;;;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GAAG,cAAc,QAAQ,GAAG,cAAc,GAAG;;;;;;;;;EAwBzD,YAAY,MAAM,2BAA2B,IAAI,YAAS;;;;;;;;;EAY1D,UAAM;;;;;;;;;EAYN,aAAa,MAAM,2BAA2B,IAAI,aAAU"}
|
package/dist/classes/path.js
CHANGED
|
@@ -302,8 +302,13 @@ var Path = class Path {
|
|
|
302
302
|
rmdir(...args) {
|
|
303
303
|
return fsp.rmdir(this.#value, ...args);
|
|
304
304
|
}
|
|
305
|
-
stat(
|
|
306
|
-
|
|
305
|
+
async stat(opts) {
|
|
306
|
+
try {
|
|
307
|
+
return await fsp.stat(this.#value, opts);
|
|
308
|
+
} catch (error) {
|
|
309
|
+
if (opts?.throwIfNoEntry === false && error instanceof Error && "code" in error && error.code === "ENOENT") return void 0;
|
|
310
|
+
throw error;
|
|
311
|
+
}
|
|
307
312
|
}
|
|
308
313
|
/**
|
|
309
314
|
* Truncates or extends the file at the stored path.
|
package/dist/classes/path.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.js","names":[],"sources":["../../src/classes/path.ts"],"sourcesContent":["import type { Buffer } from 'node:buffer';\nimport type { Abortable } from 'node:events';\nimport type * as fs from 'node:fs';\nimport * as fsp from 'node:fs/promises';\nimport * as nodePath from 'node:path';\n\ntype DropFirstParameters<T extends (...args: any) => any> = Parameters<T> extends [any, ...infer R] ? R : never;\n\n/**\n * Values accepted by the `Path` constructor and path-composition methods.\n */\nexport type PathLike = fs.PathLike | Path;\n\n/**\n * An immutable file system path with Node.js path and file operations.\n *\n * @remarks\n * Path-composition methods return new instances and leave this instance unchanged.\n * File operations act on the stored path and forward Node.js defaults and promise rejections.\n * They do not update the stored path, including after a successful rename.\n * The constructor joins stringified inputs using the platform-specific Node.js path rules.\n */\nexport class Path {\n // Private instance properties\n readonly #value: string;\n\n // Constructor\n\n /**\n * Creates a normalized path value by joining the provided path segments.\n *\n * @param paths - Path segments accepted by Node.js `path.join` or another `Path` instance.\n */\n constructor(...paths: PathLike[]) {\n this.#value = nodePath.join(...this.#toStrings(paths));\n }\n\n // Private instance methods\n #newInstance(...paths: PathLike[]) {\n return new Path(...paths);\n }\n\n #toStrings(paths: PathLike[]) {\n return paths.map((path) => path.toString());\n }\n\n // Public instance accessors\n\n /**\n * The parent directory as a new `Path`; this instance is unchanged.\n *\n * @see {@link Path.dirname}\n */\n get parent() {\n return this.dirname();\n }\n\n /**\n * The normalized path string stored by this instance.\n */\n get value() {\n return this.#value;\n }\n\n // Public static methods\n\n /**\n * Creates a new path from a Node.js path object.\n *\n * @param pathObject - The path components to format.\n *\n * @returns A new normalized `Path`.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.format}\n */\n static format(pathObject: nodePath.FormatInputPathObject) {\n return new Path(nodePath.format(pathObject));\n }\n\n /**\n * Resolves joined path segments to an absolute path.\n *\n * @remarks\n * Inputs are joined before resolution; unlike Node.js `path.resolve`,\n * later absolute segments do not reset the path.\n *\n * @param paths - The stringified path segments to join.\n *\n * @returns A new absolute `Path`.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.resolve}\n */\n static resolve(...paths: PathLike[]) {\n return new this(...paths).resolve();\n }\n\n // Public instance methods\n [Symbol.for('nodejs.util.inspect.custom')]() {\n return this.#value;\n }\n\n [Symbol.toPrimitive](hint: string) {\n if (hint === 'number') throw new TypeError('Cannot convert a Path to a number');\n return this.#value;\n }\n\n /**\n * Returns the final component of this path.\n *\n * @param suffix - An optional exact suffix to remove.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.basename}\n */\n basename(suffix?: string) {\n return nodePath.basename(this.#value, suffix);\n }\n\n /**\n * Returns the parent directory of this path.\n *\n * @returns A new `Path`; this instance is unchanged.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.dirname}\n */\n dirname() {\n return this.#newInstance(nodePath.dirname(this.#value));\n }\n\n /**\n * Returns the extension of the final path component.\n *\n * @returns The extension including its leading dot, or an empty string when absent.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.extname}\n */\n extname() {\n return nodePath.extname(this.#value);\n }\n\n /**\n * Checks whether this path is absolute on the current platform.\n *\n * @returns Whether this path is absolute.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.isAbsolute}\n */\n isAbsolute() {\n return nodePath.isAbsolute(this.#value);\n }\n\n /**\n * Normalizes separators and relative segments in this path.\n *\n * @returns A new `Path`; this instance is unchanged.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.normalize}\n */\n normalize() {\n return this.#newInstance(nodePath.normalize(this.#value));\n }\n\n /**\n * Joins additional segments onto this path.\n *\n * @param paths - The stringified path segments to append.\n *\n * @returns A new normalized `Path`; this instance is unchanged.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.join}\n */\n join(...paths: PathLike[]) {\n return this.#newInstance(this.#value, ...this.#toStrings(paths));\n }\n\n /**\n * Parses this path into its root, directory, basename, extension, and name.\n *\n * @returns A new object containing the path components.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.parse}\n */\n parse() {\n return nodePath.parse(this.#value);\n }\n\n /**\n * Computes a relative path from this path to the destination.\n *\n * @param to - The destination path.\n *\n * @returns A new `Path`; this instance is unchanged.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.relative}\n */\n relative(to: PathLike) {\n return this.#newInstance(nodePath.relative(this.#value, to.toString()));\n }\n\n /**\n * Resolves this path to an absolute path using the current working directory.\n *\n * @remarks\n * Relative paths use the current working directory. This instance is unchanged.\n *\n * @returns A new absolute `Path`.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.resolve}\n */\n resolve() {\n return this.#newInstance(nodePath.resolve(this.#value));\n }\n\n toJSON() {\n return this.#value;\n }\n\n /**\n * Converts this path to the Windows namespace form when applicable.\n *\n * @returns The namespace-converted path string; this instance is unchanged.\n * On non-Windows platforms, the path text is unchanged.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.toNamespacedPath}\n */\n toNamespacedPath() {\n return nodePath.toNamespacedPath(this.#value);\n }\n\n /**\n * Returns the stored path as a string.\n */\n toString() {\n return this.#value;\n }\n\n /**\n * Checks access permissions for the stored path.\n *\n * @remarks\n * The promise resolves when the access check succeeds and rejects if access is denied or the path is missing.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.access}\n */\n access(...args: DropFirstParameters<typeof fsp.access>) {\n return fsp.access(this.#value, ...args);\n }\n\n /**\n * Appends data to the file at the stored path.\n *\n * @remarks\n * The promise resolves when appending completes; a missing file is created according to the supplied options.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.appendFile}\n */\n appendFile(...args: DropFirstParameters<typeof fsp.appendFile>) {\n return fsp.appendFile(this.#value, ...args);\n }\n\n /**\n * Changes the permissions of the stored path.\n *\n * @remarks\n * The promise resolves when the permissions are changed.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.chmod}\n */\n chmod(...args: DropFirstParameters<typeof fsp.chmod>) {\n return fsp.chmod(this.#value, ...args);\n }\n\n /**\n * Changes the owner and group of the stored path.\n *\n * @remarks\n * The promise resolves when the ownership is changed.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.chown}\n */\n chown(...args: DropFirstParameters<typeof fsp.chown>) {\n return fsp.chown(this.#value, ...args);\n }\n\n /**\n * Copies the file at the stored path to a destination.\n *\n * @remarks\n * The promise resolves when copying completes. The stored path remains the source path.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.copyFile}\n */\n copyFile(...args: DropFirstParameters<typeof fsp.copyFile>) {\n return fsp.copyFile(this.#value, ...args);\n }\n\n /**\n * Creates a directory at the stored path.\n *\n * @remarks\n * The promise resolves after creation. Recursive mode resolves to the first created directory path, or\n * `undefined` if no directory is created; nonrecursive mode resolves without a value.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.mkdir}\n */\n mkdir(options: fs.MakeDirectoryOptions & { recursive: true }): Promise<string | undefined>;\n mkdir(\n options?:\n | (fs.MakeDirectoryOptions & { recursive?: false })\n | fs.Mode\n | null,\n ): Promise<void>;\n mkdir(options?: fs.MakeDirectoryOptions | fs.Mode | null): Promise<string | undefined>;\n mkdir(...args: any): any {\n return fsp.mkdir(this.#value, ...args);\n }\n\n /**\n * Opens the file at the stored path.\n *\n * @remarks\n * The promise resolves to a new file handle. The caller must close the handle when it is no longer needed.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.open}\n */\n open(...args: DropFirstParameters<typeof fsp.open>) {\n return fsp.open(this.#value, ...args);\n }\n\n /**\n * Reads the entries of the directory at the stored path.\n *\n * @remarks\n * The promise resolves to names, buffers, or directory entries according to the options.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.readdir}\n */\n readdir(\n options?:\n | BufferEncoding\n | (fs.ObjectEncodingOptions & {\n recursive?: boolean;\n withFileTypes?: false;\n })\n | null,\n ): Promise<string[]>;\n readdir(\n options:\n | 'buffer'\n | {\n encoding: 'buffer';\n recursive?: boolean;\n withFileTypes?: false;\n },\n ): Promise<Buffer[]>;\n readdir(\n options?:\n | BufferEncoding\n | (fs.ObjectEncodingOptions & {\n recursive?: boolean;\n withFileTypes?: false;\n })\n | null,\n ): Promise<Buffer[] | string[]>;\n readdir(\n options: fs.ObjectEncodingOptions & {\n recursive?: boolean;\n withFileTypes: true;\n },\n ): Promise<fs.Dirent[]>;\n readdir(\n options: {\n encoding: 'buffer';\n recursive?: boolean;\n withFileTypes: true;\n },\n ): Promise<fs.Dirent<Buffer>[]>;\n readdir(...args: any): any {\n return fsp.readdir(this.#value, ...args);\n }\n\n /**\n * Reads the entire file at the stored path.\n *\n * @remarks\n * The promise resolves to a string when a text encoding is supplied, or a `Buffer` otherwise.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.readFile}\n */\n readFile(\n options?:\n | (Abortable & {\n encoding?: null;\n flag?: fs.OpenMode;\n })\n | null,\n ): Promise<Buffer>;\n readFile(\n options:\n | (Abortable & {\n encoding: BufferEncoding;\n flag?: fs.OpenMode;\n })\n | BufferEncoding,\n ): Promise<string>;\n readFile(\n options?:\n | (\n & Abortable\n & fs.ObjectEncodingOptions\n & { flag?: fs.OpenMode }\n )\n | BufferEncoding\n | null,\n ): Promise<Buffer | string>;\n readFile(...args: any): any {\n return fsp.readFile(this.#value, ...args);\n }\n\n /**\n * Renames or moves the file or directory at the stored path.\n *\n * @remarks\n * The promise resolves when the rename completes. This instance retains its original stored path.\n *\n * @param newPath - The destination path; this instance retains its original value.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.rename}\n */\n rename(newPath: PathLike) {\n return fsp.rename(this.#value, newPath.toString());\n }\n\n /**\n * Removes the file or directory at the stored path.\n *\n * @remarks\n * The promise resolves after removal according to the supplied options.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.rm}\n */\n rm(...args: DropFirstParameters<typeof fsp.rm>) {\n return fsp.rm(this.#value, ...args);\n }\n\n /**\n * Removes the directory at the stored path.\n *\n * @remarks\n * The promise resolves after directory removal.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.rmdir}\n */\n rmdir(...args: DropFirstParameters<typeof fsp.rmdir>) {\n return fsp.rmdir(this.#value, ...args);\n }\n\n /**\n * Reads file system metadata for the stored path.\n *\n * @remarks\n * The promise resolves to `Stats`, or `BigIntStats` when `bigint` is enabled.\n * If `throwIfNoEntry` is `false`, a missing path resolves to `undefined` instead of rejecting.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.stat}\n */\n stat(\n opts?: fs.StatOptions & {\n bigint?: false;\n throwIfNoEntry?: true;\n },\n ): Promise<fs.Stats>;\n stat(\n opts: fs.StatOptions & {\n bigint: true;\n throwIfNoEntry?: true;\n },\n ): Promise<fs.BigIntStats>;\n stat(\n opts: fs.StatOptions & {\n bigint?: false;\n throwIfNoEntry: false;\n },\n ): Promise<fs.Stats | undefined>;\n stat(\n opts: fs.StatOptions & {\n bigint: true;\n throwIfNoEntry: false;\n },\n ): Promise<fs.BigIntStats | undefined>;\n stat(opts: fs.StatOptions & { throwIfNoEntry?: true }): Promise<fs.BigIntStats | fs.Stats>;\n stat(opts?: fs.StatOptions): Promise<fs.BigIntStats | fs.Stats | undefined>;\n stat(...args: any): any {\n return fsp.stat(this.#value, ...args);\n }\n\n /**\n * Truncates or extends the file at the stored path.\n *\n * @remarks\n * The promise resolves when the file reaches the requested length in bytes; the default length is `0`.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.truncate}\n */\n truncate(...args: DropFirstParameters<typeof fsp.truncate>) {\n return fsp.truncate(this.#value, ...args);\n }\n\n /**\n * Deletes the file or symbolic link at the stored path.\n *\n * @remarks\n * The promise resolves after deletion; directories are not removed.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.unlink}\n */\n unlink() {\n return fsp.unlink(this.#value);\n }\n\n /**\n * Writes data to the file at the stored path.\n *\n * @remarks\n * The promise resolves when writing completes; the default flag replaces existing file contents.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.writeFile}\n */\n writeFile(...args: DropFirstParameters<typeof fsp.writeFile>) {\n return fsp.writeFile(this.#value, ...args);\n }\n}\n"],"mappings":";;;;;;;;;;;;AAsBA,IAAa,OAAb,MAAa,KAAK;CAEd;;;;;;CASA,YAAY,GAAG,OAAmB;EAC9B,KAAK,SAAS,SAAS,KAAK,GAAG,KAAK,WAAW,KAAK,CAAC;CACzD;CAGA,aAAa,GAAG,OAAmB;EAC/B,OAAO,IAAI,KAAK,GAAG,KAAK;CAC5B;CAEA,WAAW,OAAmB;EAC1B,OAAO,MAAM,KAAK,SAAS,KAAK,SAAS,CAAC;CAC9C;;;;;;CASA,IAAI,SAAS;EACT,OAAO,KAAK,QAAQ;CACxB;;;;CAKA,IAAI,QAAQ;EACR,OAAO,KAAK;CAChB;;;;;;;;;;CAaA,OAAO,OAAO,YAA4C;EACtD,OAAO,IAAI,KAAK,SAAS,OAAO,UA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CACjC;;;;;;;;;CAUA,UAAU,GAAG,MAAiD;EAC1D,OAAO,IAAI,UAAU,KAAK,QAAQ,GAAG,IAAI;CAC7C;AACJ"}
|
|
1
|
+
{"version":3,"file":"path.js","names":[],"sources":["../../src/classes/path.ts"],"sourcesContent":["import type { Buffer } from 'node:buffer';\nimport type { Abortable } from 'node:events';\nimport type * as fs from 'node:fs';\nimport * as fsp from 'node:fs/promises';\nimport * as nodePath from 'node:path';\n\ntype DropFirstParameters<T extends (...args: any) => any> = Parameters<T> extends [any, ...infer R] ? R : never;\n\n/**\n * Values accepted by the `Path` constructor and path-composition methods.\n */\nexport type PathLike = fs.PathLike | Path;\n\n/**\n * An immutable file system path with Node.js path and file operations.\n *\n * @remarks\n * Path-composition methods return new instances and leave this instance unchanged.\n * File operations act on the stored path and forward Node.js defaults and promise rejections.\n * They do not update the stored path, including after a successful rename.\n * The constructor joins stringified inputs using the platform-specific Node.js path rules.\n */\nexport class Path {\n // Private instance properties\n readonly #value: string;\n\n // Constructor\n\n /**\n * Creates a normalized path value by joining the provided path segments.\n *\n * @param paths - Path segments accepted by Node.js `path.join` or another `Path` instance.\n */\n constructor(...paths: PathLike[]) {\n this.#value = nodePath.join(...this.#toStrings(paths));\n }\n\n // Private instance methods\n #newInstance(...paths: PathLike[]) {\n return new Path(...paths);\n }\n\n #toStrings(paths: PathLike[]) {\n return paths.map((path) => path.toString());\n }\n\n // Public instance accessors\n\n /**\n * The parent directory as a new `Path`; this instance is unchanged.\n *\n * @see {@link Path.dirname}\n */\n get parent() {\n return this.dirname();\n }\n\n /**\n * The normalized path string stored by this instance.\n */\n get value() {\n return this.#value;\n }\n\n // Public static methods\n\n /**\n * Creates a new path from a Node.js path object.\n *\n * @param pathObject - The path components to format.\n *\n * @returns A new normalized `Path`.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.format}\n */\n static format(pathObject: nodePath.FormatInputPathObject) {\n return new Path(nodePath.format(pathObject));\n }\n\n /**\n * Resolves joined path segments to an absolute path.\n *\n * @remarks\n * Inputs are joined before resolution; unlike Node.js `path.resolve`,\n * later absolute segments do not reset the path.\n *\n * @param paths - The stringified path segments to join.\n *\n * @returns A new absolute `Path`.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.resolve}\n */\n static resolve(...paths: PathLike[]) {\n return new this(...paths).resolve();\n }\n\n // Public instance methods\n [Symbol.for('nodejs.util.inspect.custom')]() {\n return this.#value;\n }\n\n [Symbol.toPrimitive](hint: string) {\n if (hint === 'number') throw new TypeError('Cannot convert a Path to a number');\n return this.#value;\n }\n\n /**\n * Returns the final component of this path.\n *\n * @param suffix - An optional exact suffix to remove.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.basename}\n */\n basename(suffix?: string) {\n return nodePath.basename(this.#value, suffix);\n }\n\n /**\n * Returns the parent directory of this path.\n *\n * @returns A new `Path`; this instance is unchanged.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.dirname}\n */\n dirname() {\n return this.#newInstance(nodePath.dirname(this.#value));\n }\n\n /**\n * Returns the extension of the final path component.\n *\n * @returns The extension including its leading dot, or an empty string when absent.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.extname}\n */\n extname() {\n return nodePath.extname(this.#value);\n }\n\n /**\n * Checks whether this path is absolute on the current platform.\n *\n * @returns Whether this path is absolute.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.isAbsolute}\n */\n isAbsolute() {\n return nodePath.isAbsolute(this.#value);\n }\n\n /**\n * Normalizes separators and relative segments in this path.\n *\n * @returns A new `Path`; this instance is unchanged.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.normalize}\n */\n normalize() {\n return this.#newInstance(nodePath.normalize(this.#value));\n }\n\n /**\n * Joins additional segments onto this path.\n *\n * @param paths - The stringified path segments to append.\n *\n * @returns A new normalized `Path`; this instance is unchanged.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.join}\n */\n join(...paths: PathLike[]) {\n return this.#newInstance(this.#value, ...this.#toStrings(paths));\n }\n\n /**\n * Parses this path into its root, directory, basename, extension, and name.\n *\n * @returns A new object containing the path components.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.parse}\n */\n parse() {\n return nodePath.parse(this.#value);\n }\n\n /**\n * Computes a relative path from this path to the destination.\n *\n * @param to - The destination path.\n *\n * @returns A new `Path`; this instance is unchanged.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.relative}\n */\n relative(to: PathLike) {\n return this.#newInstance(nodePath.relative(this.#value, to.toString()));\n }\n\n /**\n * Resolves this path to an absolute path using the current working directory.\n *\n * @remarks\n * Relative paths use the current working directory. This instance is unchanged.\n *\n * @returns A new absolute `Path`.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.resolve}\n */\n resolve() {\n return this.#newInstance(nodePath.resolve(this.#value));\n }\n\n toJSON() {\n return this.#value;\n }\n\n /**\n * Converts this path to the Windows namespace form when applicable.\n *\n * @returns The namespace-converted path string; this instance is unchanged.\n * On non-Windows platforms, the path text is unchanged.\n *\n * @see {@link https://nodejs.org/api/path.html | Node.js path.toNamespacedPath}\n */\n toNamespacedPath() {\n return nodePath.toNamespacedPath(this.#value);\n }\n\n /**\n * Returns the stored path as a string.\n */\n toString() {\n return this.#value;\n }\n\n /**\n * Checks access permissions for the stored path.\n *\n * @remarks\n * The promise resolves when the access check succeeds and rejects if access is denied or the path is missing.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.access}\n */\n access(...args: DropFirstParameters<typeof fsp.access>) {\n return fsp.access(this.#value, ...args);\n }\n\n /**\n * Appends data to the file at the stored path.\n *\n * @remarks\n * The promise resolves when appending completes; a missing file is created according to the supplied options.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.appendFile}\n */\n appendFile(...args: DropFirstParameters<typeof fsp.appendFile>) {\n return fsp.appendFile(this.#value, ...args);\n }\n\n /**\n * Changes the permissions of the stored path.\n *\n * @remarks\n * The promise resolves when the permissions are changed.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.chmod}\n */\n chmod(...args: DropFirstParameters<typeof fsp.chmod>) {\n return fsp.chmod(this.#value, ...args);\n }\n\n /**\n * Changes the owner and group of the stored path.\n *\n * @remarks\n * The promise resolves when the ownership is changed.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.chown}\n */\n chown(...args: DropFirstParameters<typeof fsp.chown>) {\n return fsp.chown(this.#value, ...args);\n }\n\n /**\n * Copies the file at the stored path to a destination.\n *\n * @remarks\n * The promise resolves when copying completes. The stored path remains the source path.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.copyFile}\n */\n copyFile(...args: DropFirstParameters<typeof fsp.copyFile>) {\n return fsp.copyFile(this.#value, ...args);\n }\n\n /**\n * Creates a directory at the stored path.\n *\n * @remarks\n * The promise resolves after creation. Recursive mode resolves to the first created directory path, or\n * `undefined` if no directory is created; nonrecursive mode resolves without a value.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.mkdir}\n */\n mkdir(options: fs.MakeDirectoryOptions & { recursive: true }): Promise<string | undefined>;\n mkdir(\n options?:\n | (fs.MakeDirectoryOptions & { recursive?: false })\n | fs.Mode\n | null,\n ): Promise<void>;\n mkdir(options?: fs.MakeDirectoryOptions | fs.Mode | null): Promise<string | undefined>;\n mkdir(...args: any): any {\n return fsp.mkdir(this.#value, ...args);\n }\n\n /**\n * Opens the file at the stored path.\n *\n * @remarks\n * The promise resolves to a new file handle. The caller must close the handle when it is no longer needed.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.open}\n */\n open(...args: DropFirstParameters<typeof fsp.open>) {\n return fsp.open(this.#value, ...args);\n }\n\n /**\n * Reads the entries of the directory at the stored path.\n *\n * @remarks\n * The promise resolves to names, buffers, or directory entries according to the options.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.readdir}\n */\n readdir(\n options?:\n | BufferEncoding\n | (fs.ObjectEncodingOptions & {\n recursive?: boolean;\n withFileTypes?: false;\n })\n | null,\n ): Promise<string[]>;\n readdir(\n options:\n | 'buffer'\n | {\n encoding: 'buffer';\n recursive?: boolean;\n withFileTypes?: false;\n },\n ): Promise<Buffer[]>;\n readdir(\n options?:\n | BufferEncoding\n | (fs.ObjectEncodingOptions & {\n recursive?: boolean;\n withFileTypes?: false;\n })\n | null,\n ): Promise<Buffer[] | string[]>;\n readdir(\n options: fs.ObjectEncodingOptions & {\n recursive?: boolean;\n withFileTypes: true;\n },\n ): Promise<fs.Dirent[]>;\n readdir(\n options: {\n encoding: 'buffer';\n recursive?: boolean;\n withFileTypes: true;\n },\n ): Promise<fs.Dirent<Buffer>[]>;\n readdir(...args: any): any {\n return fsp.readdir(this.#value, ...args);\n }\n\n /**\n * Reads the entire file at the stored path.\n *\n * @remarks\n * The promise resolves to a string when a text encoding is supplied, or a `Buffer` otherwise.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.readFile}\n */\n readFile(\n options?:\n | (Abortable & {\n encoding?: null;\n flag?: fs.OpenMode;\n })\n | null,\n ): Promise<Buffer>;\n readFile(\n options:\n | (Abortable & {\n encoding: BufferEncoding;\n flag?: fs.OpenMode;\n })\n | BufferEncoding,\n ): Promise<string>;\n readFile(\n options?:\n | (\n & Abortable\n & fs.ObjectEncodingOptions\n & { flag?: fs.OpenMode }\n )\n | BufferEncoding\n | null,\n ): Promise<Buffer | string>;\n readFile(...args: any): any {\n return fsp.readFile(this.#value, ...args);\n }\n\n /**\n * Renames or moves the file or directory at the stored path.\n *\n * @remarks\n * The promise resolves when the rename completes. This instance retains its original stored path.\n *\n * @param newPath - The destination path; this instance retains its original value.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.rename}\n */\n rename(newPath: PathLike) {\n return fsp.rename(this.#value, newPath.toString());\n }\n\n /**\n * Removes the file or directory at the stored path.\n *\n * @remarks\n * The promise resolves after removal according to the supplied options.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.rm}\n */\n rm(...args: DropFirstParameters<typeof fsp.rm>) {\n return fsp.rm(this.#value, ...args);\n }\n\n /**\n * Removes the directory at the stored path.\n *\n * @remarks\n * The promise resolves after directory removal.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.rmdir}\n */\n rmdir(...args: DropFirstParameters<typeof fsp.rmdir>) {\n return fsp.rmdir(this.#value, ...args);\n }\n\n /**\n * Reads file system metadata for the stored path.\n *\n * @remarks\n * The promise resolves to `Stats`, or `BigIntStats` when `bigint` is enabled.\n * If `throwIfNoEntry` is `false`, a missing path resolves to `undefined` instead of rejecting.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.stat}\n */\n stat(\n opts?: fs.StatOptions & {\n bigint?: false;\n throwIfNoEntry?: true;\n },\n ): Promise<fs.Stats>;\n stat(\n opts: fs.StatOptions & {\n bigint: true;\n throwIfNoEntry?: true;\n },\n ): Promise<fs.BigIntStats>;\n stat(\n opts: fs.StatOptions & {\n bigint?: false;\n throwIfNoEntry: false;\n },\n ): Promise<fs.Stats | undefined>;\n stat(\n opts: fs.StatOptions & {\n bigint: true;\n throwIfNoEntry: false;\n },\n ): Promise<fs.BigIntStats | undefined>;\n stat(opts: fs.StatOptions & { throwIfNoEntry?: true }): Promise<fs.BigIntStats | fs.Stats>;\n stat(opts?: fs.StatOptions): Promise<fs.BigIntStats | fs.Stats | undefined>;\n async stat(opts?: fs.StatOptions): Promise<fs.BigIntStats | fs.Stats | undefined> {\n try {\n return await fsp.stat(this.#value, opts);\n } catch (error) {\n if (\n opts?.throwIfNoEntry === false\n && error instanceof Error\n && 'code' in error\n && error.code === 'ENOENT'\n ) return undefined;\n\n throw error;\n }\n }\n\n /**\n * Truncates or extends the file at the stored path.\n *\n * @remarks\n * The promise resolves when the file reaches the requested length in bytes; the default length is `0`.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.truncate}\n */\n truncate(...args: DropFirstParameters<typeof fsp.truncate>) {\n return fsp.truncate(this.#value, ...args);\n }\n\n /**\n * Deletes the file or symbolic link at the stored path.\n *\n * @remarks\n * The promise resolves after deletion; directories are not removed.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.unlink}\n */\n unlink() {\n return fsp.unlink(this.#value);\n }\n\n /**\n * Writes data to the file at the stored path.\n *\n * @remarks\n * The promise resolves when writing completes; the default flag replaces existing file contents.\n *\n * @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.writeFile}\n */\n writeFile(...args: DropFirstParameters<typeof fsp.writeFile>) {\n return fsp.writeFile(this.#value, ...args);\n }\n}\n"],"mappings":";;;;;;;;;;;;AAsBA,IAAa,OAAb,MAAa,KAAK;CAEd;;;;;;CASA,YAAY,GAAG,OAAmB;EAC9B,KAAK,SAAS,SAAS,KAAK,GAAG,KAAK,WAAW,KAAK,CAAC;CACzD;CAGA,aAAa,GAAG,OAAmB;EAC/B,OAAO,IAAI,KAAK,GAAG,KAAK;CAC5B;CAEA,WAAW,OAAmB;EAC1B,OAAO,MAAM,KAAK,SAAS,KAAK,SAAS,CAAC;CAC9C;;;;;;CASA,IAAI,SAAS;EACT,OAAO,KAAK,QAAQ;CACxB;;;;CAKA,IAAI,QAAQ;EACR,OAAO,KAAK;CAChB;;;;;;;;;;CAaA,OAAO,OAAO,YAA4C;EACtD,OAAO,IAAI,KAAK,SAAS,OAAO,UAAU,CAAC;CAC/C;;;;;;;;;;;;;;CAeA,OAAO,QAAQ,GAAG,OAAmB;EACjC,OAAO,IAAI,KAAK,GAAG,KAAK,CAAC,CAAC,QAAQ;CACtC;CAGA,CAAC,OAAO,IAAI,4BAA4B,KAAK;EACzC,OAAO,KAAK;CAChB;CAEA,CAAC,OAAO,aAAa,MAAc;EAC/B,IAAI,SAAS,UAAU,MAAM,IAAI,UAAU,mCAAmC;EAC9E,OAAO,KAAK;CAChB;;;;;;;;CASA,SAAS,QAAiB;EACtB,OAAO,SAAS,SAAS,KAAK,QAAQ,MAAM;CAChD;;;;;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|
3
|
+
/**
|
|
4
|
+
* Detects a lowercase MIME type from binary content rather than its name or declared type.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Requires the optional `file-type` peer dependency. Only formats supported by its binary detection
|
|
8
|
+
* are recognized; this is not a general text-file detector or a guarantee that a file is safe.
|
|
9
|
+
* Blob and File inputs are read through the detector's tokenizer instead of being fully buffered up front.
|
|
10
|
+
* The amount of content inspected depends on its format; this does not impose a fixed read limit.
|
|
11
|
+
* Detection and input-reading errors propagate to the caller.
|
|
12
|
+
*
|
|
13
|
+
* @param input - The binary content to inspect.
|
|
14
|
+
*
|
|
15
|
+
* @returns The detected lowercase MIME type, or `undefined` when the content is not recognized.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { getFileMimeType } from '@kikiutils/shared/file';
|
|
21
|
+
*
|
|
22
|
+
* const mimeType = await getFileMimeType(file);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function getFileMimeType(input: BinaryInput): Promise<string | undefined>;
|
|
26
|
+
//#endregion
|
|
27
|
+
//# sourceMappingURL=file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.d.ts","names":[],"sources":["../src/file.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;wBA6BsB,gBAAgB,OAAO,cAAW"}
|
package/dist/file.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { fileTypeFromBlob, fileTypeFromBuffer } from "file-type";
|
|
2
|
+
//#region src/file.ts
|
|
3
|
+
/**
|
|
4
|
+
* Detects a lowercase MIME type from binary content rather than its name or declared type.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Requires the optional `file-type` peer dependency. Only formats supported by its binary detection
|
|
8
|
+
* are recognized; this is not a general text-file detector or a guarantee that a file is safe.
|
|
9
|
+
* Blob and File inputs are read through the detector's tokenizer instead of being fully buffered up front.
|
|
10
|
+
* The amount of content inspected depends on its format; this does not impose a fixed read limit.
|
|
11
|
+
* Detection and input-reading errors propagate to the caller.
|
|
12
|
+
*
|
|
13
|
+
* @param input - The binary content to inspect.
|
|
14
|
+
*
|
|
15
|
+
* @returns The detected lowercase MIME type, or `undefined` when the content is not recognized.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { getFileMimeType } from '@kikiutils/shared/file';
|
|
21
|
+
*
|
|
22
|
+
* const mimeType = await getFileMimeType(file);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
async function getFileMimeType(input) {
|
|
26
|
+
return (input instanceof ArrayBuffer || input instanceof Uint8Array ? await fileTypeFromBuffer(input) : await fileTypeFromBlob(input))?.mime.toLowerCase();
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { getFileMimeType };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=file.js.map
|
package/dist/file.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.js","names":[],"sources":["../src/file.ts"],"sourcesContent":["import {\n fileTypeFromBlob,\n fileTypeFromBuffer,\n} from 'file-type';\n\nimport type { BinaryInput } from './types';\n\n/**\n * Detects a lowercase MIME type from binary content rather than its name or declared type.\n *\n * @remarks\n * Requires the optional `file-type` peer dependency. Only formats supported by its binary detection\n * are recognized; this is not a general text-file detector or a guarantee that a file is safe.\n * Blob and File inputs are read through the detector's tokenizer instead of being fully buffered up front.\n * The amount of content inspected depends on its format; this does not impose a fixed read limit.\n * Detection and input-reading errors propagate to the caller.\n *\n * @param input - The binary content to inspect.\n *\n * @returns The detected lowercase MIME type, or `undefined` when the content is not recognized.\n *\n * @example\n *\n * ```ts\n * import { getFileMimeType } from '@kikiutils/shared/file';\n *\n * const mimeType = await getFileMimeType(file);\n * ```\n */\nexport async function getFileMimeType(input: BinaryInput) {\n // The tokenizer only uses size, slice, and arrayBuffer; Node/DOM Blob stream typings differ.\n const result = input instanceof ArrayBuffer || input instanceof Uint8Array\n ? await fileTypeFromBuffer(input)\n : await fileTypeFromBlob(input as Blob);\n\n return result?.mime.toLowerCase();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA6BA,eAAsB,gBAAgB,OAAoB;CAMtD,QAJe,iBAAiB,eAAe,iBAAiB,aAC1D,MAAM,mBAAmB,KAAK,IAC9B,MAAM,iBAAiB,KAAa,EAAA,EAE3B,KAAK,YAAY;AACpC"}
|
package/dist/math.d.ts
CHANGED
|
@@ -46,4 +46,5 @@ export interface ToPercentageStringOptions {
|
|
|
46
46
|
*/
|
|
47
47
|
export declare function toPercentageString(molecular: CalculableValue, denominator: CalculableValue, options?: ToPercentageStringOptions): string;
|
|
48
48
|
//#endregion
|
|
49
|
+
export {};
|
|
49
50
|
//# sourceMappingURL=math.d.ts.map
|
package/dist/pino.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { pino } from "pino";
|
|
1
2
|
//#region src/pino.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* A pino logger with environment-controlled verbosity.
|
|
@@ -18,7 +19,7 @@
|
|
|
18
19
|
*
|
|
19
20
|
* @see {@link https://getpino.io/#/docs/api?id=level-string | Pino log levels}
|
|
20
21
|
*/
|
|
21
|
-
export declare const pinoLogger:
|
|
22
|
-
export declare const logger:
|
|
22
|
+
export declare const pinoLogger: pino.Logger<never, boolean>;
|
|
23
|
+
export declare const logger: pino.Logger<never, boolean>;
|
|
23
24
|
//#endregion
|
|
24
25
|
//# sourceMappingURL=pino.d.ts.map
|
package/dist/pino.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pino.d.ts","names":[],"sources":["../src/pino.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"pino.d.ts","names":[],"sources":["../src/pino.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;qBA6Ba,YAAU,KAAA;qBACV,QAAM,KAAA"}
|
|
@@ -7,6 +7,7 @@ import { LRUCache } from "lru-cache";
|
|
|
7
7
|
* The key resolver is called synchronously once per operation, and its exceptions propagate.
|
|
8
8
|
* Reads return the cached value without copying it, or `null` for missing or nullish values.
|
|
9
9
|
* `getItemTtl` exposes the underlying remaining TTL in milliseconds; `setItem` returns the underlying cache.
|
|
10
|
+
* `setItemWithTtl` accepts its TTL in milliseconds before the value and key arguments and returns the cache.
|
|
10
11
|
* The facade does not dispose the supplied cache, and LRU defaults remain those of the supplied instance.
|
|
11
12
|
*
|
|
12
13
|
* @typeParam D - The stored value type used by reads and writes.
|
|
@@ -42,6 +43,7 @@ export declare function createLruKeyedStore<D = unknown>(lruInstance: LRUCache<a
|
|
|
42
43
|
*/
|
|
43
44
|
resolveKey: (...args: P) => string;
|
|
44
45
|
setItem: (value: D, ...args: P) => LRUCache<any, any, any>;
|
|
46
|
+
setItemWithTtl(ttlMilliseconds: number, value: D, ...args: P): LRUCache<any, any, any>;
|
|
45
47
|
}>;
|
|
46
48
|
//#endregion
|
|
47
49
|
//# sourceMappingURL=keyed-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyed-store.d.ts","names":[],"sources":["../../../src/storages/lru/keyed-store.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"keyed-store.d.ts","names":[],"sources":["../../../src/storages/lru/keyed-store.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA8BgB,oBAAoB,aAAa,aAAa,2BAClD,iBAAiB,WAAW,MAAM,iBAAY;;;;;;EAMjC,WAAA,MAAA,IAAC,YAAA;EAII,gBAAA,MAAA;EACH,aAAA,MAAA;EACG,gBAAA,MAAA;;;;EAIA,gBAAA,MAAA;EACL,UAAA,OAAA,MAAC,MAAW,MAAC;EACE,eAAA,yBAAM,OAAS,MAAC,MAAW,IAAC"}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* The key resolver is called synchronously once per operation, and its exceptions propagate.
|
|
7
7
|
* Reads return the cached value without copying it, or `null` for missing or nullish values.
|
|
8
8
|
* `getItemTtl` exposes the underlying remaining TTL in milliseconds; `setItem` returns the underlying cache.
|
|
9
|
+
* `setItemWithTtl` accepts its TTL in milliseconds before the value and key arguments and returns the cache.
|
|
9
10
|
* The facade does not dispose the supplied cache, and LRU defaults remain those of the supplied instance.
|
|
10
11
|
*
|
|
11
12
|
* @typeParam D - The stored value type used by reads and writes.
|
|
@@ -43,7 +44,10 @@ function createLruKeyedStore(lruInstance) {
|
|
|
43
44
|
* Resolves the full cache key from the given arguments.
|
|
44
45
|
*/
|
|
45
46
|
resolveKey: (...args) => keyFn(...args),
|
|
46
|
-
setItem: (value, ...args) => lruInstance.set(keyFn(...args), value)
|
|
47
|
+
setItem: (value, ...args) => lruInstance.set(keyFn(...args), value),
|
|
48
|
+
setItemWithTtl(ttlMilliseconds, value, ...args) {
|
|
49
|
+
return lruInstance.set(keyFn(...args), value, { ttl: ttlMilliseconds });
|
|
50
|
+
}
|
|
47
51
|
});
|
|
48
52
|
}
|
|
49
53
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyed-store.js","names":[],"sources":["../../../src/storages/lru/keyed-store.ts"],"sourcesContent":["import type { LRUCache } from 'lru-cache';\n\n/**\n * Creates a keyed cache factory sharing a caller-owned LRU cache.\n *\n * @remarks\n * The key resolver is called synchronously once per operation, and its exceptions propagate.\n * Reads return the cached value without copying it, or `null` for missing or nullish values.\n * `getItemTtl` exposes the underlying remaining TTL in milliseconds; `setItem` returns the underlying cache.\n * The facade does not dispose the supplied cache, and LRU defaults remain those of the supplied instance.\n *\n * @typeParam D - The stored value type used by reads and writes.\n *\n * @param lruInstance - The shared LRU cache instance.\n *\n * @returns A factory accepting a key resolver and returning a new frozen keyed facade sharing the cache.\n *\n * @example\n *\n * ```ts\n * import { createLruKeyedStore } from '@kikiutils/shared/storages/lru/keyed-store';\n * import { LRUCache } from 'lru-cache';\n *\n * const cache = new LRUCache<string, { name: string }>({ max: 100 });\n * const keyedStore = createLruKeyedStore<{ name: string }>(cache)((userId: string) => `user:${userId}`);\n * keyedStore.setItem({ name: 'Alice' }, 'user-123');\n * console.log(keyedStore.getItem('user-123')); // => { name: 'Alice' }\n * ```\n */\nexport function createLruKeyedStore<D = unknown>(lruInstance: LRUCache<any, any, any>) {\n return <P extends any[]>(keyFn: (...args: P) => string) => Object.freeze({\n /**\n * Returns the cached value and applies the underlying cache's read-recency policy.\n *\n * @returns The cached value without copying it, or `null` when absent or nullish.\n */\n getItem(...args: P) {\n const rawValue = lruInstance.get(keyFn(...args));\n return rawValue as D ?? null;\n },\n getItemTtl: (...args: P) => lruInstance.getRemainingTTL(keyFn(...args)),\n hasItem: (...args: P) => lruInstance.has(keyFn(...args)),\n removeItem: (...args: P) => lruInstance.delete(keyFn(...args)),\n /**\n * Resolves the full cache key from the given arguments.\n */\n resolveKey: (...args: P) => keyFn(...args),\n setItem: (value: D, ...args: P) => lruInstance.set(keyFn(...args), value),\n });\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"keyed-store.js","names":[],"sources":["../../../src/storages/lru/keyed-store.ts"],"sourcesContent":["import type { LRUCache } from 'lru-cache';\n\n/**\n * Creates a keyed cache factory sharing a caller-owned LRU cache.\n *\n * @remarks\n * The key resolver is called synchronously once per operation, and its exceptions propagate.\n * Reads return the cached value without copying it, or `null` for missing or nullish values.\n * `getItemTtl` exposes the underlying remaining TTL in milliseconds; `setItem` returns the underlying cache.\n * `setItemWithTtl` accepts its TTL in milliseconds before the value and key arguments and returns the cache.\n * The facade does not dispose the supplied cache, and LRU defaults remain those of the supplied instance.\n *\n * @typeParam D - The stored value type used by reads and writes.\n *\n * @param lruInstance - The shared LRU cache instance.\n *\n * @returns A factory accepting a key resolver and returning a new frozen keyed facade sharing the cache.\n *\n * @example\n *\n * ```ts\n * import { createLruKeyedStore } from '@kikiutils/shared/storages/lru/keyed-store';\n * import { LRUCache } from 'lru-cache';\n *\n * const cache = new LRUCache<string, { name: string }>({ max: 100 });\n * const keyedStore = createLruKeyedStore<{ name: string }>(cache)((userId: string) => `user:${userId}`);\n * keyedStore.setItem({ name: 'Alice' }, 'user-123');\n * console.log(keyedStore.getItem('user-123')); // => { name: 'Alice' }\n * ```\n */\nexport function createLruKeyedStore<D = unknown>(lruInstance: LRUCache<any, any, any>) {\n return <P extends any[]>(keyFn: (...args: P) => string) => Object.freeze({\n /**\n * Returns the cached value and applies the underlying cache's read-recency policy.\n *\n * @returns The cached value without copying it, or `null` when absent or nullish.\n */\n getItem(...args: P) {\n const rawValue = lruInstance.get(keyFn(...args));\n return rawValue as D ?? null;\n },\n getItemTtl: (...args: P) => lruInstance.getRemainingTTL(keyFn(...args)),\n hasItem: (...args: P) => lruInstance.has(keyFn(...args)),\n removeItem: (...args: P) => lruInstance.delete(keyFn(...args)),\n /**\n * Resolves the full cache key from the given arguments.\n */\n resolveKey: (...args: P) => keyFn(...args),\n setItem: (value: D, ...args: P) => lruInstance.set(keyFn(...args), value),\n setItemWithTtl(ttlMilliseconds: number, value: D, ...args: P) {\n return lruInstance.set(keyFn(...args), value, { ttl: ttlMilliseconds });\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,oBAAiC,aAAsC;CACnF,QAAyB,UAAkC,OAAO,OAAO;;;;;;EAMrE,QAAQ,GAAG,MAAS;GAEhB,OADiB,YAAY,IAAI,MAAM,GAAG,IAAI,CAChC,KAAU;EAC5B;EACA,aAAa,GAAG,SAAY,YAAY,gBAAgB,MAAM,GAAG,IAAI,CAAC;EACtE,UAAU,GAAG,SAAY,YAAY,IAAI,MAAM,GAAG,IAAI,CAAC;EACvD,aAAa,GAAG,SAAY,YAAY,OAAO,MAAM,GAAG,IAAI,CAAC;;;;EAI7D,aAAa,GAAG,SAAY,MAAM,GAAG,IAAI;EACzC,UAAU,OAAU,GAAG,SAAY,YAAY,IAAI,MAAM,GAAG,IAAI,GAAG,KAAK;EACxE,eAAe,iBAAyB,OAAU,GAAG,MAAS;GAC1D,OAAO,YAAY,IAAI,MAAM,GAAG,IAAI,GAAG,OAAO,EAAE,KAAK,gBAAgB,CAAC;EAC1E;CACJ,CAAC;AACL"}
|
|
@@ -14,4 +14,5 @@ type PathImpl<K extends number | string, V, U> = [U] extends [never] ? DefaultPa
|
|
|
14
14
|
type TerminalType = bigint | Blob | boolean | Date | File | null | number | ObjectId | RegExp | string | symbol | undefined;
|
|
15
15
|
type TupleKey<T extends ReadonlyArray<any>> = Exclude<keyof T, keyof any[]>;
|
|
16
16
|
//#endregion
|
|
17
|
+
export {};
|
|
17
18
|
//# sourceMappingURL=filtered-key-path.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kikiutils/shared",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "18.
|
|
4
|
+
"version": "18.3.0",
|
|
5
5
|
"description": "A lightweight and modular utility library for modern JavaScript and TypeScript — includes secure hashing, flexible logging, datetime tools, Vue/web helpers, storage abstraction, and more.",
|
|
6
6
|
"author": "kiki-kanri",
|
|
7
7
|
"license": "MIT",
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"date-fns": "^4.4.0",
|
|
76
76
|
"decimal.js": "^10.6.0",
|
|
77
77
|
"element-plus": "^2.14.4",
|
|
78
|
+
"file-type": "^22.1.1",
|
|
78
79
|
"lru-cache": "^11.5.2",
|
|
79
80
|
"millify": "^6.1.0",
|
|
80
81
|
"msgpackr": "^2.0.5",
|
|
@@ -109,6 +110,9 @@
|
|
|
109
110
|
"element-plus": {
|
|
110
111
|
"optional": true
|
|
111
112
|
},
|
|
113
|
+
"file-type": {
|
|
114
|
+
"optional": true
|
|
115
|
+
},
|
|
112
116
|
"lru-cache": {
|
|
113
117
|
"optional": true
|
|
114
118
|
},
|
|
@@ -136,12 +140,12 @@
|
|
|
136
140
|
},
|
|
137
141
|
"devDependencies": {
|
|
138
142
|
"@antfu/eslint-config": "^9.5.1",
|
|
139
|
-
"@kikiutils/eslint-config": "^9.
|
|
143
|
+
"@kikiutils/eslint-config": "^9.3.0",
|
|
140
144
|
"@kikiutils/tsconfigs": "^7.0.0",
|
|
141
145
|
"@noble/hashes": "^2.4.0",
|
|
142
|
-
"@types/node": "^26.6.
|
|
146
|
+
"@types/node": "^26.6.5",
|
|
143
147
|
"@types/ssh2": "^1.15.6",
|
|
144
|
-
"@vitest/coverage-v8": "^5.0.
|
|
148
|
+
"@vitest/coverage-v8": "^5.0.4",
|
|
145
149
|
"async-validator": "^4.2.5",
|
|
146
150
|
"bson": "^7.3.3",
|
|
147
151
|
"changelogen": "^0.6.2",
|
|
@@ -150,21 +154,22 @@
|
|
|
150
154
|
"date-fns": "^4.4.0",
|
|
151
155
|
"decimal.js": "^10.6.0",
|
|
152
156
|
"element-plus": "^2.14.7",
|
|
153
|
-
"eslint": "^10.
|
|
154
|
-
"
|
|
155
|
-
"
|
|
157
|
+
"eslint": "^10.12.0",
|
|
158
|
+
"file-type": "^22.1.1",
|
|
159
|
+
"jsdom": "^30.1.2",
|
|
160
|
+
"knip": "^6.41.0",
|
|
156
161
|
"lru-cache": "^11.5.3",
|
|
157
162
|
"millify": "^6.1.0",
|
|
158
163
|
"msgpackr": "^2.1.0",
|
|
159
164
|
"node-ssh": "^13.2.1",
|
|
160
|
-
"pino": "^10.
|
|
161
|
-
"pino-pretty": "^13.
|
|
165
|
+
"pino": "^10.4.0",
|
|
166
|
+
"pino-pretty": "^13.2.0",
|
|
162
167
|
"publint": "^0.3.25",
|
|
163
|
-
"tsdown": "^0.23.
|
|
168
|
+
"tsdown": "^0.23.1",
|
|
164
169
|
"typescript": "^6.0.3",
|
|
165
170
|
"unplugin-unused": "^0.6.0",
|
|
166
|
-
"vitest": "^5.0.
|
|
171
|
+
"vitest": "^5.0.4",
|
|
167
172
|
"vue": "^3.5.43",
|
|
168
|
-
"vue-router": "^5.
|
|
173
|
+
"vue-router": "^5.4.0"
|
|
169
174
|
}
|
|
170
175
|
}
|
|
@@ -39,6 +39,20 @@ export class EnhancedDate extends Date {
|
|
|
39
39
|
return new EnhancedDate(dateFns.endOfToday());
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Returns a new instance at the end of tomorrow in the system time zone.
|
|
44
|
+
*/
|
|
45
|
+
static endOfTomorrow() {
|
|
46
|
+
return new EnhancedDate(dateFns.endOfTomorrow());
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Returns a new instance at the end of yesterday in the system time zone.
|
|
51
|
+
*/
|
|
52
|
+
static endOfYesterday() {
|
|
53
|
+
return new EnhancedDate(dateFns.endOfYesterday());
|
|
54
|
+
}
|
|
55
|
+
|
|
42
56
|
/**
|
|
43
57
|
* Parses a date using date-fns and an explicit reference for missing fields.
|
|
44
58
|
*
|
|
@@ -79,6 +93,28 @@ export class EnhancedDate extends Date {
|
|
|
79
93
|
return new EnhancedDate(seconds * 1000);
|
|
80
94
|
}
|
|
81
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Returns the latest date as a new independent instance.
|
|
98
|
+
*
|
|
99
|
+
* @param dates - Dates or millisecond timestamps to compare.
|
|
100
|
+
*
|
|
101
|
+
* @returns A new `EnhancedDate`, or `Invalid Date` if the array is empty or contains an invalid date.
|
|
102
|
+
*/
|
|
103
|
+
static max(dates: (Date | number)[]) {
|
|
104
|
+
return new EnhancedDate(dateFns.max(dates));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Returns the earliest date as a new independent instance.
|
|
109
|
+
*
|
|
110
|
+
* @param dates - Dates or millisecond timestamps to compare.
|
|
111
|
+
*
|
|
112
|
+
* @returns A new `EnhancedDate`, or `Invalid Date` if the array is empty or contains an invalid date.
|
|
113
|
+
*/
|
|
114
|
+
static min(dates: (Date | number)[]) {
|
|
115
|
+
return new EnhancedDate(dateFns.min(dates));
|
|
116
|
+
}
|
|
117
|
+
|
|
82
118
|
/**
|
|
83
119
|
* Returns a new instance at the start of today in the system time zone.
|
|
84
120
|
*/
|
|
@@ -86,6 +122,20 @@ export class EnhancedDate extends Date {
|
|
|
86
122
|
return new EnhancedDate(dateFns.startOfToday());
|
|
87
123
|
}
|
|
88
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Returns a new instance at the start of tomorrow in the system time zone.
|
|
127
|
+
*/
|
|
128
|
+
static startOfTomorrow() {
|
|
129
|
+
return new EnhancedDate(dateFns.startOfTomorrow());
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Returns a new instance at the start of yesterday in the system time zone.
|
|
134
|
+
*/
|
|
135
|
+
static startOfYesterday() {
|
|
136
|
+
return new EnhancedDate(dateFns.startOfYesterday());
|
|
137
|
+
}
|
|
138
|
+
|
|
89
139
|
// Public instance methods
|
|
90
140
|
|
|
91
141
|
/**
|
package/src/classes/path.ts
CHANGED
|
@@ -489,8 +489,19 @@ export class Path {
|
|
|
489
489
|
): Promise<fs.BigIntStats | undefined>;
|
|
490
490
|
stat(opts: fs.StatOptions & { throwIfNoEntry?: true }): Promise<fs.BigIntStats | fs.Stats>;
|
|
491
491
|
stat(opts?: fs.StatOptions): Promise<fs.BigIntStats | fs.Stats | undefined>;
|
|
492
|
-
stat(
|
|
493
|
-
|
|
492
|
+
async stat(opts?: fs.StatOptions): Promise<fs.BigIntStats | fs.Stats | undefined> {
|
|
493
|
+
try {
|
|
494
|
+
return await fsp.stat(this.#value, opts);
|
|
495
|
+
} catch (error) {
|
|
496
|
+
if (
|
|
497
|
+
opts?.throwIfNoEntry === false
|
|
498
|
+
&& error instanceof Error
|
|
499
|
+
&& 'code' in error
|
|
500
|
+
&& error.code === 'ENOENT'
|
|
501
|
+
) return undefined;
|
|
502
|
+
|
|
503
|
+
throw error;
|
|
504
|
+
}
|
|
494
505
|
}
|
|
495
506
|
|
|
496
507
|
/**
|
package/src/file.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fileTypeFromBlob,
|
|
3
|
+
fileTypeFromBuffer,
|
|
4
|
+
} from 'file-type';
|
|
5
|
+
|
|
6
|
+
import type { BinaryInput } from './types';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Detects a lowercase MIME type from binary content rather than its name or declared type.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* Requires the optional `file-type` peer dependency. Only formats supported by its binary detection
|
|
13
|
+
* are recognized; this is not a general text-file detector or a guarantee that a file is safe.
|
|
14
|
+
* Blob and File inputs are read through the detector's tokenizer instead of being fully buffered up front.
|
|
15
|
+
* The amount of content inspected depends on its format; this does not impose a fixed read limit.
|
|
16
|
+
* Detection and input-reading errors propagate to the caller.
|
|
17
|
+
*
|
|
18
|
+
* @param input - The binary content to inspect.
|
|
19
|
+
*
|
|
20
|
+
* @returns The detected lowercase MIME type, or `undefined` when the content is not recognized.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { getFileMimeType } from '@kikiutils/shared/file';
|
|
26
|
+
*
|
|
27
|
+
* const mimeType = await getFileMimeType(file);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export async function getFileMimeType(input: BinaryInput) {
|
|
31
|
+
// The tokenizer only uses size, slice, and arrayBuffer; Node/DOM Blob stream typings differ.
|
|
32
|
+
const result = input instanceof ArrayBuffer || input instanceof Uint8Array
|
|
33
|
+
? await fileTypeFromBuffer(input)
|
|
34
|
+
: await fileTypeFromBlob(input as Blob);
|
|
35
|
+
|
|
36
|
+
return result?.mime.toLowerCase();
|
|
37
|
+
}
|
|
@@ -7,6 +7,7 @@ import type { LRUCache } from 'lru-cache';
|
|
|
7
7
|
* The key resolver is called synchronously once per operation, and its exceptions propagate.
|
|
8
8
|
* Reads return the cached value without copying it, or `null` for missing or nullish values.
|
|
9
9
|
* `getItemTtl` exposes the underlying remaining TTL in milliseconds; `setItem` returns the underlying cache.
|
|
10
|
+
* `setItemWithTtl` accepts its TTL in milliseconds before the value and key arguments and returns the cache.
|
|
10
11
|
* The facade does not dispose the supplied cache, and LRU defaults remain those of the supplied instance.
|
|
11
12
|
*
|
|
12
13
|
* @typeParam D - The stored value type used by reads and writes.
|
|
@@ -46,5 +47,8 @@ export function createLruKeyedStore<D = unknown>(lruInstance: LRUCache<any, any,
|
|
|
46
47
|
*/
|
|
47
48
|
resolveKey: (...args: P) => keyFn(...args),
|
|
48
49
|
setItem: (value: D, ...args: P) => lruInstance.set(keyFn(...args), value),
|
|
50
|
+
setItemWithTtl(ttlMilliseconds: number, value: D, ...args: P) {
|
|
51
|
+
return lruInstance.set(keyFn(...args), value, { ttl: ttlMilliseconds });
|
|
52
|
+
},
|
|
49
53
|
});
|
|
50
54
|
}
|