temporal-fmt 0.8.2 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ export declare function isGregorianLeapYear(year: number): boolean;
2
+ export declare function dayOfYear(year: number, month: number, day: number): number;
3
+ export interface IsoWeekDate {
4
+ isoYear: number;
5
+ week: number;
6
+ }
7
+ export declare function isoWeekYearAndWeek(year: number, month: number, day: number, dayOfWeek: number): IsoWeekDate;
@@ -5,5 +5,32 @@ export interface LocaleVocab {
5
5
  weekdayShort: string[];
6
6
  dayPeriod: string[];
7
7
  }
8
+ /**
9
+ * Supply a custom month/weekday/day-period vocabulary for a locale key,
10
+ * overriding the Intl-derived vocab this library would otherwise build
11
+ * for that key. Useful for locales Intl doesn't cover well — the README's
12
+ * known-limitations section calls out the Hebrew leap-month gap as a
13
+ * specific case this addresses.
14
+ *
15
+ * Throws descriptively on malformed input (wrong array lengths, empty
16
+ * strings, duplicate entries, missing fields) rather than failing later
17
+ * during format/parse.
18
+ *
19
+ * Registered vocab takes precedence over the Intl-derived vocab for that
20
+ * locale key, including for already-cached entries — registering
21
+ * invalidates the prior cache entry for that locale so the next call
22
+ * picks up the new vocab.
23
+ *
24
+ * @example
25
+ * registerLocaleVocab('en-u-ca-hebrew-leap', {
26
+ * monthLong: ['Nisan','Iyar','Sivan','Tammuz','Av','Elul','Tishrei','Marcheshvan','Kislev','Tevet','Shevat','Adar I','Adar II'],
27
+ * monthShort: ['Nis','Iyy','Siv','Tam','Av','Elu','Tish','Chesh','Kis','Tev','Shv','Ad1','Ad2'],
28
+ * weekdayLong: ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'],
29
+ * weekdayShort: ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'],
30
+ * dayPeriod: ['AM','PM'],
31
+ * });
32
+ */
33
+ export declare function registerLocaleVocab(locale: string, vocab: Partial<LocaleVocab>): void;
8
34
  export declare function canonicalCacheKey(locale: string): string;
35
+ export declare function getCustomVocab(locale: string): LocaleVocab | undefined;
9
36
  export declare function getLocaleVocab(locale: string): LocaleVocab;
@@ -5,5 +5,32 @@ export interface LocaleVocab {
5
5
  weekdayShort: string[];
6
6
  dayPeriod: string[];
7
7
  }
8
+ /**
9
+ * Supply a custom month/weekday/day-period vocabulary for a locale key,
10
+ * overriding the Intl-derived vocab this library would otherwise build
11
+ * for that key. Useful for locales Intl doesn't cover well — the README's
12
+ * known-limitations section calls out the Hebrew leap-month gap as a
13
+ * specific case this addresses.
14
+ *
15
+ * Throws descriptively on malformed input (wrong array lengths, empty
16
+ * strings, duplicate entries, missing fields) rather than failing later
17
+ * during format/parse.
18
+ *
19
+ * Registered vocab takes precedence over the Intl-derived vocab for that
20
+ * locale key, including for already-cached entries — registering
21
+ * invalidates the prior cache entry for that locale so the next call
22
+ * picks up the new vocab.
23
+ *
24
+ * @example
25
+ * registerLocaleVocab('en-u-ca-hebrew-leap', {
26
+ * monthLong: ['Nisan','Iyar','Sivan','Tammuz','Av','Elul','Tishrei','Marcheshvan','Kislev','Tevet','Shevat','Adar I','Adar II'],
27
+ * monthShort: ['Nis','Iyy','Siv','Tam','Av','Elu','Tish','Chesh','Kis','Tev','Shv','Ad1','Ad2'],
28
+ * weekdayLong: ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'],
29
+ * weekdayShort: ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'],
30
+ * dayPeriod: ['AM','PM'],
31
+ * });
32
+ */
33
+ export declare function registerLocaleVocab(locale: string, vocab: Partial<LocaleVocab>): void;
8
34
  export declare function canonicalCacheKey(locale: string): string;
35
+ export declare function getCustomVocab(locale: string): LocaleVocab | undefined;
9
36
  export declare function getLocaleVocab(locale: string): LocaleVocab;
@@ -0,0 +1,25 @@
1
+ import { type FormatOptions } from './tokens.cjs';
2
+ export interface ParseRelativeOptions extends FormatOptions {
3
+ }
4
+ /**
5
+ * Resolve common English relative-date phrases against a reference date,
6
+ * returning a Temporal.PlainDate. Supported phrases (English only):
7
+ *
8
+ * - weekday refs: "next Tuesday", "last Friday", "this Monday"
9
+ * - day offsets: "today", "tomorrow", "yesterday"
10
+ * - unit offsets: "in 3 days", "2 weeks ago", "in 1 month", "1 year ago"
11
+ * - month-day without year: "March 5th" (resolved to next occurrence)
12
+ *
13
+ * For ambiguous "next Tuesday"-on-a-Tuesday — i.e. today is the named
14
+ * weekday — "next Tuesday" means 7 days from now (strictly future), not
15
+ * today. See README "parseRelative" for the documented behavior of each
16
+ * ambiguous case.
17
+ *
18
+ * Returns a Temporal.PlainDate for every supported phrase. (Time-of-day
19
+ * extensions like "next Tuesday at 3pm" aren't supported in this pass —
20
+ * the return type is always PlainDate.)
21
+ *
22
+ * Throws a descriptive error for any phrase it doesn't recognize, rather
23
+ * than guessing.
24
+ */
25
+ export declare function parseRelative(input: string, referenceDate: unknown, options?: ParseRelativeOptions): unknown;
@@ -0,0 +1,25 @@
1
+ import { type FormatOptions } from './tokens.js';
2
+ export interface ParseRelativeOptions extends FormatOptions {
3
+ }
4
+ /**
5
+ * Resolve common English relative-date phrases against a reference date,
6
+ * returning a Temporal.PlainDate. Supported phrases (English only):
7
+ *
8
+ * - weekday refs: "next Tuesday", "last Friday", "this Monday"
9
+ * - day offsets: "today", "tomorrow", "yesterday"
10
+ * - unit offsets: "in 3 days", "2 weeks ago", "in 1 month", "1 year ago"
11
+ * - month-day without year: "March 5th" (resolved to next occurrence)
12
+ *
13
+ * For ambiguous "next Tuesday"-on-a-Tuesday — i.e. today is the named
14
+ * weekday — "next Tuesday" means 7 days from now (strictly future), not
15
+ * today. See README "parseRelative" for the documented behavior of each
16
+ * ambiguous case.
17
+ *
18
+ * Returns a Temporal.PlainDate for every supported phrase. (Time-of-day
19
+ * extensions like "next Tuesday at 3pm" aren't supported in this pass —
20
+ * the return type is always PlainDate.)
21
+ *
22
+ * Throws a descriptive error for any phrase it doesn't recognize, rather
23
+ * than guessing.
24
+ */
25
+ export declare function parseRelative(input: string, referenceDate: unknown, options?: ParseRelativeOptions): unknown;
@@ -2,6 +2,7 @@ interface TemporalFactory {
2
2
  from(fields: Record<string, number | string | undefined>, options?: {
3
3
  overflow?: 'constrain' | 'reject';
4
4
  }): unknown;
5
+ compare?(one: unknown, two: unknown): number;
5
6
  }
6
7
  export interface TemporalNamespace {
7
8
  PlainDate: TemporalFactory;
@@ -2,6 +2,7 @@ interface TemporalFactory {
2
2
  from(fields: Record<string, number | string | undefined>, options?: {
3
3
  overflow?: 'constrain' | 'reject';
4
4
  }): unknown;
5
+ compare?(one: unknown, two: unknown): number;
5
6
  }
6
7
  export interface TemporalNamespace {
7
8
  PlainDate: TemporalFactory;
package/dist/tokens.d.cts CHANGED
@@ -16,6 +16,13 @@ export interface TemporalLike {
16
16
  export interface FormatOptions {
17
17
  /** BCP 47 locale tag, e.g. 'en-US', 'fr-FR', 'ar-EG'. Defaults to 'en-US'. */
18
18
  locale?: string;
19
+ /**
20
+ * When set on parse(), opts into the lenient split heuristic for ambiguous
21
+ * glued numeric runs (e.g. "121" against "Md"). Default (false) keeps
22
+ * parse()'s strict behavior — throw on ambiguity rather than guess.
23
+ * See README "Lenient parse mode" for the heuristic and why it's opt-in.
24
+ */
25
+ lenient?: boolean;
19
26
  }
20
27
  export declare const DEFAULT_LOCALE = "en-US";
21
28
  type TokenHandler = (t: TemporalLike, locale: string) => string;
package/dist/tokens.d.ts CHANGED
@@ -16,6 +16,13 @@ export interface TemporalLike {
16
16
  export interface FormatOptions {
17
17
  /** BCP 47 locale tag, e.g. 'en-US', 'fr-FR', 'ar-EG'. Defaults to 'en-US'. */
18
18
  locale?: string;
19
+ /**
20
+ * When set on parse(), opts into the lenient split heuristic for ambiguous
21
+ * glued numeric runs (e.g. "121" against "Md"). Default (false) keeps
22
+ * parse()'s strict behavior — throw on ambiguity rather than guess.
23
+ * See README "Lenient parse mode" for the heuristic and why it's opt-in.
24
+ */
25
+ lenient?: boolean;
19
26
  }
20
27
  export declare const DEFAULT_LOCALE = "en-US";
21
28
  type TokenHandler = (t: TemporalLike, locale: string) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "temporal-fmt",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "description": "Format Temporal.PlainDate/PlainDateTime/PlainTime/ZonedDateTime objects using date-fns-style token strings.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -25,12 +25,13 @@
25
25
  "scripts": {
26
26
  "build": "tsup && tsc --declaration --emitDeclarationOnly && node scripts/emit-cjs-types.mjs",
27
27
  "dev": "tsup --watch",
28
- "test": "node --test test/*.test.js test/*.test.cjs",
28
+ "test": "node scripts/run-tests.mjs",
29
29
  "test:unit": "vitest run",
30
30
  "test:unit:watch": "vitest",
31
+ "test:coverage": "c8 --include=\"dist/index.js\" --include=\"dist/index.cjs\" --check-coverage --lines 90 --branches 75 --functions 88 -r text node scripts/run-tests.mjs",
31
32
  "test:types": "vitest run --typecheck",
32
- "test:pack": "attw --pack .",
33
- "test:all": "npm run build && npm test && npm run test:unit && npm run test:types && npm run test:pack",
33
+ "test:pack": "attw --pack . && publint .",
34
+ "test:all": "npm run build && npm test && npm run test:coverage && npm run test:unit && npm run test:types && npm run test:pack",
34
35
  "prepublishOnly": "npm run build && npm test"
35
36
  },
36
37
  "keywords": [
@@ -55,10 +56,12 @@
55
56
  "homepage": "https://github.com/DirazCoder/temporal-fmt#readme",
56
57
  "devDependencies": {
57
58
  "@arethetypeswrong/cli": "^0.18.5",
59
+ "c8": "^12.0.0",
60
+ "publint": "^0.3.23",
58
61
  "temporal-polyfill": "^1.0.4",
59
62
  "tsup": "^8.5.1",
60
63
  "typescript": "^7.0.2",
61
- "vitest": "^4.1.10"
64
+ "vitest": "^4.1.11"
62
65
  },
63
66
  "overrides": {
64
67
  "esbuild": "0.28.1"