@kikiutils/shared 20.0.0 → 20.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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.map +1 -1
- package/dist/enum.d.ts +3 -3
- package/dist/enum.d.ts.map +1 -1
- package/dist/enum.js.map +1 -1
- package/dist/event-awaiter.d.ts.map +1 -1
- package/dist/event-awaiter.js +1 -0
- package/dist/event-awaiter.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 +3 -1
- package/dist/logger/_internals/logger.js.map +1 -1
- package/dist/logger/index.js +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 +6 -2
- 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 +4 -2
- 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/types/filtered-key-path.d.ts +2 -2
- package/dist/types/filtered-key-path.d.ts.map +1 -1
- package/dist/types/filtered-key-path.js +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/vue.js +1 -0
- package/dist/url.d.ts.map +1 -1
- package/dist/url.js.map +1 -1
- package/package.json +44 -70
- package/src/buffer.ts +0 -1
- package/src/classes/enhanced-date.ts +2 -2
- package/src/classes/path.ts +1 -1
- package/src/enum.ts +3 -3
- package/src/event-awaiter.ts +3 -1
- package/src/logger/_internals/formatter.ts +12 -4
- package/src/logger/_internals/logger.ts +6 -2
- package/src/logger/node/_internals/file-writer.ts +6 -2
- package/src/logger/node/_internals/formatter.ts +3 -1
- package/src/logger/node/index.ts +4 -1
- 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/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,QAAQ,QAAQ,OAC/B,UAAU,QAAQ,eAAY;;;;;;;;;SAa3B,QAAQ,eAAe,UAAU,QAAQ,kBAAe;;;;;;SASxD,gBAAgB,kBAAe;;;;;;;;SAW/B,IAAI,
|
|
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;;;;;;;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,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,aAAa,QAAQ,aAAa,CAAC;CAClD;;;;CAKA,OAAO,kBAAkB;EACrB,OAAO,IAAI,aAAa,QAAQ,gBAAgB,CAAC;CACrD;;;;CAKA,OAAO,mBAAmB;EACtB,OAAO,IAAI,aAAa,QAAQ,iBAAiB,CAAC;CACtD;;;;;;;;CAWA,QAAQ,QAAgB;EACpB,KAAK,QAAQ,QAAQ,QAAQ,MAAM,MAAM,CAAC,CAAC,QAAQ,CAAC;EACpD,OAAO;CACX;;;;;;;;CASA,SAAS,QAAgB;EACrB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,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":";;;;;;;;;;;;;;;;;;;;;;;;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2BAA2B,IAAI,YAAS;;;;;;;;;EAY1D,UAAM;;;;;;;;;EAYN,aAAa,MAAM,2BAA2B,IAAI,aAAU"}
|
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,SAA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AI,SAAS,KAAK,QAAQ,GAAG,IAAI;CAC5C;CAmBA,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 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<Array<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;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;;;;;;;;C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;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"}
|
package/dist/enum.d.ts
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* console.log(getEnumNumberValues(RecordType)); // => [0, 1]
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
-
export declare function getEnumNumberValues<T extends Record<string, any>>(enumObject: T): Extract<T[keyof T], number
|
|
25
|
+
export declare function getEnumNumberValues<T extends Record<string, any>>(enumObject: T): Array<Extract<T[keyof T], number>>;
|
|
26
26
|
/**
|
|
27
27
|
* Extracts only the string values from an enumeration-like object.
|
|
28
28
|
*
|
|
@@ -47,7 +47,7 @@ export declare function getEnumNumberValues<T extends Record<string, any>>(enumO
|
|
|
47
47
|
* console.log(getEnumStringValues(RecordType)); // => ['unknown']
|
|
48
48
|
* ```
|
|
49
49
|
*/
|
|
50
|
-
export declare function getEnumStringValues<T extends Record<string, any>>(enumObject: T): Extract<T[keyof T], string
|
|
50
|
+
export declare function getEnumStringValues<T extends Record<string, any>>(enumObject: T): Array<Extract<T[keyof T], string>>;
|
|
51
51
|
/**
|
|
52
52
|
* Extracts all values from an enumeration-like object.
|
|
53
53
|
*
|
|
@@ -96,5 +96,5 @@ export declare function getEnumStringValues<T extends Record<string, any>>(enumO
|
|
|
96
96
|
* console.log(getEnumValues(RecordType)); // => [0, 1, 'unknown']
|
|
97
97
|
* ```
|
|
98
98
|
*/
|
|
99
|
-
export declare function getEnumValues<T extends Record<string, any>>(enumObject: T):
|
|
99
|
+
export declare function getEnumValues<T extends Record<string, any>>(enumObject: T): Array<T[keyof T]>;
|
|
100
100
|
//# 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":";;;;;;;;;;;;;;;;;;;;;;;;wBAwBgB,oBAAoB,UAAU,qBAAqB,YAAY,IAAI,QAAQ,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"enum.d.ts","names":[],"sources":["../src/enum.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;wBAwBgB,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.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[keyof T], number
|
|
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): Array<Extract<T[keyof 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<T[keyof 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<T[keyof T]> {\n const values = Object.values(enumObject);\n const hasNumberValues = values.some((value) => typeof value === 'number');\n if (!hasNumberValues) return values;\n return Object.keys(enumObject).filter((key) => Number.isNaN(Number(key))).map((key) => enumObject[key]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,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,OAAO,OAAO,UAAU;CAEvC,IAAI,CADoB,OAAO,MAAM,UAAU,OAAO,UAAU,QAC7C,GAAG,OAAO;CAC7B,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,QAAQ,QAAQ,OAAO,MAAM,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,QAAQ,WAAW,IAAI;AAC1G"}
|
|
@@ -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;;;;;;;;;;;;;;;;;;;;EAwBlB,KAAK,aAAa,oBAAoB,8BAA8B,SAAS,cAAW,QAAA;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"event-awaiter.d.ts","names":[],"sources":["../src/event-awaiter.ts"],"mappings":";;;;;;;;;;;qBAWa,aAAa;;;;;;;;EAYtB,QAAQ,aAAa,OAAO;;;;;;EAa5B,WAAW,QAAO;;;;;;;;;;;;;;;;;;;;EAwBlB,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
|
@@ -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 wait(key: string, timeoutMs?: number, mode?: 'override' | 'strict', signal?: AbortSignal) {\n return 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 waitExclusive(key: string, timeoutMs?: number, signal?: AbortSignal) {\n return 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 waitLatest(key: string, timeoutMs?: number, signal?: AbortSignal) {\n return 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,OAAO,GAAG;GACjC,WAAW,SAAS,YAAY,QAAQ,KAAK,CAAC;EAClD;CACJ;;;;;;CAOA,WAAW,QAAuB,KAAA,GAAW;EACzC,KAAK,MAAM,CAAC,GAAG,cAAc,KAAK,kBAAkB,QAAQ,GAAG,UAAU,SAAS,YAAY,QAAQ,KAAK,CAAC;EAC5G,KAAK,kBAAkB,MAAM;CACjC;;;;;;;;;;;;;;;;;;;;CAqBA,KAAK,KAAa,WAAoB,MAA8B,QAAsB;EACtF,OAAO,IAAI,SAAwB,YAAY;GAC3C,MAAM,YAAY,KAAK,kBAAkB,IAAI,GAAG,KAAK,CAAC;GACtD,IAAI,UAAU,QACV,QAAQ,MAAR;IACI,KAAK;KACD,UAAU,SAAS,MAAM,EAAE,KAAA,CAAS,CAAC;KACrC,UAAU,SAAS;KACnB;IACJ,KAAK,UACD,MAAM,IAAI,MAAM,oCAAoC,KAAK;IAC7D,KAAK,KAAA;GAET;GAGJ,UAAU,KAAK,OAAO;GACtB,KAAK,kBAAkB,IAAI,KAAK,SAAS;GACzC,IAAI,aAAa,MACb,iBACU;IACF,MAAM,YAAY,KAAK,kBAAkB,IAAI,GAAG;IAChD,IAAI,WAAW,SAAS,OAAO,GAAG;KAC9B,QAAQ,KAAA,CAAS;KACjB,MAAM,eAAe,UAAU,QAAQ,MAAM,MAAM,OAAO;KAC1D,IAAI,aAAa,QAAQ,KAAK,kBAAkB,IAAI,KAAK,YAAY;UAChE,KAAK,kBAAkB,OAAO,GAAG;IAC1C;GACJ,GACA,SACJ;GAGJ,IAAI,QACA,OAAO,iBACH,eACM;IACF,MAAM,YAAY,KAAK,kBAAkB,IAAI,GAAG;IAChD,IAAI,WAAW,SAAS,OAAO,GAAG;KAC9B,QAAQ,KAAA,CAAS;KACjB,MAAM,eAAe,UAAU,QAAQ,MAAM,MAAM,OAAO;KAC1D,IAAI,aAAa,QAAQ,KAAK,kBAAkB,IAAI,KAAK,YAAY;UAChE,KAAK,kBAAkB,OAAO,GAAG;IAC1C;GACJ,GACA,EAAE,MAAM,KAAK,CACjB;EAER,CAAC;CACL;;;;;;;;;;;;;;CAeA,cAAc,KAAa,WAAoB,QAAsB;EACjE,OAAO,KAAK,KAAK,KAAK,WAAW,UAAU,MAAM;CACrD;;;;;;;;;;;;;;;CAgBA,WAAW,KAAa,WAAoB,QAAsB;EAC9D,OAAO,KAAK,KAAK,KAAK,WAAW,YAAY,MAAM;CACvD;AACJ"}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { LoggerRecord } from "./types.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Native console formatting keeps user strings literal and objects expandable.
|
|
4
|
+
*/
|
|
3
5
|
export declare function formatLoggerConsoleArgs(record: LoggerRecord): unknown[];
|
|
4
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Keeps data arguments intact so browser developer tools can expand objects.
|
|
8
|
+
*/
|
|
5
9
|
export declare function formatLoggerParts(record: LoggerRecord, colors?: boolean): unknown[];
|
|
6
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Fixed local-time representation, deliberately without a per-second cache.
|
|
12
|
+
*/
|
|
7
13
|
export declare function formatLoggerTime(date: Date): string;
|
|
8
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Use native terminal detection; redirected streams still honor FORCE_COLOR.
|
|
16
|
+
*/
|
|
9
17
|
export declare function supportsLoggerColor(target: {
|
|
10
18
|
hasColors?: () => boolean;
|
|
11
19
|
isTTY?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","names":[],"sources":["../../../src/logger/_internals/formatter.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","names":[],"sources":["../../../src/logger/_internals/formatter.ts"],"mappings":";;;;wBAWgB,wBAAwB,QAAQ;;;;wBAmChC,kBAAkB,QAAQ,cAAc;;;;wBAcxC,iBAAiB,MAAM;;;;wBAUvB,oBAAoB;EAAU;EAA2B"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { getLoggerStreamName, loggerMethods } from "./levels.js";
|
|
2
2
|
// src/logger/_internals/formatter.ts
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Native console formatting keeps user strings literal and objects expandable.
|
|
5
|
+
*/
|
|
4
6
|
function formatLoggerConsoleArgs(record) {
|
|
5
7
|
if (typeof process !== "undefined" && process.versions?.node) {
|
|
6
8
|
const target = process[getLoggerStreamName(record.type)];
|
|
@@ -23,7 +25,9 @@ function formatLoggerConsoleArgs(record) {
|
|
|
23
25
|
if (record.suffix) decorate(record.suffix, "#0891b2");
|
|
24
26
|
return [format.join(" "), ...args];
|
|
25
27
|
}
|
|
26
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Keeps data arguments intact so browser developer tools can expand objects.
|
|
30
|
+
*/
|
|
27
31
|
function formatLoggerParts(record, colors = false) {
|
|
28
32
|
const parts = [];
|
|
29
33
|
const paint = (text, color) => colors ? `\u001B[${color}m${text}\u001B[0m` : text;
|
|
@@ -34,12 +38,16 @@ function formatLoggerParts(record, colors = false) {
|
|
|
34
38
|
if (record.suffix) parts.push(paint(record.suffix, "36"));
|
|
35
39
|
return parts;
|
|
36
40
|
}
|
|
37
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* Fixed local-time representation, deliberately without a per-second cache.
|
|
43
|
+
*/
|
|
38
44
|
function formatLoggerTime(date) {
|
|
39
45
|
const pad = (value, width = 2) => String(value).padStart(width, "0");
|
|
40
46
|
return `[${`${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`} ${`${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`}.${pad(date.getMilliseconds(), 3)}]`;
|
|
41
47
|
}
|
|
42
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Use native terminal detection; redirected streams still honor FORCE_COLOR.
|
|
50
|
+
*/
|
|
43
51
|
function supportsLoggerColor(target) {
|
|
44
52
|
if (target.hasColors) return target.hasColors();
|
|
45
53
|
const forced = process.env.FORCE_COLOR;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.js","names":[],"sources":["../../../src/logger/_internals/formatter.ts"],"sourcesContent":["import {\n getLoggerStreamName,\n loggerMethods,\n} from './levels';\nimport type { LoggerRecord } from './types';\n\n// Functions\n\n
|
|
1
|
+
{"version":3,"file":"formatter.js","names":[],"sources":["../../../src/logger/_internals/formatter.ts"],"sourcesContent":["import {\n getLoggerStreamName,\n loggerMethods,\n} from './levels';\nimport type { LoggerRecord } from './types';\n\n// Functions\n\n/**\n * Native console formatting keeps user strings literal and objects expandable.\n */\nexport function formatLoggerConsoleArgs(record: LoggerRecord): unknown[] {\n if (typeof process !== 'undefined' && process.versions?.node) {\n const target = process[getLoggerStreamName(record.type)];\n const parts = formatLoggerParts(record, supportsLoggerColor(target));\n return [\n parts.map((part) => typeof part === 'string' ? '%s' : '%O').join(' '),\n ...parts,\n ];\n }\n\n const format: string[] = [];\n const args: unknown[] = [];\n const decorate = (text: string, color: string) => {\n format.push('%c%s%c');\n args.push(`color: ${color}`, text, '');\n };\n\n if (record.icons) decorate(loggerMethods[record.type].icon, loggerMethods[record.type].cssColor);\n if (record.timestamp) decorate(formatLoggerTime(record.date), '#808080');\n if (record.prefix) decorate(record.prefix, '#0891b2');\n for (const arg of record.args) {\n format.push(typeof arg === 'string' ? '%s' : '%o');\n args.push(arg);\n }\n\n if (record.suffix) decorate(record.suffix, '#0891b2');\n return [\n format.join(' '),\n ...args,\n ];\n}\n\n/**\n * Keeps data arguments intact so browser developer tools can expand objects.\n */\nexport function formatLoggerParts(record: LoggerRecord, colors = false): unknown[] {\n const parts: unknown[] = [];\n const paint = (text: string, color: string) => colors ? `\\u001B[${color}m${text}\\u001B[0m` : text;\n if (record.icons) parts.push(paint(loggerMethods[record.type].icon, loggerMethods[record.type].ansiColor));\n if (record.timestamp) parts.push(paint(formatLoggerTime(record.date), '90'));\n if (record.prefix) parts.push(paint(record.prefix, '36'));\n parts.push(...record.args);\n if (record.suffix) parts.push(paint(record.suffix, '36'));\n return parts;\n}\n\n/**\n * Fixed local-time representation, deliberately without a per-second cache.\n */\nexport function formatLoggerTime(date: Date): string {\n const pad = (value: number, width = 2) => String(value).padStart(width, '0');\n const day = `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;\n const time = `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;\n return `[${day} ${time}.${pad(date.getMilliseconds(), 3)}]`;\n}\n\n/**\n * Use native terminal detection; redirected streams still honor FORCE_COLOR.\n */\nexport function supportsLoggerColor(target: { hasColors?: () => boolean; isTTY?: boolean }): boolean {\n if (target.hasColors) return target.hasColors();\n const forced = process.env.FORCE_COLOR;\n if (forced !== undefined) {\n return [\n '',\n '1',\n '2',\n '3',\n 'true',\n ].includes(forced);\n }\n\n return Boolean(target.isTTY)\n && !process.env.NO_COLOR\n && !process.env.NODE_DISABLE_COLORS\n && process.env.TERM !== 'dumb';\n}\n"],"mappings":";;;;;AAWA,SAAgB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AAK,MAAM,OAAO,QAAQ,IAAI,CAAC;CACxD,MAAM,KAAK,GAAG,OAAO,IAAI;CACzB,IAAI,OAAO,QAAQ,MAAM,KAAK,MAAM,OAAO,QAAQ,IAAI,CAAC;CACxD,OAAO;AACX;;;;AAKA,SAAgB,iBAAiB,MAAoB;CACjD,MAAM,OAAO,OAAe,QAAQ,MAAM,OAAO,KAAK,CAAC,CAAC,SAAS,OAAO,GAAG;CAG3E,OAAO,IAAI,GAFI,KAAK,YAAY,EAAE,GAAG,IAAI,KAAK,SAAS,IAAI,CAAC,EAAE,GAAG,IAAI,KAAK,QAAQ,CAAC,IAEpE,GAAG,GADF,IAAI,KAAK,SAAS,CAAC,EAAE,GAAG,IAAI,KAAK,WAAW,CAAC,EAAE,GAAG,IAAI,KAAK,WAAW,CAAC,IAChE,GAAG,IAAI,KAAK,gBAAgB,GAAG,CAAC,EAAE;AAC7D;;;;AAKA,SAAgB,oBAAoB,QAAiE;CACjG,IAAI,OAAO,WAAW,OAAO,OAAO,UAAU;CAC9C,MAAM,SAAS,QAAQ,IAAI;CAC3B,IAAI,WAAW,KAAA,GACX,OAAO;EACH;EACA;EACA;EACA;EACA;CACJ,CAAC,CAAC,SAAS,MAAM;CAGrB,OAAO,QAAQ,OAAO,KAAK,KACtB,CAAC,QAAQ,IAAI,YACb,CAAC,QAAQ,IAAI,uBACb,QAAQ,IAAI,SAAS;AAC9B"}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { Logger, LoggerDiagnostic, LoggerOptions } from "../types.js";
|
|
2
2
|
import { LoggerRecord } from "./types.js";
|
|
3
3
|
interface LoggerHooks {
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* A non-throwing reporter created by createDiagnosticReporter.
|
|
6
|
+
*/
|
|
5
7
|
report: (event: LoggerDiagnostic) => void;
|
|
6
8
|
write: (record: LoggerRecord) => Promise<void> | void;
|
|
7
9
|
}
|
|
8
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* A non-recursive, rate-limited diagnostic boundary shared by server and browser adapters.
|
|
12
|
+
*/
|
|
9
13
|
export declare function createDiagnosticReporter(onError?: (event: Readonly<LoggerDiagnostic>) => void, fallback?: (message: string) => void): (event: LoggerDiagnostic) => void;
|
|
10
14
|
export declare function createLoggerCore(options: LoggerOptions, hooks: LoggerHooks): Readonly<Logger>;
|
|
11
15
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","names":[],"sources":["../../../src/logger/_internals/logger.ts"],"mappings":";;UAWU
|
|
1
|
+
{"version":3,"file":"logger.d.ts","names":[],"sources":["../../../src/logger/_internals/logger.ts"],"mappings":";;UAWU;;;;EAIN,SAAS,OAAO;EAChB,QAAQ,QAAQ,iBAAiB;;;;;wBAoBrB,yBACZ,WAAW,OAAO,SAAS,4BAC3B,YAAY,4BACZ,OAAO;wBAkEK,iBAAiB,SAAS,eAAe,OAAO,cAAc,SAAS"}
|
|
@@ -6,7 +6,9 @@ const booleanPresentationKeys = [
|
|
|
6
6
|
"timestamp"
|
|
7
7
|
];
|
|
8
8
|
const stringPresentationKeys = ["prefix", "suffix"];
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* A non-recursive, rate-limited diagnostic boundary shared by server and browser adapters.
|
|
11
|
+
*/
|
|
10
12
|
function createDiagnosticReporter(onError, fallback) {
|
|
11
13
|
let reporting = false;
|
|
12
14
|
let callbackPending = false;
|