@sanity/util 5.0.0-next.0-9b570ece82-202507150640 → 5.0.0-next.7

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.
Files changed (41) hide show
  1. package/LICENSE +1 -1
  2. package/lib/client.js +9 -8
  3. package/lib/client.js.map +1 -1
  4. package/lib/concurrency-limiter.js +3 -3
  5. package/lib/concurrency-limiter.js.map +1 -1
  6. package/lib/content.js +11 -15
  7. package/lib/content.js.map +1 -1
  8. package/lib/{createSafeJsonParser.mjs → createSafeJsonParser.cjs} +5 -5
  9. package/lib/{createSafeJsonParser.mjs.map → createSafeJsonParser.cjs.map} +1 -1
  10. package/lib/createSafeJsonParser.js +4 -4
  11. package/lib/createSafeJsonParser.js.map +1 -1
  12. package/lib/fs.js +13 -15
  13. package/lib/fs.js.map +1 -1
  14. package/lib/index.js +1 -1
  15. package/lib/legacyDateFormat.js +160 -78
  16. package/lib/legacyDateFormat.js.map +1 -1
  17. package/lib/paths.js +25 -25
  18. package/lib/paths.js.map +1 -1
  19. package/package.json +18 -30
  20. package/lib/client.d.mts +0 -12
  21. package/lib/client.mjs +0 -64
  22. package/lib/client.mjs.map +0 -1
  23. package/lib/concurrency-limiter.d.mts +0 -22
  24. package/lib/concurrency-limiter.mjs +0 -32
  25. package/lib/concurrency-limiter.mjs.map +0 -1
  26. package/lib/content.d.mts +0 -39
  27. package/lib/content.mjs +0 -89
  28. package/lib/content.mjs.map +0 -1
  29. package/lib/fs.d.mts +0 -7
  30. package/lib/fs.mjs +0 -31
  31. package/lib/fs.mjs.map +0 -1
  32. package/lib/index.d.mts +0 -1
  33. package/lib/index.mjs +0 -2
  34. package/lib/index.mjs.map +0 -1
  35. package/lib/legacyDateFormat.d.mts +0 -39
  36. package/lib/legacyDateFormat.mjs +0 -213
  37. package/lib/legacyDateFormat.mjs.map +0 -1
  38. package/lib/paths.d.mts +0 -53
  39. package/lib/paths.mjs +0 -153
  40. package/lib/paths.mjs.map +0 -1
  41. /package/lib/{createSafeJsonParser.d.mts → createSafeJsonParser.d.cts} +0 -0
@@ -1,6 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var tz = require("@date-fns/tz"), utc = require("@date-fns/utc"), dateFns = require("date-fns");
1
+ import { TZDateMini } from "@date-fns/tz";
2
+ import { UTCDateMini } from "@date-fns/utc";
3
+ import { format as format$1, parse as parse$1, parseISO } from "date-fns";
4
4
  const sanitizeLocale = (locale) => locale.replace(/@posix$/, "");
5
5
  function getMonthName(date, style = "long", locale = "en-US") {
6
6
  const validLocale = sanitizeLocale(locale);
@@ -10,6 +10,10 @@ function getDayName(date, style = "long", locale = "en-US") {
10
10
  const validLocale = sanitizeLocale(locale);
11
11
  return new Intl.DateTimeFormat(validLocale, { weekday: style }).format(date);
12
12
  }
13
+ function getLocalizedDate(date, options, locale = "en-US") {
14
+ const validLocale = sanitizeLocale(locale);
15
+ return new Intl.DateTimeFormat(validLocale, options).format(date);
16
+ }
13
17
  function zeroPad(num, length) {
14
18
  return String(num).padStart(length, "0");
15
19
  }
@@ -43,124 +47,187 @@ function getFractionalSeconds(date, length) {
43
47
  return length === 1 ? ms.slice(0, 1) : length === 2 ? ms.slice(0, 2) : length === 3 ? ms : `${ms}0`;
44
48
  }
45
49
  function getTimeZoneAbbreviation(date) {
46
- const tz2 = new Intl.DateTimeFormat(sanitizeLocale("en-US"), {
50
+ const tz = new Intl.DateTimeFormat(sanitizeLocale("en-US"), {
47
51
  timeZoneName: "short"
48
52
  }).formatToParts(date).find((part) => part.type === "timeZoneName");
49
- return tz2 ? tz2.value : "";
53
+ return tz ? tz.value : "";
50
54
  }
51
55
  function formatMomentLike(date, formatStr) {
52
- const escapeSequences = [], escapeToken = "\uE000", processedFormat = formatStr.replace(/\[([^\]]+)\]/g, (_, contents) => (escapeSequences.push(contents), escapeToken)), year = date.getFullYear(), monthIndex = date.getMonth(), dayOfMonth = date.getDate(), dayOfWeek = date.getDay(), hours = date.getHours(), minutes = date.getMinutes(), seconds = date.getSeconds(), isoWeekNum = getISOWeekNumber(date), isoWeekYear = getISOWeekYear(date), localeWeekYear = getLocaleWeekYear(date), unixMs = date.getTime(), unixSec = Math.floor(unixMs / 1e3), tokens = [
56
+ const escapeSequences = [], processedFormat = formatStr.replace(/\[([^\]]+)\]/g, (_, contents) => (escapeSequences.push(contents), "\uE000")), year = date.getFullYear(), monthIndex = date.getMonth(), dayOfMonth = date.getDate(), dayOfWeek = date.getDay(), hours = date.getHours(), minutes = date.getMinutes(), seconds = date.getSeconds(), isoWeekNum = getISOWeekNumber(date), isoWeekYear = getISOWeekYear(date), localeWeekYear = getLocaleWeekYear(date), unixMs = date.getTime(), unixSec = Math.floor(unixMs / 1e3), tokens = [
53
57
  // Year
54
58
  // 1970 1971 ... 2029 2030
55
- { key: "YYYY", value: String(year) },
59
+ { key: "YYYY", getValue: () => String(year) },
56
60
  // 70 71 ... 29 30
57
- { key: "YY", value: String(year).slice(-2) },
61
+ { key: "YY", getValue: () => String(year).slice(-2) },
58
62
  // 1970 1971 ... 9999 +10000 +10001
59
- { key: "Y", value: String(year) },
63
+ { key: "Y", getValue: () => String(year) },
60
64
  // Expanded years, -001970 -001971 ... +001907 +001971
61
- { key: "YYYYY", value: zeroPad(year, 5) },
65
+ { key: "YYYYY", getValue: () => zeroPad(year, 5) },
62
66
  // ISO week-year
63
67
  // 1970 1971 ... 2029 2030
64
- { key: "GGGG", value: String(isoWeekYear) },
68
+ { key: "GGGG", getValue: () => String(isoWeekYear) },
65
69
  // 70 71 ... 29 30
66
- { key: "GG", value: String(isoWeekYear).slice(-2) },
70
+ { key: "GG", getValue: () => String(isoWeekYear).slice(-2) },
67
71
  // "locale" week-year
68
- { key: "gggg", value: String(localeWeekYear) },
69
- { key: "gg", value: String(localeWeekYear).slice(-2) },
72
+ { key: "gggg", getValue: () => String(localeWeekYear) },
73
+ { key: "gg", getValue: () => String(localeWeekYear).slice(-2) },
70
74
  // Quarter
71
- { key: "Q", value: String(Math.floor(monthIndex / 3) + 1) },
72
- { key: "Qo", value: getOrdinal(Math.floor(monthIndex / 3) + 1) },
75
+ { key: "Q", getValue: () => String(Math.floor(monthIndex / 3) + 1) },
76
+ { key: "Qo", getValue: () => getOrdinal(Math.floor(monthIndex / 3) + 1) },
73
77
  // --- Month (using Intl) ---
74
- { key: "MMMM", value: getMonthName(date, "long") },
78
+ { key: "MMMM", getValue: () => getMonthName(date, "long") },
75
79
  // e.g. "January"
76
- { key: "MMM", value: getMonthName(date, "short") },
80
+ { key: "MMM", getValue: () => getMonthName(date, "short") },
77
81
  // e.g. "Jan"
78
82
  // For numeric months, we still do a manual approach:
79
- { key: "MM", value: zeroPad(monthIndex + 1, 2) },
80
- { key: "M", value: String(monthIndex + 1) },
81
- { key: "Mo", value: getOrdinal(monthIndex + 1) },
83
+ { key: "MM", getValue: () => zeroPad(monthIndex + 1, 2) },
84
+ { key: "M", getValue: () => String(monthIndex + 1) },
85
+ { key: "Mo", getValue: () => getOrdinal(monthIndex + 1) },
82
86
  // Day of Month
83
- { key: "DD", value: zeroPad(dayOfMonth, 2) },
84
- { key: "D", value: String(dayOfMonth) },
85
- { key: "Do", value: getOrdinal(dayOfMonth) },
87
+ { key: "DD", getValue: () => zeroPad(dayOfMonth, 2) },
88
+ { key: "D", getValue: () => String(dayOfMonth) },
89
+ { key: "Do", getValue: () => getOrdinal(dayOfMonth) },
86
90
  // --- Day of Week (using Intl) ---
87
- { key: "dddd", value: getDayName(date, "long") },
91
+ { key: "dddd", getValue: () => getDayName(date, "long") },
88
92
  // e.g. "Monday"
89
- { key: "ddd", value: getDayName(date, "short") },
93
+ { key: "ddd", getValue: () => getDayName(date, "short") },
90
94
  // e.g. "Mon"
91
95
  {
92
96
  key: "dd",
93
97
  // e.g. "Mo" => first 2 chars of short day name
94
- value: getDayName(date, "short").slice(0, 2)
98
+ getValue: () => getDayName(date, "short").slice(0, 2)
95
99
  },
96
- { key: "d", value: String(dayOfWeek) },
97
- { key: "do", value: getOrdinal(dayOfWeek + 1) },
100
+ { key: "d", getValue: () => String(dayOfWeek) },
101
+ { key: "do", getValue: () => getOrdinal(dayOfWeek + 1) },
98
102
  // Day of the year
99
- { key: "DDDD", value: zeroPad(getDayOfYear(date), 3) },
100
- { key: "DDD", value: String(getDayOfYear(date)) },
101
- { key: "DDDo", value: getOrdinal(getDayOfYear(date)) },
103
+ { key: "DDDD", getValue: () => zeroPad(getDayOfYear(date), 3) },
104
+ { key: "DDD", getValue: () => String(getDayOfYear(date)) },
105
+ { key: "DDDo", getValue: () => getOrdinal(getDayOfYear(date)) },
102
106
  // ISO day of week
103
- { key: "E", value: String(getISODayOfWeek(date)) },
104
- // Day of Year
105
- { key: "DDDD", value: zeroPad(getDayOfYear(date), 3) },
106
- { key: "DDD", value: String(getDayOfYear(date)) },
107
+ { key: "E", getValue: () => String(getISODayOfWeek(date)) },
107
108
  // Week of the year
108
109
  // w 1 2 ... 52 53
109
- { key: "w", value: zeroPad(isoWeekNum, 2) },
110
+ { key: "w", getValue: () => zeroPad(isoWeekNum, 2) },
110
111
  // week 1st 2nd ... 52nd 53rd
111
- { key: "wo", value: getOrdinal(isoWeekNum) },
112
+ { key: "wo", getValue: () => getOrdinal(isoWeekNum) },
112
113
  // 01 02 ... 52 53
113
- { key: "ww", value: zeroPad(isoWeekNum, 2) },
114
+ { key: "ww", getValue: () => zeroPad(isoWeekNum, 2) },
114
115
  // ISO Week
115
- { key: "WW", value: zeroPad(isoWeekNum, 2) },
116
- { key: "W", value: String(isoWeekNum) },
117
- { key: "Wo", value: getOrdinal(isoWeekNum) },
116
+ { key: "WW", getValue: () => zeroPad(isoWeekNum, 2) },
117
+ { key: "W", getValue: () => String(isoWeekNum) },
118
+ { key: "Wo", getValue: () => getOrdinal(isoWeekNum) },
118
119
  // or "locale" week => replace isoWeekNum
119
120
  // 24h hours
120
- { key: "HH", value: zeroPad(hours, 2) },
121
- { key: "H", value: String(hours) },
121
+ { key: "HH", getValue: () => zeroPad(hours, 2) },
122
+ { key: "H", getValue: () => String(hours) },
122
123
  // 12h hours
123
- { key: "hh", value: zeroPad((hours + 11) % 12 + 1, 2) },
124
- { key: "h", value: String((hours + 11) % 12 + 1) },
124
+ { key: "hh", getValue: () => zeroPad((hours + 11) % 12 + 1, 2) },
125
+ { key: "h", getValue: () => String((hours + 11) % 12 + 1) },
125
126
  // 1 2 ... 23 24
126
- { key: "k", value: String(hours || 24) },
127
+ { key: "k", getValue: () => String(hours || 24) },
127
128
  // 01 02 ... 23 24
128
- { key: "kk", value: zeroPad(hours || 24, 2) },
129
+ { key: "kk", getValue: () => zeroPad(hours || 24, 2) },
129
130
  // Minutes
130
- { key: "mm", value: zeroPad(minutes, 2) },
131
- { key: "m", value: String(minutes) },
131
+ { key: "mm", getValue: () => zeroPad(minutes, 2) },
132
+ { key: "m", getValue: () => String(minutes) },
132
133
  // Seconds
133
- { key: "ss", value: zeroPad(seconds, 2) },
134
- { key: "s", value: String(seconds) },
134
+ { key: "ss", getValue: () => zeroPad(seconds, 2) },
135
+ { key: "s", getValue: () => String(seconds) },
135
136
  // Fractional seconds (S..SSSS) => handled separately
136
137
  // Timezone offset (Z, ZZ) => handled separately
137
138
  // AM/PM
138
- { key: "A", value: hours < 12 ? "AM" : "PM" },
139
- { key: "a", value: hours < 12 ? "am" : "pm" },
139
+ { key: "A", getValue: () => hours < 12 ? "AM" : "PM" },
140
+ { key: "a", getValue: () => hours < 12 ? "am" : "pm" },
140
141
  // Unix timestamps
141
- { key: "X", value: String(unixSec) },
142
- { key: "x", value: String(unixMs) },
142
+ { key: "X", getValue: () => String(unixSec) },
143
+ { key: "x", getValue: () => String(unixMs) },
143
144
  // Eras BC AD
144
- { key: "N", value: year < 0 ? "BC" : "AD" },
145
- { key: "NN", value: year < 0 ? "BC" : "AD" },
146
- { key: "NNN", value: year < 0 ? "BC" : "AD" },
145
+ { key: "N", getValue: () => year < 0 ? "BC" : "AD" },
146
+ { key: "NN", getValue: () => year < 0 ? "BC" : "AD" },
147
+ { key: "NNN", getValue: () => year < 0 ? "BC" : "AD" },
147
148
  // Before Christ, Anno Domini
148
- { key: "NNNN", value: year < 0 ? "Before Christ" : "Anno Domini" },
149
- { key: "NNNNN", value: year < 0 ? "BC" : "AD" },
149
+ { key: "NNNN", getValue: () => year < 0 ? "Before Christ" : "Anno Domini" },
150
+ { key: "NNNNN", getValue: () => year < 0 ? "BC" : "AD" },
150
151
  // Time zone offset
151
- { key: "z", value: getTimeZoneAbbreviation(date) },
152
- { key: "zz", value: getTimeZoneAbbreviation(date) },
153
- { key: "Z", value: dateFns.format(date, "xxx") },
154
- { key: "ZZ", value: dateFns.format(date, "xx") }
152
+ { key: "z", getValue: () => getTimeZoneAbbreviation(date) },
153
+ { key: "zz", getValue: () => getTimeZoneAbbreviation(date) },
154
+ { key: "Z", getValue: () => format$1(date, "xxx") },
155
+ { key: "ZZ", getValue: () => format$1(date, "xx") },
156
+ // Time
157
+ { key: "LTS", getValue: () => getLocalizedDate(date, { timeStyle: "medium" }) },
158
+ { key: "LT", getValue: () => getLocalizedDate(date, { timeStyle: "short" }) },
159
+ // Date (uppercase = longer names)
160
+ {
161
+ key: "LLLL",
162
+ getValue: () => getLocalizedDate(date, {
163
+ weekday: "long",
164
+ year: "numeric",
165
+ month: "long",
166
+ day: "numeric",
167
+ hour: "numeric",
168
+ minute: "numeric"
169
+ })
170
+ },
171
+ {
172
+ key: "LLL",
173
+ getValue: () => getLocalizedDate(date, {
174
+ year: "numeric",
175
+ month: "long",
176
+ day: "numeric",
177
+ hour: "numeric",
178
+ minute: "numeric"
179
+ })
180
+ },
181
+ {
182
+ key: "LL",
183
+ getValue: () => getLocalizedDate(date, { year: "numeric", month: "long", day: "numeric" })
184
+ },
185
+ {
186
+ key: "L",
187
+ getValue: () => getLocalizedDate(date, { year: "numeric", month: "2-digit", day: "2-digit" })
188
+ },
189
+ // Date (lowercase = shorter names)
190
+ {
191
+ key: "llll",
192
+ getValue: () => getLocalizedDate(date, {
193
+ weekday: "short",
194
+ year: "numeric",
195
+ month: "short",
196
+ day: "numeric",
197
+ hour: "numeric",
198
+ minute: "numeric"
199
+ })
200
+ },
201
+ {
202
+ key: "lll",
203
+ getValue: () => getLocalizedDate(date, {
204
+ year: "numeric",
205
+ month: "short",
206
+ day: "numeric",
207
+ hour: "numeric",
208
+ minute: "numeric"
209
+ })
210
+ },
211
+ {
212
+ key: "ll",
213
+ getValue: () => getLocalizedDate(date, { year: "numeric", month: "short", day: "numeric" })
214
+ },
215
+ {
216
+ key: "l",
217
+ getValue: () => getLocalizedDate(date, { year: "numeric", month: "numeric", day: "numeric" })
218
+ }
155
219
  ];
156
220
  tokens.sort((a, b) => b.key.length - a.key.length);
157
- const fracSecRegex = /(S{1,4})/g;
221
+ const fracSecRegex = new RegExp("(?<!LT)S{1,4}", "g");
158
222
  let output = processedFormat.replace(fracSecRegex, (match) => getFractionalSeconds(date, match.length));
159
- for (const { key, value } of tokens) {
223
+ for (const { key, getValue } of tokens) {
160
224
  const escapedKey = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), tokenRegex = new RegExp(`(^|[^A-Z0-9a-z])(${escapedKey})(?![A-Z0-9a-z])`, "g");
161
- output = output.replace(tokenRegex, `$1${value}`);
225
+ if (output.match(tokenRegex)) {
226
+ const value = getValue();
227
+ output = output.replace(tokenRegex, `$1${value}`);
228
+ }
162
229
  }
163
- return output = output.replace(new RegExp(escapeToken, "g"), () => escapeSequences.shift() || ""), output;
230
+ return output = output.replace(new RegExp("\uE000", "g"), () => escapeSequences.shift() || ""), output;
164
231
  }
165
232
  function momentToDateFnsFormat(momentFormat) {
166
233
  const formatMap = {
@@ -193,19 +260,34 @@ function momentToDateFnsFormat(momentFormat) {
193
260
  const DEFAULT_DATE_FORMAT = "YYYY-MM-DD", DEFAULT_TIME_FORMAT = "HH:mm", DEFAULT_TIMEZONE = Intl.DateTimeFormat().resolvedOptions().timeZone;
194
261
  function format(input, dateFormat, options = { useUTC: !1, timeZone: void 0 }) {
195
262
  const { useUTC, timeZone } = options;
196
- return formatMomentLike(useUTC ? new utc.UTCDateMini(input) : timeZone ? new tz.TZDateMini(input, timeZone || DEFAULT_TIMEZONE) : new Date(input), dateFormat);
263
+ return formatMomentLike(useUTC ? new UTCDateMini(input) : timeZone ? new TZDateMini(input, timeZone || DEFAULT_TIMEZONE) : new Date(input), dateFormat);
197
264
  }
198
265
  function parse(dateString, dateFormat, timeZone) {
199
- const dnsFormat = dateFormat ? momentToDateFnsFormat(dateFormat) : void 0, parsed = dnsFormat ? dateFns.parse(dateString, dnsFormat, /* @__PURE__ */ new Date()) : dateFns.parseISO(dateString);
200
- return parsed && !isNaN(parsed.getTime()) ? { isValid: !0, date: timeZone && isValidTimeZoneString(timeZone) ? new tz.TZDateMini(parsed, timeZone) : parsed } : { isValid: !1, error: `Invalid date. Must be on the format "${dateFormat}"` };
266
+ const dnsFormat = dateFormat ? momentToDateFnsFormat(dateFormat) : void 0, parsed = dnsFormat ? parse$1(dateString, dnsFormat, /* @__PURE__ */ new Date()) : parseISO(dateString);
267
+ if (parsed && !isNaN(parsed.getTime())) {
268
+ let parsedDate = parsed;
269
+ return timeZone && isValidTimeZoneString(timeZone) && dateFormat ? parsedDate = new TZDateMini(
270
+ parsed.getFullYear(),
271
+ parsed.getMonth(),
272
+ parsed.getDate(),
273
+ parsed.getHours(),
274
+ parsed.getMinutes(),
275
+ parsed.getSeconds(),
276
+ parsed.getMilliseconds(),
277
+ timeZone
278
+ ) : timeZone && isValidTimeZoneString(timeZone) && (parsedDate = new TZDateMini(parsed, timeZone)), { isValid: !0, date: parsedDate };
279
+ }
280
+ return { isValid: !1, error: `Invalid date. Must be on the format "${dateFormat}"` };
201
281
  }
202
282
  function isValidTimeZoneString(timeZone) {
203
283
  return Intl.supportedValuesOf("timeZone").includes(timeZone);
204
284
  }
205
- exports.DEFAULT_DATE_FORMAT = DEFAULT_DATE_FORMAT;
206
- exports.DEFAULT_TIME_FORMAT = DEFAULT_TIME_FORMAT;
207
- exports.format = format;
208
- exports.isValidTimeZoneString = isValidTimeZoneString;
209
- exports.parse = parse;
210
- exports.sanitizeLocale = sanitizeLocale;
285
+ export {
286
+ DEFAULT_DATE_FORMAT,
287
+ DEFAULT_TIME_FORMAT,
288
+ format,
289
+ isValidTimeZoneString,
290
+ parse,
291
+ sanitizeLocale
292
+ };
211
293
  //# sourceMappingURL=legacyDateFormat.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"legacyDateFormat.js","sources":["../src/datetime-formatter/sanitizeLocale.ts","../src/datetime-formatter/formatter.ts","../src/datetime-formatter/momentToDateFnsFormat.ts","../src/legacyDateFormat.ts"],"sourcesContent":["// this is used to avoid issues with the Intl.DateTimeFormat constructor as part of the efps tests\nconst sanitizeLocale = (locale: string): string => locale.replace(/@posix$/, '')\n\nexport default sanitizeLocale\n","import {format} from 'date-fns'\n\nimport sanitizeLocale from './sanitizeLocale'\n\nfunction getMonthName(\n date: Date,\n style: 'long' | 'short' | 'narrow' | undefined = 'long',\n locale = 'en-US',\n): string {\n const validLocale = sanitizeLocale(locale)\n return new Intl.DateTimeFormat(validLocale, {month: style}).format(date)\n}\n\nfunction getDayName(\n date: Date,\n style: 'long' | 'short' | 'narrow' | undefined = 'long',\n locale = 'en-US',\n): string {\n const validLocale = sanitizeLocale(locale)\n return new Intl.DateTimeFormat(validLocale, {weekday: style}).format(date)\n}\n\n/**\n * Zero-pads a number to `length` digits (e.g. zeroPad(7, 2) = \"07\").\n */\nfunction zeroPad(num: number, length: number): string {\n return String(num).padStart(length, '0')\n}\n\n/**\n * Returns an English ordinal for a given day number\n */\nfunction getOrdinal(day: number): string {\n const j = day % 10\n const k = day % 100\n if (j === 1 && k !== 11) return `${day}st`\n if (j === 2 && k !== 12) return `${day}nd`\n if (j === 3 && k !== 13) return `${day}rd`\n return `${day}th`\n}\n\nfunction getISODayOfWeek(date: Date): number {\n // Sunday=0 in JS, but ISO calls Monday=1...Sunday=7\n const dow = date.getDay()\n return dow === 0 ? 7 : dow\n}\n\nfunction getISOWeekYear(date: Date): number {\n // Clone date, shift to the \"Thursday\" of this week\n const temp = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()))\n const dayOfWeek = getISODayOfWeek(temp)\n temp.setUTCDate(temp.getUTCDate() - dayOfWeek + 4)\n return temp.getUTCFullYear()\n}\n\nfunction getISOWeekNumber(date: Date): number {\n const temp = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()))\n const dayOfWeek = getISODayOfWeek(temp)\n temp.setUTCDate(temp.getUTCDate() - dayOfWeek + 4)\n const yearStart = new Date(Date.UTC(temp.getUTCFullYear(), 0, 1))\n return Math.ceil(((temp.valueOf() - yearStart.valueOf()) / 86400000 + 1) / 7)\n}\n\nfunction getDayOfYear(date: Date): number {\n const startOfYear = new Date(Date.UTC(date.getFullYear(), 0, 1))\n // fix for local-time differences\n const diff =\n date.valueOf() -\n startOfYear.valueOf() +\n (startOfYear.getTimezoneOffset() - date.getTimezoneOffset()) * 60_000\n return Math.floor(diff / (1000 * 60 * 60 * 24)) + 1\n}\n\n// \"Locale\" week-year => approximate with ISO logic here\nfunction getLocaleWeekYear(date: Date): number {\n return getISOWeekYear(date)\n}\n\n/**\n * Returns fractional seconds based on the count of 'S' in the token.\n */\nfunction getFractionalSeconds(date: Date, length: number): string {\n const ms = zeroPad(date.getMilliseconds(), 3) // \"123\"\n if (length === 1) {\n return ms.slice(0, 1) // \"1\"\n } else if (length === 2) {\n return ms.slice(0, 2) // \"12\"\n } else if (length === 3) {\n return ms // \"123\"\n }\n // length=4 => e.g. \"1230\"\n return `${ms}0`\n}\n\nfunction getTimeZoneAbbreviation(date: Date) {\n const parts = new Intl.DateTimeFormat(sanitizeLocale('en-US'), {\n timeZoneName: 'short',\n }).formatToParts(date)\n const tz = parts.find((part) => part.type === 'timeZoneName')\n return tz ? tz.value : ''\n}\n\n/**\n * Formats a Date object using many Moment-like tokens.\n */\nfunction formatMomentLike(date: Date, formatStr: string): string {\n // Store escaped sequences to restore later\n const escapeSequences: string[] = []\n const escapeToken = '\\uE000' // Use a Unicode private use character as placeholder\n\n // Replace bracketed content with placeholders\n const processedFormat = formatStr.replace(/\\[([^\\]]+)\\]/g, (_, contents) => {\n escapeSequences.push(contents)\n return escapeToken\n })\n\n // Basic fields\n const year = date.getFullYear()\n const monthIndex = date.getMonth() // 0..11\n const dayOfMonth = date.getDate() // 1..31\n const dayOfWeek = date.getDay() // 0..6 (Sun=0)\n const hours = date.getHours() // 0..23\n const minutes = date.getMinutes() // 0..59\n const seconds = date.getSeconds() // 0..59\n\n // Week-related\n const isoWeekNum = getISOWeekNumber(date)\n const isoWeekYear = getISOWeekYear(date)\n const localeWeekYear = getLocaleWeekYear(date)\n\n // Timestamps\n const unixMs = date.getTime() // milliseconds since epoch\n const unixSec = Math.floor(unixMs / 1000) // seconds since epoch\n\n // Build token -> value map\n const tokens = [\n // Year\n // 1970 1971 ... 2029 2030\n {key: 'YYYY', value: String(year)},\n // 70 71 ... 29 30\n {key: 'YY', value: String(year).slice(-2)},\n // 1970 1971 ... 9999 +10000 +10001\n {key: 'Y', value: String(year)},\n // Expanded years, -001970 -001971 ... +001907 +001971\n {key: 'YYYYY', value: zeroPad(year, 5)},\n\n // ISO week-year\n // 1970 1971 ... 2029 2030\n {key: 'GGGG', value: String(isoWeekYear)},\n // 70 71 ... 29 30\n {key: 'GG', value: String(isoWeekYear).slice(-2)},\n\n // \"locale\" week-year\n {key: 'gggg', value: String(localeWeekYear)},\n {key: 'gg', value: String(localeWeekYear).slice(-2)},\n\n // Quarter\n {key: 'Q', value: String(Math.floor(monthIndex / 3) + 1)},\n {key: 'Qo', value: getOrdinal(Math.floor(monthIndex / 3) + 1)},\n\n // --- Month (using Intl) ---\n {key: 'MMMM', value: getMonthName(date, 'long')}, // e.g. \"January\"\n {key: 'MMM', value: getMonthName(date, 'short')}, // e.g. \"Jan\"\n // For numeric months, we still do a manual approach:\n {key: 'MM', value: zeroPad(monthIndex + 1, 2)},\n {key: 'M', value: String(monthIndex + 1)},\n {key: 'Mo', value: getOrdinal(monthIndex + 1)},\n\n // Day of Month\n {key: 'DD', value: zeroPad(dayOfMonth, 2)},\n {key: 'D', value: String(dayOfMonth)},\n {key: 'Do', value: getOrdinal(dayOfMonth)},\n\n // --- Day of Week (using Intl) ---\n {key: 'dddd', value: getDayName(date, 'long')}, // e.g. \"Monday\"\n {key: 'ddd', value: getDayName(date, 'short')}, // e.g. \"Mon\"\n {\n key: 'dd',\n // e.g. \"Mo\" => first 2 chars of short day name\n value: getDayName(date, 'short').slice(0, 2),\n },\n {key: 'd', value: String(dayOfWeek)},\n {key: 'do', value: getOrdinal(dayOfWeek + 1)},\n\n // Day of the year\n {key: 'DDDD', value: zeroPad(getDayOfYear(date), 3)},\n {key: 'DDD', value: String(getDayOfYear(date))},\n {key: 'DDDo', value: getOrdinal(getDayOfYear(date))},\n\n // ISO day of week\n {key: 'E', value: String(getISODayOfWeek(date))},\n\n // Day of Year\n {key: 'DDDD', value: zeroPad(getDayOfYear(date), 3)},\n {key: 'DDD', value: String(getDayOfYear(date))},\n\n // Week of the year\n // w 1 2 ... 52 53\n {key: 'w', value: zeroPad(isoWeekNum, 2)},\n // week 1st 2nd ... 52nd 53rd\n {key: 'wo', value: getOrdinal(isoWeekNum)},\n // 01 02 ... 52 53\n {key: 'ww', value: zeroPad(isoWeekNum, 2)},\n\n // ISO Week\n {key: 'WW', value: zeroPad(isoWeekNum, 2)},\n {key: 'W', value: String(isoWeekNum)},\n {key: 'Wo', value: getOrdinal(isoWeekNum)},\n\n // or \"locale\" week => replace isoWeekNum\n\n // 24h hours\n {key: 'HH', value: zeroPad(hours, 2)},\n {key: 'H', value: String(hours)},\n\n // 12h hours\n {key: 'hh', value: zeroPad(((hours + 11) % 12) + 1, 2)},\n {key: 'h', value: String(((hours + 11) % 12) + 1)},\n\n // 1 2 ... 23 24\n {key: 'k', value: String(hours || 24)},\n // 01 02 ... 23 24\n {key: 'kk', value: zeroPad(hours || 24, 2)},\n\n // Minutes\n {key: 'mm', value: zeroPad(minutes, 2)},\n {key: 'm', value: String(minutes)},\n\n // Seconds\n {key: 'ss', value: zeroPad(seconds, 2)},\n {key: 's', value: String(seconds)},\n\n // Fractional seconds (S..SSSS) => handled separately\n // Timezone offset (Z, ZZ) => handled separately\n\n // AM/PM\n {key: 'A', value: hours < 12 ? 'AM' : 'PM'},\n {key: 'a', value: hours < 12 ? 'am' : 'pm'},\n\n // Unix timestamps\n {key: 'X', value: String(unixSec)},\n {key: 'x', value: String(unixMs)},\n\n // Eras BC AD\n {key: 'N', value: year < 0 ? 'BC' : 'AD'},\n {key: 'NN', value: year < 0 ? 'BC' : 'AD'},\n {key: 'NNN', value: year < 0 ? 'BC' : 'AD'},\n\n // Before Christ, Anno Domini\n {key: 'NNNN', value: year < 0 ? 'Before Christ' : 'Anno Domini'},\n {key: 'NNNNN', value: year < 0 ? 'BC' : 'AD'},\n\n // Time zone offset\n {key: 'z', value: getTimeZoneAbbreviation(date)},\n {key: 'zz', value: getTimeZoneAbbreviation(date)},\n {key: 'Z', value: format(date, 'xxx')},\n {key: 'ZZ', value: format(date, 'xx')},\n ]\n\n // Sort tokens by descending length to avoid partial collisions\n tokens.sort((a, b) => b.key.length - a.key.length)\n\n // 1) Fractional seconds\n const fracSecRegex = /(S{1,4})/g\n let output = processedFormat.replace(fracSecRegex, (match) => {\n return getFractionalSeconds(date, match.length)\n })\n\n // Find each token and replace it, make sure not to replace overlapping tokens\n\n for (const {key, value} of tokens) {\n // Escape special characters\n const escapedKey = key.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n // Match the token, but only if it's not part of a larger word\n const tokenRegex = new RegExp(`(^|[^A-Z0-9a-z])(${escapedKey})(?![A-Z0-9a-z])`, 'g')\n output = output.replace(tokenRegex, `$1${value}`)\n }\n\n // After all token replacements, restore escaped sequences\n output = output.replace(new RegExp(escapeToken, 'g'), () => escapeSequences.shift() || '')\n\n return output\n}\n\nexport default formatMomentLike\n","/**\n * Converts a Moment.js format string into a UTS 35 (Unicode Technical Standard #35)\n * format string\n *\n * This function doesn't take absolutely every token into account, but should cover\n * all common cases. If you find a missing token, feel free to add it.\n *\n */\nexport function momentToDateFnsFormat(momentFormat: string): string {\n // A list of replacements from Moment tokens to date-fns tokens\n // ordered from longest to shortest to prevent partial replacements\n const formatMap: Record<string, string> = {\n YYYY: 'yyyy',\n YY: 'yy',\n MMMM: 'MMMM',\n MMM: 'MMM',\n MM: 'MM',\n M: 'M',\n DD: 'dd',\n D: 'd',\n dddd: 'EEEE',\n ddd: 'EEE',\n HH: 'HH',\n H: 'H',\n hh: 'hh',\n h: 'h',\n mm: 'mm',\n m: 'm',\n ss: 'ss',\n s: 's',\n A: 'a',\n a: 'a',\n }\n\n // Replace each token in the format string\n return Object.keys(formatMap).reduce(\n (acc, key) => acc.replace(new RegExp(key, 'g'), formatMap[key]),\n momentFormat,\n )\n}\n","import {TZDateMini} from '@date-fns/tz'\nimport {UTCDateMini} from '@date-fns/utc'\nimport {parse as dateFnsParse, parseISO} from 'date-fns'\n\nimport formatMomentLike from './datetime-formatter/formatter'\nimport {momentToDateFnsFormat} from './datetime-formatter/momentToDateFnsFormat'\nimport sanitizeLocale from './datetime-formatter/sanitizeLocale'\n\nexport {sanitizeLocale}\n\nexport const DEFAULT_DATE_FORMAT = 'YYYY-MM-DD'\nexport const DEFAULT_TIME_FORMAT = 'HH:mm'\n// take local as default time zone\nconst DEFAULT_TIMEZONE = Intl.DateTimeFormat().resolvedOptions().timeZone\n\nexport type ParseResult = {isValid: boolean; date?: Date; error?: string} & (\n | {isValid: true; date: Date}\n | {isValid: false; error?: string}\n)\n\nexport function format(\n input: Date,\n dateFormat: string,\n options: {useUTC?: boolean; timeZone?: string} = {useUTC: false, timeZone: undefined},\n): string {\n const {useUTC, timeZone} = options\n\n if (useUTC) return formatMomentLike(new UTCDateMini(input), dateFormat)\n return formatMomentLike(\n timeZone ? new TZDateMini(input, timeZone || DEFAULT_TIMEZONE) : new Date(input),\n dateFormat,\n )\n}\n\n/*\n It would be so good to remove date-fns from this file, but it's used in the parse function. We could write our own parser,\n but this is better than moment.\n */\nexport function parse(dateString: string, dateFormat?: string, timeZone?: string): ParseResult {\n const dnsFormat = dateFormat ? momentToDateFnsFormat(dateFormat) : undefined\n\n // parse string to date using the format string from date-fns\n const parsed = dnsFormat ? dateFnsParse(dateString, dnsFormat, new Date()) : parseISO(dateString)\n if (parsed && !isNaN(parsed.getTime())) {\n const parsedDate =\n timeZone && isValidTimeZoneString(timeZone) ? new TZDateMini(parsed, timeZone) : parsed\n return {isValid: true, date: parsedDate}\n }\n return {isValid: false, error: `Invalid date. Must be on the format \"${dateFormat}\"`}\n}\n\nexport function isValidTimeZoneString(timeZone: string): boolean {\n return Intl.supportedValuesOf('timeZone').includes(timeZone)\n}\n"],"names":["tz","format","UTCDateMini","TZDateMini","dateFnsParse","parseISO"],"mappings":";;;AACA,MAAM,iBAAiB,CAAC,WAA2B,OAAO,QAAQ,WAAW,EAAE;ACG/E,SAAS,aACP,MACA,QAAiD,QACjD,SAAS,SACD;AACF,QAAA,cAAc,eAAe,MAAM;AAClC,SAAA,IAAI,KAAK,eAAe,aAAa,EAAC,OAAO,MAAM,CAAA,EAAE,OAAO,IAAI;AACzE;AAEA,SAAS,WACP,MACA,QAAiD,QACjD,SAAS,SACD;AACF,QAAA,cAAc,eAAe,MAAM;AAClC,SAAA,IAAI,KAAK,eAAe,aAAa,EAAC,SAAS,MAAM,CAAA,EAAE,OAAO,IAAI;AAC3E;AAKA,SAAS,QAAQ,KAAa,QAAwB;AACpD,SAAO,OAAO,GAAG,EAAE,SAAS,QAAQ,GAAG;AACzC;AAKA,SAAS,WAAW,KAAqB;AACvC,QAAM,IAAI,MAAM,IACV,IAAI,MAAM;AACZ,SAAA,MAAM,KAAK,MAAM,KAAW,GAAG,GAAG,OAClC,MAAM,KAAK,MAAM,KAAW,GAAG,GAAG,OAClC,MAAM,KAAK,MAAM,KAAW,GAAG,GAAG,OAC/B,GAAG,GAAG;AACf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,CAAM,IAAIC,iBAAS,UAAU;AAChG,SAAI,UAAU,CAAC,MAAM,OAAO,QAAS,CAAA,IAG5B,EAAC,SAAS,IAAM,MADrB,YAAY,sBAAsB,QAAQ,IAAI,IAAIF,GAAAA,WAAW,QAAQ,QAAQ,IAAI,OAC5C,IAElC,EAAC,SAAS,IAAO,OAAO,wCAAwC,UAAU,IAAG;AACtF;AAEO,SAAS,sBAAsB,UAA2B;AAC/D,SAAO,KAAK,kBAAkB,UAAU,EAAE,SAAS,QAAQ;AAC7D;;;;;;;"}
1
+ {"version":3,"file":"legacyDateFormat.js","sources":["../src/datetime-formatter/sanitizeLocale.ts","../src/datetime-formatter/formatter.ts","../src/datetime-formatter/momentToDateFnsFormat.ts","../src/legacyDateFormat.ts"],"sourcesContent":["// this is used to avoid issues with the Intl.DateTimeFormat constructor as part of the efps tests\nconst sanitizeLocale = (locale: string): string => locale.replace(/@posix$/, '')\n\nexport default sanitizeLocale\n","import {format} from 'date-fns'\n\nimport sanitizeLocale from './sanitizeLocale'\n\nfunction getMonthName(\n date: Date,\n style: 'long' | 'short' | 'narrow' | undefined = 'long',\n locale = 'en-US',\n): string {\n const validLocale = sanitizeLocale(locale)\n return new Intl.DateTimeFormat(validLocale, {month: style}).format(date)\n}\n\nfunction getDayName(\n date: Date,\n style: 'long' | 'short' | 'narrow' | undefined = 'long',\n locale = 'en-US',\n): string {\n const validLocale = sanitizeLocale(locale)\n return new Intl.DateTimeFormat(validLocale, {weekday: style}).format(date)\n}\n\nfunction getLocalizedDate(date: Date, options: Intl.DateTimeFormatOptions, locale = 'en-US') {\n const validLocale = sanitizeLocale(locale)\n return new Intl.DateTimeFormat(validLocale, options).format(date)\n}\n\n/**\n * Zero-pads a number to `length` digits (e.g. zeroPad(7, 2) = \"07\").\n */\nfunction zeroPad(num: number, length: number): string {\n return String(num).padStart(length, '0')\n}\n\n/**\n * Returns an English ordinal for a given day number\n */\nfunction getOrdinal(day: number): string {\n const j = day % 10\n const k = day % 100\n if (j === 1 && k !== 11) return `${day}st`\n if (j === 2 && k !== 12) return `${day}nd`\n if (j === 3 && k !== 13) return `${day}rd`\n return `${day}th`\n}\n\nfunction getISODayOfWeek(date: Date): number {\n // Sunday=0 in JS, but ISO calls Monday=1...Sunday=7\n const dow = date.getDay()\n return dow === 0 ? 7 : dow\n}\n\nfunction getISOWeekYear(date: Date): number {\n // Clone date, shift to the \"Thursday\" of this week\n const temp = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()))\n const dayOfWeek = getISODayOfWeek(temp)\n temp.setUTCDate(temp.getUTCDate() - dayOfWeek + 4)\n return temp.getUTCFullYear()\n}\n\nfunction getISOWeekNumber(date: Date): number {\n const temp = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()))\n const dayOfWeek = getISODayOfWeek(temp)\n temp.setUTCDate(temp.getUTCDate() - dayOfWeek + 4)\n const yearStart = new Date(Date.UTC(temp.getUTCFullYear(), 0, 1))\n return Math.ceil(((temp.valueOf() - yearStart.valueOf()) / 86400000 + 1) / 7)\n}\n\nfunction getDayOfYear(date: Date): number {\n const startOfYear = new Date(Date.UTC(date.getFullYear(), 0, 1))\n // fix for local-time differences\n const diff =\n date.valueOf() -\n startOfYear.valueOf() +\n (startOfYear.getTimezoneOffset() - date.getTimezoneOffset()) * 60_000\n return Math.floor(diff / (1000 * 60 * 60 * 24)) + 1\n}\n\n// \"Locale\" week-year => approximate with ISO logic here\nfunction getLocaleWeekYear(date: Date): number {\n return getISOWeekYear(date)\n}\n\n/**\n * Returns fractional seconds based on the count of 'S' in the token.\n */\nfunction getFractionalSeconds(date: Date, length: number): string {\n const ms = zeroPad(date.getMilliseconds(), 3) // \"123\"\n if (length === 1) {\n return ms.slice(0, 1) // \"1\"\n } else if (length === 2) {\n return ms.slice(0, 2) // \"12\"\n } else if (length === 3) {\n return ms // \"123\"\n }\n // length=4 => e.g. \"1230\"\n return `${ms}0`\n}\n\nfunction getTimeZoneAbbreviation(date: Date) {\n const parts = new Intl.DateTimeFormat(sanitizeLocale('en-US'), {\n timeZoneName: 'short',\n }).formatToParts(date)\n const tz = parts.find((part) => part.type === 'timeZoneName')\n return tz ? tz.value : ''\n}\n\n/**\n * Formats a Date object using many Moment-like tokens.\n */\nfunction formatMomentLike(date: Date, formatStr: string): string {\n // Store escaped sequences to restore later\n const escapeSequences: string[] = []\n const escapeToken = '\\uE000' // Use a Unicode private use character as placeholder\n\n // Replace bracketed content with placeholders\n const processedFormat = formatStr.replace(/\\[([^\\]]+)\\]/g, (_, contents) => {\n escapeSequences.push(contents)\n return escapeToken\n })\n\n // Basic fields\n const year = date.getFullYear()\n const monthIndex = date.getMonth() // 0..11\n const dayOfMonth = date.getDate() // 1..31\n const dayOfWeek = date.getDay() // 0..6 (Sun=0)\n const hours = date.getHours() // 0..23\n const minutes = date.getMinutes() // 0..59\n const seconds = date.getSeconds() // 0..59\n\n // Week-related\n const isoWeekNum = getISOWeekNumber(date)\n const isoWeekYear = getISOWeekYear(date)\n const localeWeekYear = getLocaleWeekYear(date)\n\n // Timestamps\n const unixMs = date.getTime() // milliseconds since epoch\n const unixSec = Math.floor(unixMs / 1000) // seconds since epoch\n\n // Build token -> value map\n const tokens = [\n // Year\n // 1970 1971 ... 2029 2030\n {key: 'YYYY', getValue: () => String(year)},\n // 70 71 ... 29 30\n {key: 'YY', getValue: () => String(year).slice(-2)},\n // 1970 1971 ... 9999 +10000 +10001\n {key: 'Y', getValue: () => String(year)},\n // Expanded years, -001970 -001971 ... +001907 +001971\n {key: 'YYYYY', getValue: () => zeroPad(year, 5)},\n\n // ISO week-year\n // 1970 1971 ... 2029 2030\n {key: 'GGGG', getValue: () => String(isoWeekYear)},\n // 70 71 ... 29 30\n {key: 'GG', getValue: () => String(isoWeekYear).slice(-2)},\n\n // \"locale\" week-year\n {key: 'gggg', getValue: () => String(localeWeekYear)},\n {key: 'gg', getValue: () => String(localeWeekYear).slice(-2)},\n\n // Quarter\n {key: 'Q', getValue: () => String(Math.floor(monthIndex / 3) + 1)},\n {key: 'Qo', getValue: () => getOrdinal(Math.floor(monthIndex / 3) + 1)},\n\n // --- Month (using Intl) ---\n {key: 'MMMM', getValue: () => getMonthName(date, 'long')}, // e.g. \"January\"\n {key: 'MMM', getValue: () => getMonthName(date, 'short')}, // e.g. \"Jan\"\n // For numeric months, we still do a manual approach:\n {key: 'MM', getValue: () => zeroPad(monthIndex + 1, 2)},\n {key: 'M', getValue: () => String(monthIndex + 1)},\n {key: 'Mo', getValue: () => getOrdinal(monthIndex + 1)},\n\n // Day of Month\n {key: 'DD', getValue: () => zeroPad(dayOfMonth, 2)},\n {key: 'D', getValue: () => String(dayOfMonth)},\n {key: 'Do', getValue: () => getOrdinal(dayOfMonth)},\n\n // --- Day of Week (using Intl) ---\n {key: 'dddd', getValue: () => getDayName(date, 'long')}, // e.g. \"Monday\"\n {key: 'ddd', getValue: () => getDayName(date, 'short')}, // e.g. \"Mon\"\n {\n key: 'dd',\n // e.g. \"Mo\" => first 2 chars of short day name\n getValue: () => getDayName(date, 'short').slice(0, 2),\n },\n {key: 'd', getValue: () => String(dayOfWeek)},\n {key: 'do', getValue: () => getOrdinal(dayOfWeek + 1)},\n\n // Day of the year\n {key: 'DDDD', getValue: () => zeroPad(getDayOfYear(date), 3)},\n {key: 'DDD', getValue: () => String(getDayOfYear(date))},\n {key: 'DDDo', getValue: () => getOrdinal(getDayOfYear(date))},\n\n // ISO day of week\n {key: 'E', getValue: () => String(getISODayOfWeek(date))},\n\n // Week of the year\n // w 1 2 ... 52 53\n {key: 'w', getValue: () => zeroPad(isoWeekNum, 2)},\n // week 1st 2nd ... 52nd 53rd\n {key: 'wo', getValue: () => getOrdinal(isoWeekNum)},\n // 01 02 ... 52 53\n {key: 'ww', getValue: () => zeroPad(isoWeekNum, 2)},\n\n // ISO Week\n {key: 'WW', getValue: () => zeroPad(isoWeekNum, 2)},\n {key: 'W', getValue: () => String(isoWeekNum)},\n {key: 'Wo', getValue: () => getOrdinal(isoWeekNum)},\n\n // or \"locale\" week => replace isoWeekNum\n\n // 24h hours\n {key: 'HH', getValue: () => zeroPad(hours, 2)},\n {key: 'H', getValue: () => String(hours)},\n\n // 12h hours\n {key: 'hh', getValue: () => zeroPad(((hours + 11) % 12) + 1, 2)},\n {key: 'h', getValue: () => String(((hours + 11) % 12) + 1)},\n\n // 1 2 ... 23 24\n {key: 'k', getValue: () => String(hours || 24)},\n // 01 02 ... 23 24\n {key: 'kk', getValue: () => zeroPad(hours || 24, 2)},\n\n // Minutes\n {key: 'mm', getValue: () => zeroPad(minutes, 2)},\n {key: 'm', getValue: () => String(minutes)},\n\n // Seconds\n {key: 'ss', getValue: () => zeroPad(seconds, 2)},\n {key: 's', getValue: () => String(seconds)},\n\n // Fractional seconds (S..SSSS) => handled separately\n // Timezone offset (Z, ZZ) => handled separately\n\n // AM/PM\n {key: 'A', getValue: () => (hours < 12 ? 'AM' : 'PM')},\n {key: 'a', getValue: () => (hours < 12 ? 'am' : 'pm')},\n\n // Unix timestamps\n {key: 'X', getValue: () => String(unixSec)},\n {key: 'x', getValue: () => String(unixMs)},\n\n // Eras BC AD\n {key: 'N', getValue: () => (year < 0 ? 'BC' : 'AD')},\n {key: 'NN', getValue: () => (year < 0 ? 'BC' : 'AD')},\n {key: 'NNN', getValue: () => (year < 0 ? 'BC' : 'AD')},\n\n // Before Christ, Anno Domini\n {key: 'NNNN', getValue: () => (year < 0 ? 'Before Christ' : 'Anno Domini')},\n {key: 'NNNNN', getValue: () => (year < 0 ? 'BC' : 'AD')},\n\n // Time zone offset\n {key: 'z', getValue: () => getTimeZoneAbbreviation(date)},\n {key: 'zz', getValue: () => getTimeZoneAbbreviation(date)},\n {key: 'Z', getValue: () => format(date, 'xxx')},\n {key: 'ZZ', getValue: () => format(date, 'xx')},\n\n // Time\n {key: 'LTS', getValue: () => getLocalizedDate(date, {timeStyle: 'medium'})},\n {key: 'LT', getValue: () => getLocalizedDate(date, {timeStyle: 'short'})},\n\n // Date (uppercase = longer names)\n {\n key: 'LLLL',\n getValue: () =>\n getLocalizedDate(date, {\n weekday: 'long',\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n }),\n },\n {\n key: 'LLL',\n getValue: () =>\n getLocalizedDate(date, {\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n }),\n },\n {\n key: 'LL',\n getValue: () => getLocalizedDate(date, {year: 'numeric', month: 'long', day: 'numeric'}),\n },\n {\n key: 'L',\n getValue: () => getLocalizedDate(date, {year: 'numeric', month: '2-digit', day: '2-digit'}),\n },\n\n // Date (lowercase = shorter names)\n {\n key: 'llll',\n getValue: () =>\n getLocalizedDate(date, {\n weekday: 'short',\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n }),\n },\n {\n key: 'lll',\n getValue: () =>\n getLocalizedDate(date, {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n }),\n },\n {\n key: 'll',\n getValue: () => getLocalizedDate(date, {year: 'numeric', month: 'short', day: 'numeric'}),\n },\n {\n key: 'l',\n getValue: () => getLocalizedDate(date, {year: 'numeric', month: 'numeric', day: 'numeric'}),\n },\n ]\n\n // Sort tokens by descending length to avoid partial collisions\n tokens.sort((a, b) => b.key.length - a.key.length)\n\n // 1) Fractional seconds (avoid colliding with LTS)\n const fracSecRegex = /(?<!LT)S{1,4}/g\n let output = processedFormat.replace(fracSecRegex, (match) => {\n return getFractionalSeconds(date, match.length)\n })\n\n // Find each token and replace it, make sure not to replace overlapping tokens\n for (const {key, getValue} of tokens) {\n // Escape special characters\n const escapedKey = key.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n // Match the token, but only if it's not part of a larger word\n const tokenRegex = new RegExp(`(^|[^A-Z0-9a-z])(${escapedKey})(?![A-Z0-9a-z])`, 'g')\n\n // Only compute the value if the token exists in the output\n if (output.match(tokenRegex)) {\n const value = getValue()\n output = output.replace(tokenRegex, `$1${value}`)\n }\n }\n\n // After all token replacements, restore escaped sequences\n output = output.replace(new RegExp(escapeToken, 'g'), () => escapeSequences.shift() || '')\n\n return output\n}\n\nexport default formatMomentLike\n","/**\n * Converts a Moment.js format string into a UTS 35 (Unicode Technical Standard #35)\n * format string\n *\n * This function doesn't take absolutely every token into account, but should cover\n * all common cases. If you find a missing token, feel free to add it.\n *\n */\nexport function momentToDateFnsFormat(momentFormat: string): string {\n // A list of replacements from Moment tokens to date-fns tokens\n // ordered from longest to shortest to prevent partial replacements\n const formatMap: Record<string, string> = {\n YYYY: 'yyyy',\n YY: 'yy',\n MMMM: 'MMMM',\n MMM: 'MMM',\n MM: 'MM',\n M: 'M',\n DD: 'dd',\n D: 'd',\n dddd: 'EEEE',\n ddd: 'EEE',\n HH: 'HH',\n H: 'H',\n hh: 'hh',\n h: 'h',\n mm: 'mm',\n m: 'm',\n ss: 'ss',\n s: 's',\n A: 'a',\n a: 'a',\n }\n\n // Replace each token in the format string\n return Object.keys(formatMap).reduce(\n (acc, key) => acc.replace(new RegExp(key, 'g'), formatMap[key]),\n momentFormat,\n )\n}\n","import {TZDateMini} from '@date-fns/tz'\nimport {UTCDateMini} from '@date-fns/utc'\nimport {parse as dateFnsParse, parseISO} from 'date-fns'\n\nimport formatMomentLike from './datetime-formatter/formatter'\nimport {momentToDateFnsFormat} from './datetime-formatter/momentToDateFnsFormat'\nimport sanitizeLocale from './datetime-formatter/sanitizeLocale'\n\nexport {sanitizeLocale}\n\nexport const DEFAULT_DATE_FORMAT = 'YYYY-MM-DD'\nexport const DEFAULT_TIME_FORMAT = 'HH:mm'\n// take local as default time zone\nconst DEFAULT_TIMEZONE = Intl.DateTimeFormat().resolvedOptions().timeZone\n\nexport type ParseResult = {isValid: boolean; date?: Date; error?: string} & (\n | {isValid: true; date: Date}\n | {isValid: false; error?: string}\n)\n\nexport function format(\n input: Date,\n dateFormat: string,\n options: {useUTC?: boolean; timeZone?: string} = {useUTC: false, timeZone: undefined},\n): string {\n const {useUTC, timeZone} = options\n\n if (useUTC) return formatMomentLike(new UTCDateMini(input), dateFormat)\n return formatMomentLike(\n timeZone ? new TZDateMini(input, timeZone || DEFAULT_TIMEZONE) : new Date(input),\n dateFormat,\n )\n}\n\n/*\n It would be so good to remove date-fns from this file, but it's used in the parse function. We could write our own parser,\n but this is better than moment.\n */\nexport function parse(dateString: string, dateFormat?: string, timeZone?: string): ParseResult {\n const dnsFormat = dateFormat ? momentToDateFnsFormat(dateFormat) : undefined\n\n // parse string to date using the format string from date-fns\n const parsed = dnsFormat ? dateFnsParse(dateString, dnsFormat, new Date()) : parseISO(dateString)\n\n if (parsed && !isNaN(parsed.getTime())) {\n let parsedDate = parsed\n\n // Only apply timezone conversion if:\n // 1. A timezone is specified, AND\n // 2. A dateFormat was provided (meaning this is user input, not an ISO string being deserialized)\n if (timeZone && isValidTimeZoneString(timeZone) && dateFormat) {\n // Create TZDateMini using the component constructor to interpret the parsed\n // components as being in the target timezone. We can't use new TZDateMini(parsed, timeZone)\n // because dateFnsParse already created the Date in the browser's local timezone, which\n // would cause an incorrect conversion. By extracting components, we tell TZDateMini:\n // \"these values represent the time in the target timezone directly\"\n parsedDate = new TZDateMini(\n parsed.getFullYear(),\n parsed.getMonth(),\n parsed.getDate(),\n parsed.getHours(),\n parsed.getMinutes(),\n parsed.getSeconds(),\n parsed.getMilliseconds(),\n timeZone,\n )\n } else if (timeZone && isValidTimeZoneString(timeZone)) {\n // For ISO strings, just wrap in TZDateMini for display without conversion\n parsedDate = new TZDateMini(parsed, timeZone)\n }\n\n return {isValid: true, date: parsedDate}\n }\n return {isValid: false, error: `Invalid date. Must be on the format \"${dateFormat}\"`}\n}\n\nexport function isValidTimeZoneString(timeZone: string): boolean {\n return Intl.supportedValuesOf('timeZone').includes(timeZone)\n}\n"],"names":["format","dateFnsParse"],"mappings":";;;AACA,MAAM,iBAAiB,CAAC,WAA2B,OAAO,QAAQ,WAAW,EAAE;ACG/E,SAAS,aACP,MACA,QA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S,UAAU;AAEhG,MAAI,UAAU,CAAC,MAAM,OAAO,QAAA,CAAS,GAAG;AACtC,QAAI,aAAa;AAKjB,WAAI,YAAY,sBAAsB,QAAQ,KAAK,aAMjD,aAAa,IAAI;AAAA,MACf,OAAO,YAAA;AAAA,MACP,OAAO,SAAA;AAAA,MACP,OAAO,QAAA;AAAA,MACP,OAAO,SAAA;AAAA,MACP,OAAO,WAAA;AAAA,MACP,OAAO,WAAA;AAAA,MACP,OAAO,gBAAA;AAAA,MACP;AAAA,IAAA,IAEO,YAAY,sBAAsB,QAAQ,MAEnD,aAAa,IAAI,WAAW,QAAQ,QAAQ,IAGvC,EAAC,SAAS,IAAM,MAAM,WAAA;AAAA,EAC/B;AACA,SAAO,EAAC,SAAS,IAAO,OAAO,wCAAwC,UAAU,IAAA;AACnF;AAEO,SAAS,sBAAsB,UAA2B;AAC/D,SAAO,KAAK,kBAAkB,UAAU,EAAE,SAAS,QAAQ;AAC7D;"}
package/lib/paths.js CHANGED
@@ -1,6 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var types = require("@sanity/types");
1
+ import { isIndexSegment, isKeySegment, isIndexTuple } from "@sanity/types";
4
2
  const rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g, reKeySegment = /_key\s*==\s*['"](.*)['"]/, EMPTY_PATH = [], FOCUS_TERMINATOR = "$", GROQ_DATA_TYPE_VALUES = ["true", "false", "null"];
5
3
  function get(obj, path, defaultVal) {
6
4
  const select = typeof path == "string" ? fromString(path) : path;
@@ -9,12 +7,12 @@ function get(obj, path, defaultVal) {
9
7
  let acc = obj;
10
8
  for (let i = 0; i < select.length; i++) {
11
9
  const segment = select[i];
12
- if (types.isIndexSegment(segment)) {
10
+ if (isIndexSegment(segment)) {
13
11
  if (!Array.isArray(acc))
14
12
  return defaultVal;
15
13
  acc = acc[segment];
16
14
  }
17
- if (types.isKeySegment(segment)) {
15
+ if (isKeySegment(segment)) {
18
16
  if (!Array.isArray(acc))
19
17
  return defaultVal;
20
18
  acc = acc.find((item) => item._key === segment._key);
@@ -42,7 +40,7 @@ function numEqualSegments(path, otherPath) {
42
40
  return length;
43
41
  }
44
42
  function isSegmentEqual(segmentA, segmentB) {
45
- return types.isKeySegment(segmentA) && types.isKeySegment(segmentB) ? segmentA._key === segmentB._key : types.isIndexSegment(segmentA) ? Number(segmentA) === Number(segmentB) : types.isIndexTuple(segmentA) && types.isIndexTuple(segmentB) ? segmentA[0] === segmentB[0] && segmentA[1] === segmentB[1] : segmentA === segmentB;
43
+ return isKeySegment(segmentA) && isKeySegment(segmentB) ? segmentA._key === segmentB._key : isIndexSegment(segmentA) ? Number(segmentA) === Number(segmentB) : isIndexTuple(segmentA) && isIndexTuple(segmentB) ? segmentA[0] === segmentB[0] && segmentA[1] === segmentB[1] : segmentA === segmentB;
46
44
  }
47
45
  function hasFocus(focusPath, path) {
48
46
  const withoutTerminator = focusPath[focusPath.length - 1] === FOCUS_TERMINATOR ? focusPath.slice(0, -1) : focusPath;
@@ -85,7 +83,7 @@ function toString(path) {
85
83
  return `${target}[${segment}]`;
86
84
  if (typeof segment == "string")
87
85
  return isHead ? segment : GROQ_DATA_TYPE_VALUES.includes(segment) ? `${target}["${segment}"]` : `${target}.${segment}`;
88
- if (types.isKeySegment(segment) && segment._key)
86
+ if (isKeySegment(segment) && segment._key)
89
87
  return `${target}[_key=="${segment._key}"]`;
90
88
  if (Array.isArray(segment)) {
91
89
  const [from, to] = segment;
@@ -121,7 +119,7 @@ function fromString(path) {
121
119
  return segments.map(normalizePathSegment);
122
120
  }
123
121
  function normalizePathSegment(segment) {
124
- return types.isIndexSegment(segment) ? normalizeIndexSegment(segment) : types.isKeySegment(segment) ? normalizeKeySegment(segment) : types.isIndexTuple(segment) ? normalizeIndexTupleSegment(segment) : segment;
122
+ return isIndexSegment(segment) ? normalizeIndexSegment(segment) : isKeySegment(segment) ? normalizeKeySegment(segment) : isIndexTuple(segment) ? normalizeIndexTupleSegment(segment) : segment;
125
123
  }
126
124
  function normalizeIndexSegment(segment) {
127
125
  return Number(segment.replace(/[^\d]/g, ""));
@@ -133,21 +131,23 @@ function normalizeIndexTupleSegment(segment) {
133
131
  const [from, to] = segment.split(":").map((seg) => seg === "" ? seg : Number(seg));
134
132
  return [from, to];
135
133
  }
136
- exports.FOCUS_TERMINATOR = FOCUS_TERMINATOR;
137
- exports._resolveKeyedPath = _resolveKeyedPath;
138
- exports.fromString = fromString;
139
- exports.get = get;
140
- exports.hasFocus = hasFocus;
141
- exports.hasItemFocus = hasItemFocus;
142
- exports.isEqual = isEqual;
143
- exports.isExpanded = isExpanded;
144
- exports.isSegmentEqual = isSegmentEqual;
145
- exports.numEqualSegments = numEqualSegments;
146
- exports.pathFor = pathFor;
147
- exports.resolveKeyedPath = resolveKeyedPath;
148
- exports.startsWith = startsWith;
149
- exports.toString = toString;
150
- exports.trimChildPath = trimChildPath;
151
- exports.trimLeft = trimLeft;
152
- exports.trimRight = trimRight;
134
+ export {
135
+ FOCUS_TERMINATOR,
136
+ _resolveKeyedPath,
137
+ fromString,
138
+ get,
139
+ hasFocus,
140
+ hasItemFocus,
141
+ isEqual,
142
+ isExpanded,
143
+ isSegmentEqual,
144
+ numEqualSegments,
145
+ pathFor,
146
+ resolveKeyedPath,
147
+ startsWith,
148
+ toString,
149
+ trimChildPath,
150
+ trimLeft,
151
+ trimRight
152
+ };
153
153
  //# sourceMappingURL=paths.js.map
package/lib/paths.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"paths.js","sources":["../src/paths.ts"],"sourcesContent":["import {\n type IndexTuple,\n isIndexSegment,\n isIndexTuple,\n isKeySegment,\n type KeyedSegment,\n type Path,\n type PathSegment,\n} from '@sanity/types'\n\nconst rePropName =\n /[^.[\\]]+|\\[(?:(-?\\d+(?:\\.\\d+)?)|([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))/g\nconst reKeySegment = /_key\\s*==\\s*['\"](.*)['\"]/\nconst EMPTY_PATH: Path = []\n\nexport const FOCUS_TERMINATOR = '$'\n\n// Fields named as GROQ data types cannot be accessed using dot notation. These fields must instead\n// be serialized using square bracket notation.\nconst GROQ_DATA_TYPE_VALUES = ['true', 'false', 'null']\n\nexport function get<R>(obj: unknown, path: Path | string): R | undefined\nexport function get<R>(obj: unknown, path: Path | string, defaultValue: R): R\nexport function get(obj: unknown, path: Path | string, defaultVal?: unknown): unknown {\n const select = typeof path === 'string' ? fromString(path) : path\n if (!Array.isArray(select)) {\n throw new Error('Path must be an array or a string')\n }\n\n let acc: unknown | undefined = obj\n for (let i = 0; i < select.length; i++) {\n const segment = select[i]\n if (isIndexSegment(segment)) {\n if (!Array.isArray(acc)) {\n return defaultVal\n }\n\n acc = acc[segment]\n }\n\n if (isKeySegment(segment)) {\n if (!Array.isArray(acc)) {\n return defaultVal\n }\n\n acc = acc.find((item) => item._key === segment._key)\n }\n\n if (typeof segment === 'string') {\n acc =\n typeof acc === 'object' && acc !== null\n ? ((acc as Record<string, unknown>)[segment] as Record<string, unknown>)\n : undefined\n }\n\n if (typeof acc === 'undefined') {\n return defaultVal\n }\n }\n\n return acc\n}\n\nconst pathsMemo = new Map<string, Path>()\nexport function pathFor(path: Path): Path {\n if (path.length === 0) {\n return EMPTY_PATH\n }\n const asString = toString(path)\n if (pathsMemo.has(asString)) {\n return pathsMemo.get(asString)!\n }\n pathsMemo.set(asString, path)\n Object.freeze(path)\n return path\n}\n\nexport function isEqual(path: Path, otherPath: Path): boolean {\n return (\n path.length === otherPath.length &&\n path.every((segment, i) => isSegmentEqual(segment, otherPath[i]))\n )\n}\n\nexport function numEqualSegments(path: Path, otherPath: Path): number {\n const length = Math.min(path.length, otherPath.length)\n for (let i = 0; i < length; i++) {\n if (!isSegmentEqual(path[i], otherPath[i])) {\n return i\n }\n }\n return length\n}\n\nexport function isSegmentEqual(segmentA: PathSegment, segmentB: PathSegment): boolean {\n if (isKeySegment(segmentA) && isKeySegment(segmentB)) {\n return segmentA._key === segmentB._key\n }\n\n if (isIndexSegment(segmentA)) {\n return Number(segmentA) === Number(segmentB)\n }\n\n if (isIndexTuple(segmentA) && isIndexTuple(segmentB)) {\n return segmentA[0] === segmentB[0] && segmentA[1] === segmentB[1]\n }\n\n return segmentA === segmentB\n}\n\nexport function hasFocus(focusPath: Path, path: Path): boolean {\n const withoutTerminator =\n focusPath[focusPath.length - 1] === FOCUS_TERMINATOR ? focusPath.slice(0, -1) : focusPath\n return isEqual(withoutTerminator, path)\n}\n\nexport function hasItemFocus(focusPath: Path, item: PathSegment): boolean {\n return focusPath.length === 1 && isSegmentEqual(focusPath[0], item)\n}\n\nexport function isExpanded(segment: PathSegment, focusPath: Path): boolean {\n const [head, ...tail] = focusPath\n return tail.length > 0 && isSegmentEqual(segment, head)\n}\n\nexport function startsWith(prefix: Path, path: Path): boolean {\n return prefix.every((segment, i) => isSegmentEqual(segment, path[i]))\n}\n\nexport function trimLeft(prefix: Path, path: Path): Path {\n if (prefix.length === 0 || path.length === 0) {\n return path\n }\n const [prefixHead, ...prefixTail] = prefix\n const [pathHead, ...pathTail] = path\n if (!isSegmentEqual(prefixHead, pathHead)) {\n return path\n }\n return pathFor(trimLeft(prefixTail, pathTail))\n}\n\nexport function trimRight(suffix: Path, path: Path): Path {\n const sufLen = suffix.length\n const pathLen = path.length\n if (sufLen === 0 || pathLen === 0) {\n return path\n }\n\n let i = 0\n while (\n i < sufLen &&\n i < pathLen &&\n isSegmentEqual(path[pathLen - i - 1], suffix[sufLen - i - 1])\n ) {\n i++\n }\n\n return pathFor(path.slice(0, pathLen - i))\n}\n\nexport function trimChildPath(path: Path, childPath: Path): Path {\n return startsWith(path, childPath) ? trimLeft(path, childPath) : EMPTY_PATH\n}\n\nexport function toString(path: Path): string {\n if (!Array.isArray(path)) {\n throw new Error('Path is not an array')\n }\n\n return path.reduce<string>((target, segment, i) => {\n const isHead = i === 0\n\n if (typeof segment === 'number') {\n return `${target}[${segment}]`\n }\n\n if (typeof segment === 'string') {\n if (isHead) {\n return segment\n }\n\n if (GROQ_DATA_TYPE_VALUES.includes(segment)) {\n return `${target}[\"${segment}\"]`\n }\n\n return `${target}.${segment}`\n }\n\n if (isKeySegment(segment) && segment._key) {\n return `${target}[_key==\"${segment._key}\"]`\n }\n\n if (Array.isArray(segment)) {\n const [from, to] = segment\n return `${target}[${from}:${to}]`\n }\n\n throw new Error(`Unsupported path segment \\`${JSON.stringify(segment)}\\``)\n }, '')\n}\n\nexport function _resolveKeyedPath(value: unknown, path: Path): Path {\n if (path.length === 0) {\n return path\n }\n const [next, ...rest] = path\n if (typeof next === 'number') {\n if (!Array.isArray(value) || !(next in value)) {\n return []\n }\n const item = value[next]\n const key = item?._key\n return [typeof key === 'string' ? {_key: item._key} : next, ..._resolveKeyedPath(item, rest)]\n }\n const nextVal = get(value, [next])\n return [next, ..._resolveKeyedPath(nextVal, rest)]\n}\n\n/**\n * Takes a value and a path that may include numeric indices and attempts to replace numeric indices with keyed paths\n *\n * @param value - any json value\n * @param path - a Path that may include numeric indices\n * @returns a path where numeric indices has been replaced by keyed segments (e.g. `{_key: <key>}`)\n * Will do as good attempt as possible, but in case of missing array items, it will return the best possible match:\n * - `resolveKeyedPath([0, 'bar'], [])` will return [] since array has no value at index 0\n * - `resolveKeyedPath([0, 'foo'], [{_key: 'xyz', 'foo': 'bar'}, {_key: 'abc'}])` will return `[{_key: 'xyz'}, 'foo']` since array has no value at index 0\n * - `resolveKeyedPath([0, 'foo', 'bar'], [{_key: 'xyz'}])` will return `[{_key: 'xyz'}, 'foo', 'bar']` since array has no value at index 0\n * Object keys will be preserved as-is, e.g. `resolveKeyedPath(['foo', 'bar'], undefined)` will return `['foo', 'bar']`\n */\nexport function resolveKeyedPath(value: unknown, path: Path): Path {\n if (!Array.isArray(path)) {\n throw new Error('Path is not an array')\n }\n return pathFor(_resolveKeyedPath(value, path))\n}\n\nexport function fromString(path: string): Path {\n if (typeof path !== 'string') {\n throw new Error('Path is not a string')\n }\n\n const segments = path.match(rePropName)\n if (!segments) {\n throw new Error('Invalid path string')\n }\n\n return segments.map(normalizePathSegment)\n}\n\nfunction normalizePathSegment(segment: string): PathSegment {\n if (isIndexSegment(segment)) {\n return normalizeIndexSegment(segment)\n }\n\n if (isKeySegment(segment)) {\n return normalizeKeySegment(segment)\n }\n\n if (isIndexTuple(segment)) {\n return normalizeIndexTupleSegment(segment)\n }\n\n return segment\n}\n\nfunction normalizeIndexSegment(segment: string): PathSegment {\n return Number(segment.replace(/[^\\d]/g, ''))\n}\n\nfunction normalizeKeySegment(segment: string): KeyedSegment {\n const segments = segment.match(reKeySegment)\n return {_key: segments![1]}\n}\n\nfunction normalizeIndexTupleSegment(segment: string): IndexTuple {\n const [from, to] = segment.split(':').map((seg) => (seg === '' ? seg : Number(seg)))\n return [from, to]\n}\n"],"names":["isIndexSegment","isKeySegment","isIndexTuple"],"mappings":";;;AAUA,MAAM,aACJ,oGACI,eAAe,4BACf,aAAmB,CAAC,GAEb,mBAAmB,KAI1B,wBAAwB,CAAC,QAAQ,SAAS,MAAM;AAItC,SAAA,IAAI,KAAc,MAAqB,YAA+B;AACpF,QAAM,SAAS,OAAO,QAAS,WAAW,WAAW,IAAI,IAAI;AACzD,MAAA,CAAC,MAAM,QAAQ,MAAM;AACjB,UAAA,IAAI,MAAM,mCAAmC;AAGrD,MAAI,MAA2B;AAC/B,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AAChC,UAAA,UAAU,OAAO,CAAC;AACpB,QAAAA,MAAAA,eAAe,OAAO,GAAG;AACvB,UAAA,CAAC,MAAM,QAAQ,GAAG;AACb,eAAA;AAGT,YAAM,IAAI,OAAO;AAAA,IAAA;AAGf,QAAAC,MAAAA,aAAa,OAAO,GAAG;AACrB,UAAA,CAAC,MAAM,QAAQ,GAAG;AACb,eAAA;AAG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MAAM,sBAAsB;AAGlC,QAAA,WAAW,KAAK,MAAM,UAAU;AACtC,MAAI,CAAC;AACG,UAAA,IAAI,MAAM,qBAAqB;AAGhC,SAAA,SAAS,IAAI,oBAAoB;AAC1C;AAEA,SAAS,qBAAqB,SAA8B;AAC1D,SAAID,MAAAA,eAAe,OAAO,IACjB,sBAAsB,OAAO,IAGlCC,MAAAA,aAAa,OAAO,IACf,oBAAoB,OAAO,IAGhCC,mBAAa,OAAO,IACf,2BAA2B,OAAO,IAGpC;AACT;AAEA,SAAS,sBAAsB,SAA8B;AAC3D,SAAO,OAAO,QAAQ,QAAQ,UAAU,EAAE,CAAC;AAC7C;AAEA,SAAS,oBAAoB,SAA+B;AAE1D,SAAO,EAAC,MADS,QAAQ,MAAM,YAAY,EACnB,CAAC,EAAC;AAC5B;AAEA,SAAS,2BAA2B,SAA6B;AAC/D,QAAM,CAAC,MAAM,EAAE,IAAI,QAAQ,MAAM,GAAG,EAAE,IAAI,CAAC,QAAS,QAAQ,KAAK,MAAM,OAAO,GAAG,CAAE;AAC5E,SAAA,CAAC,MAAM,EAAE;AAClB;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"paths.js","sources":["../src/paths.ts"],"sourcesContent":["import {\n type IndexTuple,\n isIndexSegment,\n isIndexTuple,\n isKeySegment,\n type KeyedSegment,\n type Path,\n type PathSegment,\n} from '@sanity/types'\n\nconst rePropName =\n /[^.[\\]]+|\\[(?:(-?\\d+(?:\\.\\d+)?)|([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))/g\nconst reKeySegment = /_key\\s*==\\s*['\"](.*)['\"]/\nconst EMPTY_PATH: Path = []\n\nexport const FOCUS_TERMINATOR = '$'\n\n// Fields named as GROQ data types cannot be accessed using dot notation. These fields must instead\n// be serialized using square bracket notation.\nconst GROQ_DATA_TYPE_VALUES = ['true', 'false', 'null']\n\nexport function get<R>(obj: unknown, path: Path | string): R | undefined\nexport function get<R>(obj: unknown, path: Path | string, defaultValue: R): R\nexport function get(obj: unknown, path: Path | string, defaultVal?: unknown): unknown {\n const select = typeof path === 'string' ? fromString(path) : path\n if (!Array.isArray(select)) {\n throw new Error('Path must be an array or a string')\n }\n\n let acc: unknown = obj\n for (let i = 0; i < select.length; i++) {\n const segment = select[i]\n if (isIndexSegment(segment)) {\n if (!Array.isArray(acc)) {\n return defaultVal\n }\n\n acc = acc[segment]\n }\n\n if (isKeySegment(segment)) {\n if (!Array.isArray(acc)) {\n return defaultVal\n }\n\n acc = acc.find((item) => item._key === segment._key)\n }\n\n if (typeof segment === 'string') {\n acc =\n typeof acc === 'object' && acc !== null\n ? ((acc as Record<string, unknown>)[segment] as Record<string, unknown>)\n : undefined\n }\n\n if (typeof acc === 'undefined') {\n return defaultVal\n }\n }\n\n return acc\n}\n\nconst pathsMemo = new Map<string, Path>()\nexport function pathFor(path: Path): Path {\n if (path.length === 0) {\n return EMPTY_PATH\n }\n const asString = toString(path)\n if (pathsMemo.has(asString)) {\n return pathsMemo.get(asString)!\n }\n pathsMemo.set(asString, path)\n Object.freeze(path)\n return path\n}\n\nexport function isEqual(path: Path, otherPath: Path): boolean {\n return (\n path.length === otherPath.length &&\n path.every((segment, i) => isSegmentEqual(segment, otherPath[i]))\n )\n}\n\nexport function numEqualSegments(path: Path, otherPath: Path): number {\n const length = Math.min(path.length, otherPath.length)\n for (let i = 0; i < length; i++) {\n if (!isSegmentEqual(path[i], otherPath[i])) {\n return i\n }\n }\n return length\n}\n\nexport function isSegmentEqual(segmentA: PathSegment, segmentB: PathSegment): boolean {\n if (isKeySegment(segmentA) && isKeySegment(segmentB)) {\n return segmentA._key === segmentB._key\n }\n\n if (isIndexSegment(segmentA)) {\n return Number(segmentA) === Number(segmentB)\n }\n\n if (isIndexTuple(segmentA) && isIndexTuple(segmentB)) {\n return segmentA[0] === segmentB[0] && segmentA[1] === segmentB[1]\n }\n\n return segmentA === segmentB\n}\n\nexport function hasFocus(focusPath: Path, path: Path): boolean {\n const withoutTerminator =\n focusPath[focusPath.length - 1] === FOCUS_TERMINATOR ? focusPath.slice(0, -1) : focusPath\n return isEqual(withoutTerminator, path)\n}\n\nexport function hasItemFocus(focusPath: Path, item: PathSegment): boolean {\n return focusPath.length === 1 && isSegmentEqual(focusPath[0], item)\n}\n\nexport function isExpanded(segment: PathSegment, focusPath: Path): boolean {\n const [head, ...tail] = focusPath\n return tail.length > 0 && isSegmentEqual(segment, head)\n}\n\nexport function startsWith(prefix: Path, path: Path): boolean {\n return prefix.every((segment, i) => isSegmentEqual(segment, path[i]))\n}\n\nexport function trimLeft(prefix: Path, path: Path): Path {\n if (prefix.length === 0 || path.length === 0) {\n return path\n }\n const [prefixHead, ...prefixTail] = prefix\n const [pathHead, ...pathTail] = path\n if (!isSegmentEqual(prefixHead, pathHead)) {\n return path\n }\n return pathFor(trimLeft(prefixTail, pathTail))\n}\n\nexport function trimRight(suffix: Path, path: Path): Path {\n const sufLen = suffix.length\n const pathLen = path.length\n if (sufLen === 0 || pathLen === 0) {\n return path\n }\n\n let i = 0\n while (\n i < sufLen &&\n i < pathLen &&\n isSegmentEqual(path[pathLen - i - 1], suffix[sufLen - i - 1])\n ) {\n i++\n }\n\n return pathFor(path.slice(0, pathLen - i))\n}\n\nexport function trimChildPath(path: Path, childPath: Path): Path {\n return startsWith(path, childPath) ? trimLeft(path, childPath) : EMPTY_PATH\n}\n\nexport function toString(path: Path): string {\n if (!Array.isArray(path)) {\n throw new Error('Path is not an array')\n }\n\n return path.reduce<string>((target, segment, i) => {\n const isHead = i === 0\n\n if (typeof segment === 'number') {\n return `${target}[${segment}]`\n }\n\n if (typeof segment === 'string') {\n if (isHead) {\n return segment\n }\n\n if (GROQ_DATA_TYPE_VALUES.includes(segment)) {\n return `${target}[\"${segment}\"]`\n }\n\n return `${target}.${segment}`\n }\n\n if (isKeySegment(segment) && segment._key) {\n return `${target}[_key==\"${segment._key}\"]`\n }\n\n if (Array.isArray(segment)) {\n const [from, to] = segment\n return `${target}[${from}:${to}]`\n }\n\n throw new Error(`Unsupported path segment \\`${JSON.stringify(segment)}\\``)\n }, '')\n}\n\nexport function _resolveKeyedPath(value: unknown, path: Path): Path {\n if (path.length === 0) {\n return path\n }\n const [next, ...rest] = path\n if (typeof next === 'number') {\n if (!Array.isArray(value) || !(next in value)) {\n return []\n }\n const item = value[next]\n const key = item?._key\n return [typeof key === 'string' ? {_key: item._key} : next, ..._resolveKeyedPath(item, rest)]\n }\n const nextVal = get(value, [next])\n return [next, ..._resolveKeyedPath(nextVal, rest)]\n}\n\n/**\n * Takes a value and a path that may include numeric indices and attempts to replace numeric indices with keyed paths\n *\n * @param value - any json value\n * @param path - a Path that may include numeric indices\n * @returns a path where numeric indices has been replaced by keyed segments (e.g. `{_key: <key>}`)\n * Will do as good attempt as possible, but in case of missing array items, it will return the best possible match:\n * - `resolveKeyedPath([0, 'bar'], [])` will return [] since array has no value at index 0\n * - `resolveKeyedPath([0, 'foo'], [{_key: 'xyz', 'foo': 'bar'}, {_key: 'abc'}])` will return `[{_key: 'xyz'}, 'foo']` since array has no value at index 0\n * - `resolveKeyedPath([0, 'foo', 'bar'], [{_key: 'xyz'}])` will return `[{_key: 'xyz'}, 'foo', 'bar']` since array has no value at index 0\n * Object keys will be preserved as-is, e.g. `resolveKeyedPath(['foo', 'bar'], undefined)` will return `['foo', 'bar']`\n */\nexport function resolveKeyedPath(value: unknown, path: Path): Path {\n if (!Array.isArray(path)) {\n throw new Error('Path is not an array')\n }\n return pathFor(_resolveKeyedPath(value, path))\n}\n\nexport function fromString(path: string): Path {\n if (typeof path !== 'string') {\n throw new Error('Path is not a string')\n }\n\n const segments = path.match(rePropName)\n if (!segments) {\n throw new Error('Invalid path string')\n }\n\n return segments.map(normalizePathSegment)\n}\n\nfunction normalizePathSegment(segment: string): PathSegment {\n if (isIndexSegment(segment)) {\n return normalizeIndexSegment(segment)\n }\n\n if (isKeySegment(segment)) {\n return normalizeKeySegment(segment)\n }\n\n if (isIndexTuple(segment)) {\n return normalizeIndexTupleSegment(segment)\n }\n\n return segment\n}\n\nfunction normalizeIndexSegment(segment: string): PathSegment {\n return Number(segment.replace(/[^\\d]/g, ''))\n}\n\nfunction normalizeKeySegment(segment: string): KeyedSegment {\n const segments = segment.match(reKeySegment)\n return {_key: segments![1]}\n}\n\nfunction normalizeIndexTupleSegment(segment: string): IndexTuple {\n const [from, to] = segment.split(':').map((seg) => (seg === '' ? seg : Number(seg)))\n return [from, to]\n}\n"],"names":[],"mappings":";AAUA,MAAM,aACJ,oGACI,eAAe,4BACf,aAAmB,CAAA,GAEZ,mBAAmB,KAI1B,wBAAwB,CAAC,QAAQ,SAAS,MAAM;AAI/C,SAAS,IAAI,KAAc,MAAqB,YAA+B;AACpF,QAAM,SAAS,OAAO,QAAS,WAAW,WAAW,IAAI,IAAI;AAC7D,MAAI,CAAC,MAAM,QAAQ,MAAM;AACvB,UAAM,IAAI,MAAM,mCAAmC;AAGrD,MAAI,MAAe;AACnB,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,UAAM,UAAU,OAAO,CAAC;AACxB,QAAI,eAAe,OAAO,GAAG;AAC3B,UAAI,CAAC,MAAM,QAAQ,GAAG;AACpB,eAAO;AAGT,YAAM,IAAI,OAAO;AAAA,IACnB;AAEA,QAAI,aAAa,OAAO,GAAG;AACzB,UAAI,CAAC,MAAM,QAAQ,GAAG;AACpB,eAAO;AAGT,YAAM,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS,QAAQ,IAAI;AAAA,IACrD;AASA,QAPI,OAAO,WAAY,aACrB,MACE,OAAO,OAAQ,YAAY,QAAQ,OAC7B,IAAgC,OAAO,IACzC,SAGJ,OAAO,MAAQ;AACjB,aAAO;AAAA,EAEX;AAEA,SAAO;AACT;AAEA,MAAM,gCAAgB,IAAA;AACf,SAAS,QAAQ,MAAkB;AACxC,MAAI,KAAK,WAAW;AAClB,WAAO;AAET,QAAM,WAAW,SAAS,IAAI;AA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