@kikiutils/shared 20.0.1 → 20.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/buffer.js.map +1 -1
- package/dist/classes/enhanced-date.d.ts +2 -2
- package/dist/classes/enhanced-date.d.ts.map +1 -1
- package/dist/classes/enhanced-date.js.map +1 -1
- package/dist/classes/path.d.ts +1 -1
- package/dist/classes/path.d.ts.map +1 -1
- package/dist/classes/path.js +30 -30
- package/dist/classes/path.js.map +1 -1
- package/dist/enum.d.ts +4 -3
- package/dist/enum.d.ts.map +1 -1
- package/dist/enum.js +3 -2
- package/dist/enum.js.map +1 -1
- package/dist/event-awaiter.d.ts.map +1 -1
- package/dist/event-awaiter.js +7 -6
- package/dist/event-awaiter.js.map +1 -1
- package/dist/general.d.ts +3 -2
- package/dist/general.d.ts.map +1 -1
- package/dist/general.js.map +1 -1
- package/dist/logger/_internals/formatter.d.ts +12 -4
- package/dist/logger/_internals/formatter.d.ts.map +1 -1
- package/dist/logger/_internals/formatter.js +12 -4
- package/dist/logger/_internals/formatter.js.map +1 -1
- package/dist/logger/_internals/logger.d.ts +6 -2
- package/dist/logger/_internals/logger.d.ts.map +1 -1
- package/dist/logger/_internals/logger.js +6 -3
- package/dist/logger/_internals/logger.js.map +1 -1
- package/dist/logger/node/_internals/file-writer.d.ts +3 -1
- package/dist/logger/node/_internals/file-writer.d.ts.map +1 -1
- package/dist/logger/node/_internals/file-writer.js +13 -9
- package/dist/logger/node/_internals/file-writer.js.map +1 -1
- package/dist/logger/node/_internals/formatter.d.ts +3 -1
- package/dist/logger/node/_internals/formatter.d.ts.map +1 -1
- package/dist/logger/node/_internals/formatter.js +3 -1
- package/dist/logger/node/_internals/formatter.js.map +1 -1
- package/dist/logger/node/index.js +11 -9
- package/dist/logger/node/index.js.map +1 -1
- package/dist/logger/node/types.d.ts +36 -12
- package/dist/logger/node/types.d.ts.map +1 -1
- package/dist/logger/types.d.ts +44 -19
- package/dist/logger/types.d.ts.map +1 -1
- package/dist/redis/script-runner.d.ts +1 -1
- package/dist/redis/script-runner.d.ts.map +1 -1
- package/dist/redis/script-runner.js.map +1 -1
- package/dist/storages/redis/keyed-store.d.ts.map +1 -1
- package/dist/storages/redis/keyed-store.js +10 -10
- package/dist/storages/redis/keyed-store.js.map +1 -1
- package/dist/storages/redis/msgpack.js +2 -2
- package/dist/storages/redis/msgpack.js.map +1 -1
- package/dist/time.d.ts.map +1 -1
- package/dist/time.js +4 -4
- package/dist/time.js.map +1 -1
- package/dist/types/filtered-key-path.d.ts +2 -2
- package/dist/types/filtered-key-path.d.ts.map +1 -1
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/url.d.ts.map +1 -1
- package/dist/url.js.map +1 -1
- package/package.json +15 -11
- package/src/buffer.ts +0 -1
- package/src/classes/enhanced-date.ts +2 -2
- package/src/classes/path.ts +31 -31
- package/src/enum.ts +11 -5
- package/src/event-awaiter.ts +9 -7
- package/src/general.ts +5 -3
- package/src/logger/_internals/formatter.ts +12 -4
- package/src/logger/_internals/logger.ts +13 -4
- package/src/logger/node/_internals/file-writer.ts +13 -9
- package/src/logger/node/_internals/formatter.ts +3 -1
- package/src/logger/node/index.ts +13 -10
- package/src/logger/node/types.ts +36 -12
- package/src/logger/types.ts +45 -19
- package/src/redis/script-runner.ts +1 -1
- package/src/storages/redis/keyed-store.ts +10 -10
- package/src/storages/redis/msgpack.ts +2 -2
- package/src/time.ts +4 -4
- package/src/types/filtered-key-path.ts +2 -2
- package/src/types/index.ts +6 -0
- package/src/url.ts +0 -1
package/dist/buffer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer.js","names":[],"sources":["../src/buffer.ts"],"sourcesContent":["import { Buffer } from 'node:buffer';\n\nimport type { BinaryInput } from './types';\n\n/**\n * Converts binary input to a Node.js `Buffer`.\n *\n * @remarks\n * An existing `Buffer` is returned unchanged. `ArrayBuffer` and `Uint8Array` inputs share their backing memory\n * with the result, so changes are visible through both views. `Blob` and `File` inputs are read asynchronously.\n *\n * @param input - The binary data to convert.\n *\n * @returns A promise resolving to the original buffer or a new buffer view after the input is available.\n *\n * @throws TypeError through promise rejection if the input is unsupported.\n *\n * @example\n *\n * ```ts\n * import { toBuffer } from '@kikiutils/shared/buffer';\n *\n * const bytes = new Uint8Array([\n * 10,\n * 20,\n * 30,\n * ]);\n *\n * const buffer = await toBuffer(bytes);\n * bytes[0] = 40;\n * console.log(buffer[0]); // => 40\n * ```\n */\nexport async function toBuffer(input: BinaryInput) {\n if (Buffer.isBuffer(input)) return input;\n if (input instanceof ArrayBuffer) return Buffer.from(input);\n if (input instanceof Uint8Array) return Buffer.from(input.buffer, input.byteOffset, input.byteLength);\n if (typeof input.arrayBuffer === 'function') return Buffer.from(await input.arrayBuffer());\n
|
|
1
|
+
{"version":3,"file":"buffer.js","names":[],"sources":["../src/buffer.ts"],"sourcesContent":["import { Buffer } from 'node:buffer';\n\nimport type { BinaryInput } from './types';\n\n/**\n * Converts binary input to a Node.js `Buffer`.\n *\n * @remarks\n * An existing `Buffer` is returned unchanged. `ArrayBuffer` and `Uint8Array` inputs share their backing memory\n * with the result, so changes are visible through both views. `Blob` and `File` inputs are read asynchronously.\n *\n * @param input - The binary data to convert.\n *\n * @returns A promise resolving to the original buffer or a new buffer view after the input is available.\n *\n * @throws TypeError through promise rejection if the input is unsupported.\n *\n * @example\n *\n * ```ts\n * import { toBuffer } from '@kikiutils/shared/buffer';\n *\n * const bytes = new Uint8Array([\n * 10,\n * 20,\n * 30,\n * ]);\n *\n * const buffer = await toBuffer(bytes);\n * bytes[0] = 40;\n * console.log(buffer[0]); // => 40\n * ```\n */\nexport async function toBuffer(input: BinaryInput) {\n if (Buffer.isBuffer(input)) return input;\n if (input instanceof ArrayBuffer) return Buffer.from(input);\n if (input instanceof Uint8Array) return Buffer.from(input.buffer, input.byteOffset, input.byteLength);\n if (typeof input.arrayBuffer === 'function') return Buffer.from(await input.arrayBuffer());\n throw new TypeError('The provided input is not a supported binary type (Blob, Buffer, File, ArrayBuffer, or Uint8Array).');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,eAAsB,SAAS,OAAoB;CAC/C,IAAI,OAAO,SAAS,KAAK,GAAG,OAAO;CACnC,IAAI,iBAAiB,aAAa,OAAO,OAAO,KAAK,KAAK;CAC1D,IAAI,iBAAiB,YAAY,OAAO,OAAO,KAAK,MAAM,QAAQ,MAAM,YAAY,MAAM,UAAU;CACpG,IAAI,OAAO,MAAM,gBAAgB,YAAY,OAAO,OAAO,KAAK,MAAM,MAAM,YAAY,CAAC;CACzF,MAAM,IAAI,UAAU,qGAAqG;AAC7H"}
|
|
@@ -74,7 +74,7 @@ export declare class EnhancedDate extends Date {
|
|
|
74
74
|
*
|
|
75
75
|
* @returns A new `EnhancedDate`, or `Invalid Date` if the array is empty or contains an invalid date.
|
|
76
76
|
*/
|
|
77
|
-
static max(dates:
|
|
77
|
+
static max(dates: Array<Date | number>): EnhancedDate;
|
|
78
78
|
/**
|
|
79
79
|
* Returns the earliest date as a new independent instance.
|
|
80
80
|
*
|
|
@@ -82,7 +82,7 @@ export declare class EnhancedDate extends Date {
|
|
|
82
82
|
*
|
|
83
83
|
* @returns A new `EnhancedDate`, or `Invalid Date` if the array is empty or contains an invalid date.
|
|
84
84
|
*/
|
|
85
|
-
static min(dates:
|
|
85
|
+
static min(dates: Array<Date | number>): EnhancedDate;
|
|
86
86
|
/**
|
|
87
87
|
* Returns a new instance at the start of today in the system time zone.
|
|
88
88
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enhanced-date.d.ts","names":[],"sources":["../../src/classes/enhanced-date.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA+Ba,qBAAqB;;;;SAMvB,cAAU;;;;SAOV,iBAAa;;;;SAOb,kBAAc;;;;;;;;;;;SAcd,WACH,eACA,iBACA,eAAe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QAAQ;;;;EAO/B;;;;EAOA,UAAU,OAAO,QAAQ,QAAQ;;;;EAOjC,aAAa,OAAO,QAAQ,QAAQ;;;;EAOpC;;;;EAOA;;;;EAOA;;;;;;EASA;;;;;;EAUA;;;;;;EAUA;;;;;;;;EAYA,YAAY,UAAU,QAAQ;;;;;;;;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"}
|
|
@@ -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 * 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;;;;;;;;CASA,OAAO,IAAI,OAA0B;EACjC,OAAO,IAAI,aAAa,QAAQ,IAAI,KAAK,CAAC;CAC9C;;;;;;;;CASA,OAAO,IAAI,OAA0B;EACjC,OAAO,IAAI,aAAa,QAAQ,IAAI,KAAK,CAAC;CAC9C;;;;CAKA,OAAO,eAAe;EAClB,OAAO,IAAI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WAAW;CACnC;;;;CAKA,kBAAkB;EACd,OAAO,KAAK,MAAM,CAAC,CAAC,cAAc;CACtC;;;;CAKA,iBAAiB;EACb,OAAO,KAAK,MAAM,CAAC,CAAC,aAAa;CACrC;;;;CAKA,cAAc,SAAsC;EAChD,OAAO,KAAK,MAAM,CAAC,CAAC,YAAY,OAAO;CAC3C;;;;CAKA,UAAU,QAAgB;EACtB,OAAO,KAAK,MAAM,CAAC,CAAC,QAAQ,MAAM;CACtC;;;;CAKA,WAAW,QAAgB;EACvB,OAAO,KAAK,MAAM,CAAC,CAAC,SAAS,MAAM;CACvC;;;;CAKA,kBAAkB,QAAgB;EAC9B,OAAO,KAAK,MAAM,CAAC,CAAC,gBAAgB,MAAM;CAC9C;;;;CAKA,aAAa,QAAgB;EACzB,OAAO,KAAK,MAAM,CAAC,CAAC,WAAW,MAAM;CACzC;;;;CAKA,YAAY,QAAgB;EACxB,OAAO,KAAK,MAAM,CAAC,CAAC,UAAU,MAAM;CACxC;;;;CAKA,aAAa,QAAgB;EACzB,OAAO,KAAK,MAAM,CAAC,CAAC,WAAW,MAAM;CACzC;;;;CAKA,WAAW,QAAgB;EACvB,OAAO,KAAK,MAAM,CAAC,CAAC,SAAS,MAAM;CACvC;;;;CAKA,WAAW,QAAgB;EACvB,OAAO,KAAK,MAAM,CAAC,CAAC,SAAS,MAAM;CACvC;AACJ"}
|
|
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 * 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: Array<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: Array<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;;;;;;;;CASA,OAAO,IAAI,OAA6B;EACpC,OAAO,IAAI,aAAa,QAAQ,IAAI,KAAK,CAAC;CAC9C;;;;;;;;CASA,OAAO,IAAI,OAA6B;EACpC,OAAO,IAAI,aAAa,QAAQ,IAAI,KAAK,CAAC;CAC9C;;;;CAKA,OAAO,eAAe;EAClB,OAAO,IAAI,aAAa,QAAQ,aAAa,CAAC;CAClD;;;;CAKA,OAAO,kBAAkB;EACrB,OAAO,IAAI,aAAa,QAAQ,gBAAgB,CAAC;CACrD;;;;C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AGM;IACA;IACA;MAEP,QAAQ;EACX,QACI,UACI,kBACC,GAAG;IACF;IACA;cAGP,QAAQ;EACX,QACI,SAAS,GAAG;IACR;IACA;MAEL,QAAQ,GAAG;EACd,QACI;IACI;IACA;IACA;MAEL,QAAQ,MAAM,GAAG,OAAO;;;;;;;;;EAa3B,SACI,WACK;IACC;IACA,OAAO,GAAG;cAGjB,QAAQ;EACX,SACI,UACK;IACC,UAAU;IACV,OAAO,GAAG;OAEZ,iBACL;EACH,SACI,WAEQ,YACA,GAAG;IACD,OAAO,GAAG;OAEd,wBAEP,QAAQ;;;;;;;;;;;EAeL,OAAO,SAAS,WAAQ;;;;;;;;;EAYxB,MAAM,MAAM,2BAA2B,IAAI,MAAG;;;;;;;;;EAY9C,SAAS,MAAM,2BAA2B,IAAI,SAAM;;;;;;;;;;EAa1D,KACI,OAAO,GAAG;IACN;IACA;MAEL,QAAQ,GAAG;EACd,KACI,MAAM,GAAG;IACL;IACA;MAEL,QAAQ,GAAG;EACd,KACI,MAAM,GAAG;IACL;IACA;MAEL,QAAQ,GAAG;EACd,KACI,MAAM,GAAG;IACL;IACA;MAEL,QAAQ,GAAG;EACd,KAAK,MAAM,GAAG;IAAgB;MAA0B,QAAQ,GAAG,cAAc,GAAG;EACpF,KAAK,OAAO,GAAG,cAAc,QAAQ,GAAG,cAAc,GAAG;;;;;;;;;EAwBnD,YAAY,MAAM,2BAA2B,IAAI,YAAS;;;;;;;;;EAY1D,UAAM;;;;;;;;;EAYN,aAAa,MAAM,2BAA2B,IAAI,aAAU"}
|
package/dist/classes/path.js
CHANGED
|
@@ -200,8 +200,8 @@ var Path = class Path {
|
|
|
200
200
|
*
|
|
201
201
|
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.access}
|
|
202
202
|
*/
|
|
203
|
-
access(...args) {
|
|
204
|
-
return fsp.access(this.#value, ...args);
|
|
203
|
+
async access(...args) {
|
|
204
|
+
return await fsp.access(this.#value, ...args);
|
|
205
205
|
}
|
|
206
206
|
/**
|
|
207
207
|
* Appends data to the file at the stored path.
|
|
@@ -211,8 +211,8 @@ var Path = class Path {
|
|
|
211
211
|
*
|
|
212
212
|
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.appendFile}
|
|
213
213
|
*/
|
|
214
|
-
appendFile(...args) {
|
|
215
|
-
return fsp.appendFile(this.#value, ...args);
|
|
214
|
+
async appendFile(...args) {
|
|
215
|
+
return await fsp.appendFile(this.#value, ...args);
|
|
216
216
|
}
|
|
217
217
|
/**
|
|
218
218
|
* Changes the permissions of the stored path.
|
|
@@ -222,8 +222,8 @@ var Path = class Path {
|
|
|
222
222
|
*
|
|
223
223
|
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.chmod}
|
|
224
224
|
*/
|
|
225
|
-
chmod(...args) {
|
|
226
|
-
return fsp.chmod(this.#value, ...args);
|
|
225
|
+
async chmod(...args) {
|
|
226
|
+
return await fsp.chmod(this.#value, ...args);
|
|
227
227
|
}
|
|
228
228
|
/**
|
|
229
229
|
* Changes the owner and group of the stored path.
|
|
@@ -233,8 +233,8 @@ var Path = class Path {
|
|
|
233
233
|
*
|
|
234
234
|
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.chown}
|
|
235
235
|
*/
|
|
236
|
-
chown(...args) {
|
|
237
|
-
return fsp.chown(this.#value, ...args);
|
|
236
|
+
async chown(...args) {
|
|
237
|
+
return await fsp.chown(this.#value, ...args);
|
|
238
238
|
}
|
|
239
239
|
/**
|
|
240
240
|
* Copies the file at the stored path to a destination.
|
|
@@ -244,11 +244,11 @@ var Path = class Path {
|
|
|
244
244
|
*
|
|
245
245
|
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.copyFile}
|
|
246
246
|
*/
|
|
247
|
-
copyFile(...args) {
|
|
248
|
-
return fsp.copyFile(this.#value, ...args);
|
|
247
|
+
async copyFile(...args) {
|
|
248
|
+
return await fsp.copyFile(this.#value, ...args);
|
|
249
249
|
}
|
|
250
|
-
mkdir(...args) {
|
|
251
|
-
return fsp.mkdir(this.#value, ...args);
|
|
250
|
+
async mkdir(...args) {
|
|
251
|
+
return await fsp.mkdir(this.#value, ...args);
|
|
252
252
|
}
|
|
253
253
|
/**
|
|
254
254
|
* Opens the file at the stored path.
|
|
@@ -258,14 +258,14 @@ var Path = class Path {
|
|
|
258
258
|
*
|
|
259
259
|
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.open}
|
|
260
260
|
*/
|
|
261
|
-
open(...args) {
|
|
262
|
-
return fsp.open(this.#value, ...args);
|
|
261
|
+
async open(...args) {
|
|
262
|
+
return await fsp.open(this.#value, ...args);
|
|
263
263
|
}
|
|
264
|
-
readdir(...args) {
|
|
265
|
-
return fsp.readdir(this.#value, ...args);
|
|
264
|
+
async readdir(...args) {
|
|
265
|
+
return await fsp.readdir(this.#value, ...args);
|
|
266
266
|
}
|
|
267
|
-
readFile(...args) {
|
|
268
|
-
return fsp.readFile(this.#value, ...args);
|
|
267
|
+
async readFile(...args) {
|
|
268
|
+
return await fsp.readFile(this.#value, ...args);
|
|
269
269
|
}
|
|
270
270
|
/**
|
|
271
271
|
* Renames or moves the file or directory at the stored path.
|
|
@@ -277,8 +277,8 @@ var Path = class Path {
|
|
|
277
277
|
*
|
|
278
278
|
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.rename}
|
|
279
279
|
*/
|
|
280
|
-
rename(newPath) {
|
|
281
|
-
return fsp.rename(this.#value, newPath.toString());
|
|
280
|
+
async rename(newPath) {
|
|
281
|
+
return await fsp.rename(this.#value, newPath.toString());
|
|
282
282
|
}
|
|
283
283
|
/**
|
|
284
284
|
* Removes the file or directory at the stored path.
|
|
@@ -288,8 +288,8 @@ var Path = class Path {
|
|
|
288
288
|
*
|
|
289
289
|
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.rm}
|
|
290
290
|
*/
|
|
291
|
-
rm(...args) {
|
|
292
|
-
return fsp.rm(this.#value, ...args);
|
|
291
|
+
async rm(...args) {
|
|
292
|
+
return await fsp.rm(this.#value, ...args);
|
|
293
293
|
}
|
|
294
294
|
/**
|
|
295
295
|
* Removes the directory at the stored path.
|
|
@@ -299,8 +299,8 @@ var Path = class Path {
|
|
|
299
299
|
*
|
|
300
300
|
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.rmdir}
|
|
301
301
|
*/
|
|
302
|
-
rmdir(...args) {
|
|
303
|
-
return fsp.rmdir(this.#value, ...args);
|
|
302
|
+
async rmdir(...args) {
|
|
303
|
+
return await fsp.rmdir(this.#value, ...args);
|
|
304
304
|
}
|
|
305
305
|
async stat(opts) {
|
|
306
306
|
try {
|
|
@@ -318,8 +318,8 @@ var Path = class Path {
|
|
|
318
318
|
*
|
|
319
319
|
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.truncate}
|
|
320
320
|
*/
|
|
321
|
-
truncate(...args) {
|
|
322
|
-
return fsp.truncate(this.#value, ...args);
|
|
321
|
+
async truncate(...args) {
|
|
322
|
+
return await fsp.truncate(this.#value, ...args);
|
|
323
323
|
}
|
|
324
324
|
/**
|
|
325
325
|
* Deletes the file or symbolic link at the stored path.
|
|
@@ -329,8 +329,8 @@ var Path = class Path {
|
|
|
329
329
|
*
|
|
330
330
|
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.unlink}
|
|
331
331
|
*/
|
|
332
|
-
unlink() {
|
|
333
|
-
return fsp.unlink(this.#value);
|
|
332
|
+
async unlink() {
|
|
333
|
+
return await fsp.unlink(this.#value);
|
|
334
334
|
}
|
|
335
335
|
/**
|
|
336
336
|
* Writes data to the file at the stored path.
|
|
@@ -340,8 +340,8 @@ var Path = class Path {
|
|
|
340
340
|
*
|
|
341
341
|
* @see {@link https://nodejs.org/api/fs.html | Node.js fsPromises.writeFile}
|
|
342
342
|
*/
|
|
343
|
-
writeFile(...args) {
|
|
344
|
-
return fsp.writeFile(this.#value, ...args);
|
|
343
|
+
async writeFile(...args) {
|
|
344
|
+
return await fsp.writeFile(this.#value, ...args);
|
|
345
345
|
}
|
|
346
346
|
};
|
|
347
347
|
export { 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 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;;;;;;;;CASA,UAAU;E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,MAAM,GAAG,MAAgB;EACrB,OAAO,IAAI,MAAM,KAAK,QAAQ,GAAG,IAAI;CACzC;;;;;;;;;CAUA,KAAK,GAAG,MAA4C;EAChD,OAAO,IAAI,KAAK,KAAK,QAAQ,GAAG,IAAI;CACxC;CAkDA,QAAQ,GAAG,MAAgB;EACvB,OAAO,IAAI,QAAQ,KAAK,QAAQ,GAAG,IAAI;CAC3C;CAoCA,SAAS,GAAG,MAAgB;EACxB,OAAO,IAAI,SAAS,KAAK,QAAQ,GAAG,IAAI;CAC5C;;;;;;;;;;;CAYA,OAAO,SAAmB;EACtB,OAAO,IAAI,OAAO,KAAK,QAAQ,QAAQ,SAAS,CAAC;CACrD;;;;;;;;;CAUA,GAAG,GAAG,MAA0C;EAC5C,OAAO,IAAI,GAAG,KAAK,QAAQ,GAAG,IAAI;CACtC;;;;;;;;;CAUA,MAAM,GAAG,MAA6C;EAClD,OAAO,IAAI,MAAM,KAAK,QAAQ,GAAG,IAAI;CACzC;CAqCA,MAAM,KAAK,MAAuE;EAC9E,IAAI;GACA,OAAO,MAAM,IAAI,KAAK,KAAK,QAAQ,IAAI;EAC3C,SAAS,OAAO;GACZ,IACI,MAAM,mBAAmB,SACtB,iBAAiB,SACjB,UAAU,SACV,MAAM,SAAS,UACpB,OAAO,KAAA;GAET,MAAM;EACV;CACJ;;;;;;;;;CAUA,SAAS,GAAG,MAAgD;EACxD,OAAO,IAAI,SAAS,KAAK,QAAQ,GAAG,IAAI;CAC5C;;;;;;;;;CAUA,SAAS;EACL,OAAO,IAAI,OAAO,KAAK,MAAM;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 async access(...args: DropFirstParameters<typeof fsp.access>) {\n return await 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 async appendFile(...args: DropFirstParameters<typeof fsp.appendFile>) {\n return await 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 async chmod(...args: DropFirstParameters<typeof fsp.chmod>) {\n return await 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 async chown(...args: DropFirstParameters<typeof fsp.chown>) {\n return await 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 async copyFile(...args: DropFirstParameters<typeof fsp.copyFile>) {\n return await 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 async mkdir(...args: any): Promise<any> {\n return await 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 async open(...args: DropFirstParameters<typeof fsp.open>) {\n return await 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<Array<fs.Dirent<Buffer>>>;\n async readdir(...args: any): Promise<any> {\n return await 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 async readFile(...args: any): Promise<any> {\n return await 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 async rename(newPath: PathLike) {\n return await 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 async rm(...args: DropFirstParameters<typeof fsp.rm>) {\n return await 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 async rmdir(...args: DropFirstParameters<typeof fsp.rmdir>) {\n return await 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 async truncate(...args: DropFirstParameters<typeof fsp.truncate>) {\n return await 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 async unlink() {\n return await 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 async writeFile(...args: DropFirstParameters<typeof fsp.writeFile>) {\n return await 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;;;;;;;;CASA,UAAU;EACN,OAAO,KAAK,aAAa,SAAS,QAAQ,KAAK,MAAM,CAAC;CAC1D;;;;;;;;CASA,UAAU;EACN,OAAO,SAAS,QAAQ,KAAK,MAAM;CACvC;;;;;;;;CASA,aAAa;EACT,OAAO,SAAS,WAAW,KAAK,MAAM;CAC1C;;;;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 -22,7 +23,7 @@
|
|
|
22
23
|
* console.log(getEnumNumberValues(RecordType)); // => [0, 1]
|
|
23
24
|
* ```
|
|
24
25
|
*/
|
|
25
|
-
export declare function getEnumNumberValues<T extends Record<string, any>>(enumObject: T): Extract<T
|
|
26
|
+
export declare function getEnumNumberValues<T extends Record<string, any>>(enumObject: T): Array<Extract<ValueOf<T>, number>>;
|
|
26
27
|
/**
|
|
27
28
|
* Extracts only the string values from an enumeration-like object.
|
|
28
29
|
*
|
|
@@ -47,7 +48,7 @@ export declare function getEnumNumberValues<T extends Record<string, any>>(enumO
|
|
|
47
48
|
* console.log(getEnumStringValues(RecordType)); // => ['unknown']
|
|
48
49
|
* ```
|
|
49
50
|
*/
|
|
50
|
-
export declare function getEnumStringValues<T extends Record<string, any>>(enumObject: T): Extract<T
|
|
51
|
+
export declare function getEnumStringValues<T extends Record<string, any>>(enumObject: T): Array<Extract<ValueOf<T>, string>>;
|
|
51
52
|
/**
|
|
52
53
|
* Extracts all values from an enumeration-like object.
|
|
53
54
|
*
|
|
@@ -96,5 +97,5 @@ export declare function getEnumStringValues<T extends Record<string, any>>(enumO
|
|
|
96
97
|
* console.log(getEnumValues(RecordType)); // => [0, 1, 'unknown']
|
|
97
98
|
* ```
|
|
98
99
|
*/
|
|
99
|
-
export declare function getEnumValues<T extends Record<string, any>>(enumObject: T):
|
|
100
|
+
export declare function getEnumValues<T extends Record<string, any>>(enumObject: T): Array<ValueOf<T>>;
|
|
100
101
|
//# sourceMappingURL=enum.d.ts.map
|
package/dist/enum.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum.d.ts","names":[],"sources":["../src/enum.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"enum.d.ts","names":[],"sources":["../src/enum.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;wBA8BgB,oBAAoB,UAAU,qBAAqB,YAAY,IAAI,MAAM,QAAQ,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;wBA4BzF,oBAAoB,UAAU,qBAAqB,YAAY,IAAI,MAAM,QAAQ,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAoDzF,cAAc,UAAU,qBAAqB,YAAY,IAAI,MAAM,QAAQ"}
|
package/dist/enum.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { objectKeys, objectValues } from "ts-extras";
|
|
1
2
|
// src/enum.ts
|
|
2
3
|
/**
|
|
3
4
|
* Extracts only the numeric values from an enumeration-like object.
|
|
@@ -102,9 +103,9 @@ function getEnumStringValues(enumObject) {
|
|
|
102
103
|
* ```
|
|
103
104
|
*/
|
|
104
105
|
function getEnumValues(enumObject) {
|
|
105
|
-
const values =
|
|
106
|
+
const values = objectValues(enumObject);
|
|
106
107
|
if (!values.some((value) => typeof value === "number")) return values;
|
|
107
|
-
return
|
|
108
|
+
return objectKeys(enumObject).filter((key) => Number.isNaN(Number(key))).map((key) => enumObject[key]);
|
|
108
109
|
}
|
|
109
110
|
export { getEnumNumberValues, getEnumStringValues, getEnumValues };
|
|
110
111
|
|
package/dist/enum.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum.js","names":[],"sources":["../src/enum.ts"],"sourcesContent":["/**\n * Extracts only the numeric values from an enumeration-like object.\n *\n * @typeParam T - The type of the enum object.\n *\n * @param enumObject - The enumeration-like object to extract numeric values from,\n * the object can contain numeric values, string values, or both.\n *\n * @returns An array of numeric values extracted from the enum object.\n *\n * @example\n *\n * ```ts\n * import { getEnumNumberValues } from '@kikiutils/shared/enum';\n *\n * enum RecordType {\n * Receive = 0,\n * Send = 1,\n * Unknown = 'unknown',\n * }\n *\n * console.log(getEnumNumberValues(RecordType)); // => [0, 1]\n * ```\n */\nexport function getEnumNumberValues<T extends Record<string, any>>(enumObject: T): Extract<T
|
|
1
|
+
{"version":3,"file":"enum.js","names":[],"sources":["../src/enum.ts"],"sourcesContent":["import {\n objectKeys,\n objectValues,\n} from 'ts-extras';\nimport type { ValueOf } from 'type-fest';\n\n/**\n * Extracts only the numeric values from an enumeration-like object.\n *\n * @typeParam T - The type of the enum object.\n *\n * @param enumObject - The enumeration-like object to extract numeric values from,\n * the object can contain numeric values, string values, or both.\n *\n * @returns An array of numeric values extracted from the enum object.\n *\n * @example\n *\n * ```ts\n * import { getEnumNumberValues } from '@kikiutils/shared/enum';\n *\n * enum RecordType {\n * Receive = 0,\n * Send = 1,\n * Unknown = 'unknown',\n * }\n *\n * console.log(getEnumNumberValues(RecordType)); // => [0, 1]\n * ```\n */\nexport function getEnumNumberValues<T extends Record<string, any>>(enumObject: T): Array<Extract<ValueOf<T>, number>> {\n return getEnumValues(enumObject).filter((value) => typeof value === 'number');\n}\n\n/**\n * Extracts only the string values from an enumeration-like object.\n *\n * @typeParam T - The type of the enum object.\n *\n * @param enumObject - The enumeration-like object to extract string values from,\n * the object can contain numeric values, string values, or both.\n *\n * @returns An array of string values extracted from the enum object.\n *\n * @example\n *\n * ```ts\n * import { getEnumStringValues } from '@kikiutils/shared/enum';\n *\n * enum RecordType {\n * Receive = 0,\n * Send = 1,\n * Unknown = 'unknown',\n * }\n *\n * console.log(getEnumStringValues(RecordType)); // => ['unknown']\n * ```\n */\nexport function getEnumStringValues<T extends Record<string, any>>(enumObject: T): Array<Extract<ValueOf<T>, string>> {\n return getEnumValues(enumObject).filter((value) => typeof value === 'string');\n}\n\n/**\n * Extracts all values from an enumeration-like object.\n *\n * @remarks\n * This function handles TypeScript enums correctly by accounting for the reverse mapping\n * that occurs with numeric enums. It works with pure numeric enums, pure string enums,\n * and mixed enums.\n *\n * @typeParam T - The type of the enum object.\n *\n * @param enumObject - The enumeration-like object to extract values from,\n * the object can contain numeric values, string values, or both.\n *\n * @returns An array containing all the values from the enum object.\n *\n * @example\n *\n * ```ts\n * import { getEnumValues } from '@kikiutils/shared/enum';\n *\n * // Numeric enum\n * enum Status {\n * Active = 0,\n * Inactive = 1,\n * Pending = 2,\n * }\n *\n * console.log(getEnumValues(Status)); // => [0, 1, 2]\n *\n * // String enum\n * enum Color {\n * Red = 'RED',\n * Green = 'GREEN',\n * Blue = 'BLUE',\n * }\n *\n * console.log(getEnumValues(Color)); // => ['RED', 'GREEN', 'BLUE']\n *\n * // Mixed enum\n * enum RecordType {\n * Receive = 0,\n * Send = 1,\n * Unknown = 'unknown',\n * }\n *\n * console.log(getEnumValues(RecordType)); // => [0, 1, 'unknown']\n * ```\n */\nexport function getEnumValues<T extends Record<string, any>>(enumObject: T): Array<ValueOf<T>> {\n const values = objectValues(enumObject);\n const hasNumberValues = values.some((value) => typeof value === 'number');\n if (!hasNumberValues) return values;\n return objectKeys(enumObject).filter((key) => Number.isNaN(Number(key))).map((key) => enumObject[key]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,oBAAmD,YAAmD;CAClH,OAAO,cAAc,UAAU,CAAC,CAAC,QAAQ,UAAU,OAAO,UAAU,QAAQ;AAChF;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,oBAAmD,YAAmD;CAClH,OAAO,cAAc,UAAU,CAAC,CAAC,QAAQ,UAAU,OAAO,UAAU,QAAQ;AAChF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAgB,cAA6C,YAAkC;CAC3F,MAAM,SAAS,aAAa,UAAU;CAEtC,IAAI,CADoB,OAAO,MAAM,UAAU,OAAO,UAAU,QAC7C,GAAG,OAAO;CAC7B,OAAO,WAAW,UAAU,CAAC,CAAC,QAAQ,QAAQ,OAAO,MAAM,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,QAAQ,WAAW,IAAI;AACzG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-awaiter.d.ts","names":[],"sources":["../src/event-awaiter.ts"],"mappings":";;;;;;;;;;;qBAWa,aAAa;;;;;;;;EAYtB,QAAQ,aAAa,OAAO;;;;;;EAa5B,WAAW,QAAO;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"event-awaiter.d.ts","names":[],"sources":["../src/event-awaiter.ts"],"mappings":";;;;;;;;;;;qBAWa,aAAa;;;;;;;;EAYtB,QAAQ,aAAa,OAAO;;;;;;EAa5B,WAAW,QAAO;;;;;;;;;;;;;;;;;;;;EAwBZ,KAAK,aAAa,oBAAoB,8BAA8B,SAAS,cAAW,QAAA;;;;;;;;;;;;;;EAgExF,cAAc,aAAa,oBAAoB,SAAS,cAAW,QAAA;;;;;;;;;;;;;;;EAkBnE,WAAW,aAAa,oBAAoB,SAAS,cAAW,QAAA"}
|
package/dist/event-awaiter.js
CHANGED
|
@@ -53,8 +53,8 @@ var EventAwaiter = class {
|
|
|
53
53
|
*
|
|
54
54
|
* @throws Error through promise rejection if `strict` mode encounters an existing waiter.
|
|
55
55
|
*/
|
|
56
|
-
wait(key, timeoutMs, mode, signal) {
|
|
57
|
-
return new Promise((resolve) => {
|
|
56
|
+
async wait(key, timeoutMs, mode, signal) {
|
|
57
|
+
return await new Promise((resolve) => {
|
|
58
58
|
const resolvers = this.#promiseResolvers.get(key) || [];
|
|
59
59
|
if (resolvers.length) switch (mode) {
|
|
60
60
|
case "override":
|
|
@@ -62,6 +62,7 @@ var EventAwaiter = class {
|
|
|
62
62
|
resolvers.length = 0;
|
|
63
63
|
break;
|
|
64
64
|
case "strict": throw new Error(`Duplicate wait detected for key: ${key}`);
|
|
65
|
+
case void 0:
|
|
65
66
|
}
|
|
66
67
|
resolvers.push(resolve);
|
|
67
68
|
this.#promiseResolvers.set(key, resolvers);
|
|
@@ -98,8 +99,8 @@ var EventAwaiter = class {
|
|
|
98
99
|
*
|
|
99
100
|
* @see {@link EventAwaiter.wait}
|
|
100
101
|
*/
|
|
101
|
-
waitExclusive(key, timeoutMs, signal) {
|
|
102
|
-
return this.wait(key, timeoutMs, "strict", signal);
|
|
102
|
+
async waitExclusive(key, timeoutMs, signal) {
|
|
103
|
+
return await this.wait(key, timeoutMs, "strict", signal);
|
|
103
104
|
}
|
|
104
105
|
/**
|
|
105
106
|
* Replaces existing waiters for a key and waits for its next trigger.
|
|
@@ -115,8 +116,8 @@ var EventAwaiter = class {
|
|
|
115
116
|
*
|
|
116
117
|
* @see {@link EventAwaiter.wait}
|
|
117
118
|
*/
|
|
118
|
-
waitLatest(key, timeoutMs, signal) {
|
|
119
|
-
return this.wait(key, timeoutMs, "override", signal);
|
|
119
|
+
async waitLatest(key, timeoutMs, signal) {
|
|
120
|
+
return await this.wait(key, timeoutMs, "override", signal);
|
|
120
121
|
}
|
|
121
122
|
};
|
|
122
123
|
export { EventAwaiter };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-awaiter.js","names":[],"sources":["../src/event-awaiter.ts"],"sourcesContent":["/**\n * An asynchronous keyed event rendezvous for one or more waiting consumers.\n *\n * @remarks\n * Triggers resolve the currently registered waiters; values are not retained for future waits.\n * Timeouts and subsequent abort events resolve affected waiters with `undefined`.\n * Use `triggerAll` to resolve pending waits during cleanup. Timers and abort listeners are not proactively\n * removed by triggers, so they may remain until their timeout or abort event occurs.\n *\n * @typeParam T - The value delivered to waiting consumers.\n */\nexport class EventAwaiter<T> {\n // Private instance properties\n #promiseResolvers = new Map<string, (
|
|
1
|
+
{"version":3,"file":"event-awaiter.js","names":[],"sources":["../src/event-awaiter.ts"],"sourcesContent":["/**\n * An asynchronous keyed event rendezvous for one or more waiting consumers.\n *\n * @remarks\n * Triggers resolve the currently registered waiters; values are not retained for future waits.\n * Timeouts and subsequent abort events resolve affected waiters with `undefined`.\n * Use `triggerAll` to resolve pending waits during cleanup. Timers and abort listeners are not proactively\n * removed by triggers, so they may remain until their timeout or abort event occurs.\n *\n * @typeParam T - The value delivered to waiting consumers.\n */\nexport class EventAwaiter<T> {\n // Private instance properties\n #promiseResolvers = new Map<string, Array<(value: PromiseLike<T | undefined> | T | undefined) => void>>();\n\n // Public instance methods\n\n /**\n * Resolves all currently pending waits for a key with the supplied value.\n *\n * @param key - The event identifier; a key without pending waits has no effect.\n * @param value - The delivered value; `undefined` indicates no result.\n */\n trigger(key: string, value: T | undefined) {\n const resolvers = this.#promiseResolvers.get(key);\n if (resolvers) {\n this.#promiseResolvers.delete(key);\n resolvers?.forEach((resolve) => resolve(value));\n }\n }\n\n /**\n * Resolves all currently pending waits and clears their registrations.\n *\n * @param value - The delivered value; omission resolves all pending waits with `undefined`.\n */\n triggerAll(value: T | undefined = undefined) {\n for (const [_, resolvers] of this.#promiseResolvers.entries()) resolvers.forEach((resolve) => resolve(value));\n this.#promiseResolvers.clear();\n }\n\n /**\n * Waits for a trigger associated with a key.\n *\n * @remarks\n * By default, multiple waiters share a key and all receive the next trigger value.\n * `strict` mode rejects duplicate waits; `override` mode resolves existing waits with `undefined` before\n * registering the new wait. Timeout and abort remove only the affected waiter's registration.\n * An already aborted signal is not checked; only an abort event emitted after registration ends the wait.\n * Without a timeout or subsequent abort, the wait remains pending until a trigger arrives.\n *\n * @param key - The event identifier to wait for.\n * @param timeoutMs - The optional timeout in milliseconds, using native `setTimeout` timing rules.\n * @param mode - The policy for existing waiters; omission allows multiple waiters.\n * @param signal - A signal whose subsequent abort event ends this wait.\n *\n * @returns A promise resolving to the triggered value, or `undefined` after timeout, abort, or replacement.\n *\n * @throws Error through promise rejection if `strict` mode encounters an existing waiter.\n */\n async wait(key: string, timeoutMs?: number, mode?: 'override' | 'strict', signal?: AbortSignal) {\n return await new Promise<T | undefined>((resolve) => {\n const resolvers = this.#promiseResolvers.get(key) || [];\n if (resolvers.length) {\n switch (mode) {\n case 'override':\n resolvers.forEach((r) => r(undefined));\n resolvers.length = 0;\n break;\n case 'strict':\n throw new Error(`Duplicate wait detected for key: ${key}`);\n case undefined:\n break;\n }\n }\n\n resolvers.push(resolve);\n this.#promiseResolvers.set(key, resolvers);\n if (timeoutMs != null) {\n setTimeout(\n () => {\n const resolvers = this.#promiseResolvers.get(key);\n if (resolvers?.includes(resolve)) {\n resolve(undefined);\n const newResolvers = resolvers.filter((r) => r !== resolve);\n if (newResolvers.length) this.#promiseResolvers.set(key, newResolvers);\n else this.#promiseResolvers.delete(key);\n }\n },\n timeoutMs,\n );\n }\n\n if (signal) {\n signal.addEventListener(\n 'abort',\n () => {\n const resolvers = this.#promiseResolvers.get(key);\n if (resolvers?.includes(resolve)) {\n resolve(undefined);\n const newResolvers = resolvers.filter((r) => r !== resolve);\n if (newResolvers.length) this.#promiseResolvers.set(key, newResolvers);\n else this.#promiseResolvers.delete(key);\n }\n },\n { once: true },\n );\n }\n });\n }\n\n /**\n * Waits for a key while rejecting duplicate registrations.\n *\n * @param key - The event identifier to wait for.\n * @param timeoutMs - The optional timeout in milliseconds.\n * @param signal - A signal whose subsequent abort event ends this wait; an already aborted signal is not checked.\n *\n * @returns A promise resolving to the triggered value, or `undefined` on timeout or subsequent abort.\n *\n * @throws Error through promise rejection if the key already has a pending waiter.\n *\n * @see {@link EventAwaiter.wait}\n */\n async waitExclusive(key: string, timeoutMs?: number, signal?: AbortSignal) {\n return await this.wait(key, timeoutMs, 'strict', signal);\n }\n\n /**\n * Replaces existing waiters for a key and waits for its next trigger.\n *\n * @remarks\n * Existing waiters resolve with `undefined` before the new waiter is registered.\n *\n * @param key - The event identifier to wait for.\n * @param timeoutMs - The optional timeout in milliseconds.\n * @param signal - A signal whose subsequent abort event ends this wait; an already aborted signal is not checked.\n *\n * @returns A promise resolving to the triggered value, or `undefined` on timeout, subsequent abort, or replacement.\n *\n * @see {@link EventAwaiter.wait}\n */\n async waitLatest(key: string, timeoutMs?: number, signal?: AbortSignal) {\n return await this.wait(key, timeoutMs, 'override', signal);\n }\n}\n"],"mappings":";;;;;;;;;;;;AAWA,IAAa,eAAb,MAA6B;CAEzB,oCAAoB,IAAI,IAAgF;;;;;;;CAUxG,QAAQ,KAAa,OAAsB;EACvC,MAAM,YAAY,KAAK,kBAAkB,IAAI,GAAG;EAChD,IAAI,WAAW;GACX,KAAK,kBAAkB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AO,GAAG;IAC1C;GACJ,GACA,EAAE,MAAM,KAAK,CACjB;EAER,CAAC;CACL;;;;;;;;;;;;;;CAeA,MAAM,cAAc,KAAa,WAAoB,QAAsB;EACvE,OAAO,MAAM,KAAK,KAAK,KAAK,WAAW,UAAU,MAAM;CAC3D;;;;;;;;;;;;;;;CAgBA,MAAM,WAAW,KAAa,WAAoB,QAAsB;EACpE,OAAO,MAAM,KAAK,KAAK,KAAK,WAAW,YAAY,MAAM;CAC7D;AACJ"}
|
package/dist/general.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Arrayable } from "type-fest";
|
|
1
2
|
/**
|
|
2
3
|
* Returns the first array element or the input value, with a nullish fallback.
|
|
3
4
|
*
|
|
@@ -29,6 +30,6 @@
|
|
|
29
30
|
* console.log(extractFirstValue(undefined, 'fallback')); // => 'fallback'
|
|
30
31
|
* ```
|
|
31
32
|
*/
|
|
32
|
-
export declare function extractFirstValue<T>(value: T
|
|
33
|
-
export declare function extractFirstValue<T, D>(value: T
|
|
33
|
+
export declare function extractFirstValue<T>(value: Arrayable<T>): T | undefined;
|
|
34
|
+
export declare function extractFirstValue<T, D>(value: Arrayable<T>, defaultValue: D): D | NonNullable<T>;
|
|
34
35
|
//# sourceMappingURL=general.d.ts.map
|