@openpeepshq/common 0.6.2 → 0.6.3

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.
@@ -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[];
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/common",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -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[] => {