@openpeepshq/common 0.6.2 → 0.6.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.
- package/dist/lib/eventTime.d.ts +6 -0
- package/dist/lib/eventTime.js +10 -0
- package/dist/lib/resources.d.ts +9 -0
- package/dist/lib/resources.js +13 -0
- package/package.json +1 -1
- package/src/lib/eventTime.ts +15 -0
- package/src/lib/resources.ts +19 -0
package/dist/lib/eventTime.d.ts
CHANGED
|
@@ -16,6 +16,12 @@ export declare const reinterpretIsoInTimeZone: (iso: string | undefined, fromTim
|
|
|
16
16
|
export declare const utcIsoToWallClockDate: (iso: string, timeZone: string) => Date;
|
|
17
17
|
/** Treat `date`'s local components as wall time in `timeZone`. */
|
|
18
18
|
export declare const wallClockDateToUtcIso: (date: Date, timeZone: string) => string;
|
|
19
|
+
/**
|
|
20
|
+
* Zone to display an event in: the viewer's zone wins, the event zone is the
|
|
21
|
+
* last resort. `undefined` means no resolvable zone — formatters fall through
|
|
22
|
+
* to the ambient device zone.
|
|
23
|
+
*/
|
|
24
|
+
export declare const eventDisplayTimeZone: (eventTimeZone?: string | null, viewerTimeZone?: string | null) => string | undefined;
|
|
19
25
|
/** Intl `timeZone` option when `timeZone` is a valid IANA identifier. */
|
|
20
26
|
export declare const eventTimeZoneOptions: (timeZone?: string | null) => Pick<Intl.DateTimeFormatOptions, "timeZone">;
|
|
21
27
|
/** Clock time in the event timezone, always including a short zone name. */
|
package/dist/lib/eventTime.js
CHANGED
|
@@ -98,6 +98,16 @@ export const wallClockDateToUtcIso = (date, timeZone) => {
|
|
|
98
98
|
const local = `${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}T${pad2(date.getHours())}:${pad2(date.getMinutes())}`;
|
|
99
99
|
return zonedDateTimeToUtcIso(local, timeZone) ?? date.toISOString();
|
|
100
100
|
};
|
|
101
|
+
/**
|
|
102
|
+
* Zone to display an event in: the viewer's zone wins, the event zone is the
|
|
103
|
+
* last resort. `undefined` means no resolvable zone — formatters fall through
|
|
104
|
+
* to the ambient device zone.
|
|
105
|
+
*/
|
|
106
|
+
export const eventDisplayTimeZone = (eventTimeZone, viewerTimeZone) => isIanaTimeZone(viewerTimeZone)
|
|
107
|
+
? viewerTimeZone
|
|
108
|
+
: isIanaTimeZone(eventTimeZone)
|
|
109
|
+
? eventTimeZone
|
|
110
|
+
: undefined;
|
|
101
111
|
/** Intl `timeZone` option when `timeZone` is a valid IANA identifier. */
|
|
102
112
|
export const eventTimeZoneOptions = (timeZone) => {
|
|
103
113
|
const resolved = isIanaTimeZone(timeZone) ? timeZone : undefined;
|
package/dist/lib/resources.d.ts
CHANGED
|
@@ -41,4 +41,13 @@ export type CategoryNode = {
|
|
|
41
41
|
};
|
|
42
42
|
export declare const categoryTreeFromPaths: (paths: readonly (readonly string[])[]) => CategoryNode[];
|
|
43
43
|
export declare const pathStartsWith: (path: readonly string[], prefix: readonly string[]) => boolean;
|
|
44
|
+
/** Returns an injective key for a category path. Uses `JSON.stringify` so that
|
|
45
|
+
* a folder named `A/B` (single segment `["A/B"]`) never collides with
|
|
46
|
+
* folder `A` containing subfolder `B` (`["A","B"]`).
|
|
47
|
+
*/
|
|
48
|
+
export declare const categoryPathKey: (path: readonly string[]) => string;
|
|
49
|
+
/** Validates that no segment of a category path is blank or whitespace-only.
|
|
50
|
+
* Returns `true` for `undefined` (absent — not a validation error).
|
|
51
|
+
*/
|
|
52
|
+
export declare const validResourceCategoryPath: (path: readonly string[] | undefined) => boolean;
|
|
44
53
|
export declare const normalizeResourceTags: (tags: readonly string[] | undefined) => string[];
|
package/dist/lib/resources.js
CHANGED
|
@@ -122,6 +122,19 @@ export const categoryTreeFromPaths = (paths) => {
|
|
|
122
122
|
};
|
|
123
123
|
export const pathStartsWith = (path, prefix) => prefix.length <= path.length &&
|
|
124
124
|
prefix.every((segment, index) => path[index] === segment);
|
|
125
|
+
/** Returns an injective key for a category path. Uses `JSON.stringify` so that
|
|
126
|
+
* a folder named `A/B` (single segment `["A/B"]`) never collides with
|
|
127
|
+
* folder `A` containing subfolder `B` (`["A","B"]`).
|
|
128
|
+
*/
|
|
129
|
+
export const categoryPathKey = (path) => JSON.stringify(path);
|
|
130
|
+
/** Validates that no segment of a category path is blank or whitespace-only.
|
|
131
|
+
* Returns `true` for `undefined` (absent — not a validation error).
|
|
132
|
+
*/
|
|
133
|
+
export const validResourceCategoryPath = (path) => {
|
|
134
|
+
if (!path)
|
|
135
|
+
return true;
|
|
136
|
+
return path.every((segment) => segment.trim().length > 0 && segment === segment.trim());
|
|
137
|
+
};
|
|
125
138
|
export const normalizeResourceTags = (tags) => {
|
|
126
139
|
const seen = new Set();
|
|
127
140
|
const out = [];
|
package/package.json
CHANGED
package/src/lib/eventTime.ts
CHANGED
|
@@ -136,6 +136,21 @@ export const wallClockDateToUtcIso = (date: Date, timeZone: string): string => {
|
|
|
136
136
|
return zonedDateTimeToUtcIso(local, timeZone) ?? date.toISOString();
|
|
137
137
|
};
|
|
138
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Zone to display an event in: the viewer's zone wins, the event zone is the
|
|
141
|
+
* last resort. `undefined` means no resolvable zone — formatters fall through
|
|
142
|
+
* to the ambient device zone.
|
|
143
|
+
*/
|
|
144
|
+
export const eventDisplayTimeZone = (
|
|
145
|
+
eventTimeZone?: string | null,
|
|
146
|
+
viewerTimeZone?: string | null,
|
|
147
|
+
): string | undefined =>
|
|
148
|
+
isIanaTimeZone(viewerTimeZone)
|
|
149
|
+
? viewerTimeZone
|
|
150
|
+
: isIanaTimeZone(eventTimeZone)
|
|
151
|
+
? eventTimeZone
|
|
152
|
+
: undefined;
|
|
153
|
+
|
|
139
154
|
/** Intl `timeZone` option when `timeZone` is a valid IANA identifier. */
|
|
140
155
|
export const eventTimeZoneOptions = (
|
|
141
156
|
timeZone?: string | null,
|
package/src/lib/resources.ts
CHANGED
|
@@ -176,6 +176,25 @@ export const pathStartsWith = (
|
|
|
176
176
|
prefix.length <= path.length &&
|
|
177
177
|
prefix.every((segment, index) => path[index] === segment);
|
|
178
178
|
|
|
179
|
+
/** Returns an injective key for a category path. Uses `JSON.stringify` so that
|
|
180
|
+
* a folder named `A/B` (single segment `["A/B"]`) never collides with
|
|
181
|
+
* folder `A` containing subfolder `B` (`["A","B"]`).
|
|
182
|
+
*/
|
|
183
|
+
export const categoryPathKey = (path: readonly string[]): string =>
|
|
184
|
+
JSON.stringify(path);
|
|
185
|
+
|
|
186
|
+
/** Validates that no segment of a category path is blank or whitespace-only.
|
|
187
|
+
* Returns `true` for `undefined` (absent — not a validation error).
|
|
188
|
+
*/
|
|
189
|
+
export const validResourceCategoryPath = (
|
|
190
|
+
path: readonly string[] | undefined,
|
|
191
|
+
): boolean => {
|
|
192
|
+
if (!path) return true;
|
|
193
|
+
return path.every(
|
|
194
|
+
(segment) => segment.trim().length > 0 && segment === segment.trim(),
|
|
195
|
+
);
|
|
196
|
+
};
|
|
197
|
+
|
|
179
198
|
export const normalizeResourceTags = (
|
|
180
199
|
tags: readonly string[] | undefined,
|
|
181
200
|
): string[] => {
|