@arbor-css/util 0.0.1 → 0.0.2

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,8 @@
1
+ /**
2
+ * Walk an object structure and convert matching items using the supplied
3
+ * function.
4
+ */
5
+ export declare function convertStructure<In, Out>(input: any, matchConvertedItem: (item: any, path: (string | number)[]) => item is In, convert: (item: In, path: (string | number)[]) => Out, { path, ...options }?: {
6
+ path?: (string | number)[];
7
+ }): any;
8
+ //# sourceMappingURL=convertStructure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertStructure.d.ts","sourceRoot":"","sources":["../src/convertStructure.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,GAAG,EACvC,KAAK,EAAE,GAAG,EACV,kBAAkB,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,KAAK,IAAI,IAAI,EAAE,EACxE,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,KAAK,GAAG,EACrD,EACC,IAAS,EACT,GAAG,OAAO,EACV,GAAE;IACF,IAAI,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;CACtB,GACJ,GAAG,CAuBL"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Walk an object structure and convert matching items using the supplied
3
+ * function.
4
+ */
5
+ export function convertStructure(input, matchConvertedItem, convert, { path = [], ...options } = {}) {
6
+ path ?? (path = []);
7
+ if (matchConvertedItem(input, path)) {
8
+ return convert(input, path);
9
+ }
10
+ else if (Array.isArray(input)) {
11
+ return input.map((item, index) => convertStructure(item, matchConvertedItem, convert, {
12
+ path: [...path, index],
13
+ ...options,
14
+ }));
15
+ }
16
+ else if (typeof input === 'object' && input !== null) {
17
+ const output = {};
18
+ for (const key in input) {
19
+ output[key] = convertStructure(input[key], matchConvertedItem, convert, {
20
+ path: [...path, key],
21
+ ...options,
22
+ });
23
+ }
24
+ return output;
25
+ }
26
+ else {
27
+ return input;
28
+ }
29
+ }
30
+ //# sourceMappingURL=convertStructure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertStructure.js","sourceRoot":"","sources":["../src/convertStructure.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC/B,KAAU,EACV,kBAAwE,EACxE,OAAqD,EACrD,EACC,IAAI,GAAG,EAAE,EACT,GAAG,OAAO,KAGP,EAAE;IAEN,IAAI,KAAJ,IAAI,GAAK,EAAE,EAAC;IACZ,IAAI,kBAAkB,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;QACrC,OAAO,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC7B,CAAC;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAChC,gBAAgB,CAAC,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE;YACnD,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC;YACtB,GAAG,OAAO;SACV,CAAC,CACF,CAAC;IACH,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACxD,MAAM,MAAM,GAAwB,EAAE,CAAC;QACvC,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,kBAAkB,EAAE,OAAO,EAAE;gBACvE,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC;gBACpB,GAAG,OAAO;aACV,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAC;SAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,15 +1,3 @@
1
- /**
2
- * Converts a nested object to a flat mapping of
3
- * concatenated keys to values. Pass a check to decide
4
- * when to stop recursing.
5
- */
6
- export declare function toFlatKeys<V = any>(obj: Record<string, any>, stop?: (value: any) => boolean, options?: {
7
- separator?: string;
8
- }, prefix?: string): Record<string, V>;
9
- /**
10
- * Takes a key like "action-primary-fg" and looks it up from a nested object.
11
- * We don't necessarily know if a - is part of the next key or a separator,
12
- * so we first try to find the longest matching key and then work our way down until we find a match or run out of keys.
13
- */
14
- export declare function getByConcatKey(obj: Record<string, any>, concatKey: string, separator?: string): any;
1
+ export * from './convertStructure.js';
2
+ export * from './keys.js';
15
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,GAAG,GAAG,EACjC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACxB,IAAI,GAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OACsB,EAC5C,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,EACpC,MAAM,SAAK,GACT,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAanB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC7B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACxB,SAAS,EAAE,MAAM,EACjB,SAAS,SAAM,GACb,GAAG,CAeL"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -1,43 +1,3 @@
1
- /**
2
- * Converts a nested object to a flat mapping of
3
- * concatenated keys to values. Pass a check to decide
4
- * when to stop recursing.
5
- */
6
- export function toFlatKeys(obj, stop = (value) => typeof value !== 'object' || value === null, options = {}, prefix = '') {
7
- const flatObj = {};
8
- const separator = options.separator ?? '-';
9
- for (const key in obj) {
10
- const value = obj[key];
11
- const flatKey = prefix ? `${prefix}${separator}${key}` : key;
12
- if (!stop(value)) {
13
- Object.assign(flatObj, toFlatKeys(value, stop, options, flatKey));
14
- }
15
- else {
16
- flatObj[flatKey] = value;
17
- }
18
- }
19
- return flatObj;
20
- }
21
- /**
22
- * Takes a key like "action-primary-fg" and looks it up from a nested object.
23
- * We don't necessarily know if a - is part of the next key or a separator,
24
- * so we first try to find the longest matching key and then work our way down until we find a match or run out of keys.
25
- */
26
- export function getByConcatKey(obj, concatKey, separator = '-') {
27
- const parts = concatKey.split(separator);
28
- for (let i = parts.length; i > 0; i--) {
29
- const key = parts.slice(0, i).join(separator);
30
- if (key in obj) {
31
- const value = obj[key];
32
- if (i === parts.length) {
33
- return value;
34
- }
35
- else if (typeof value === 'object' && value !== null) {
36
- const restKey = parts.slice(i).join(separator);
37
- return getByConcatKey(value, restKey, separator);
38
- }
39
- }
40
- }
41
- return undefined;
42
- }
1
+ export * from './convertStructure.js';
2
+ export * from './keys.js';
43
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,UAAU,CACzB,GAAwB,EACxB,OAAgC,CAAC,KAAK,EAAE,EAAE,CACzC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAC5C,UAAkC,EAAE,EACpC,MAAM,GAAG,EAAE;IAEX,MAAM,OAAO,GAAsB,EAAE,CAAC;IACtC,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,GAAG,CAAC;IAC3C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AAC,CAAC;gBAC/C,OAAO,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;YAClD,CAAC;QACF,CAAC;IACF,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC"}
package/dist/keys.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Converts a nested object to a flat mapping of
3
+ * concatenated keys to values. Pass a check to decide
4
+ * when to stop recursing.
5
+ */
6
+ export declare function toFlatKeys<V = any>(obj: Record<string, any>, stop?: (value: any) => boolean, options?: {
7
+ separator?: string;
8
+ }, prefix?: string): Record<string, V>;
9
+ /**
10
+ * Takes a key like "action-primary-fg" and looks it up from a nested object.
11
+ * We don't necessarily know if a - is part of the next key or a separator,
12
+ * so we first try to find the longest matching key and then work our way down until we find a match or run out of keys.
13
+ */
14
+ export declare function getByConcatKey(obj: Record<string, any>, concatKey: string, separator?: string): any;
15
+ //# sourceMappingURL=keys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,GAAG,GAAG,EACjC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACxB,IAAI,GAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OACsB,EAC5C,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,EACpC,MAAM,SAAK,GACT,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAanB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC7B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACxB,SAAS,EAAE,MAAM,EACjB,SAAS,SAAM,GACb,GAAG,CAeL"}
package/dist/keys.js ADDED
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Converts a nested object to a flat mapping of
3
+ * concatenated keys to values. Pass a check to decide
4
+ * when to stop recursing.
5
+ */
6
+ export function toFlatKeys(obj, stop = (value) => typeof value !== 'object' || value === null, options = {}, prefix = '') {
7
+ const flatObj = {};
8
+ const separator = options.separator ?? '-';
9
+ for (const key in obj) {
10
+ const value = obj[key];
11
+ const flatKey = prefix ? `${prefix}${separator}${key}` : key;
12
+ if (!stop(value)) {
13
+ Object.assign(flatObj, toFlatKeys(value, stop, options, flatKey));
14
+ }
15
+ else {
16
+ flatObj[flatKey] = value;
17
+ }
18
+ }
19
+ return flatObj;
20
+ }
21
+ /**
22
+ * Takes a key like "action-primary-fg" and looks it up from a nested object.
23
+ * We don't necessarily know if a - is part of the next key or a separator,
24
+ * so we first try to find the longest matching key and then work our way down until we find a match or run out of keys.
25
+ */
26
+ export function getByConcatKey(obj, concatKey, separator = '-') {
27
+ const parts = concatKey.split(separator);
28
+ for (let i = parts.length; i > 0; i--) {
29
+ const key = parts.slice(0, i).join(separator);
30
+ if (key in obj) {
31
+ const value = obj[key];
32
+ if (i === parts.length) {
33
+ return value;
34
+ }
35
+ else if (typeof value === 'object' && value !== null) {
36
+ const restKey = parts.slice(i).join(separator);
37
+ return getByConcatKey(value, restKey, separator);
38
+ }
39
+ }
40
+ }
41
+ return undefined;
42
+ }
43
+ //# sourceMappingURL=keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,UAAU,CACzB,GAAwB,EACxB,OAAgC,CAAC,KAAK,EAAE,EAAE,CACzC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAC5C,UAAkC,EAAE,EACpC,MAAM,GAAG,EAAE;IAEX,MAAM,OAAO,GAAsB,EAAE,CAAC;IACtC,MAAM,SAAS,GAAG,OAAO,CA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C,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBAC/C,OAAO,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;YAClD,CAAC;QACF,CAAC;IACF,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC"}
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@arbor-css/util",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
+ "repository": {
9
+ "url": "https://github.com/a-type/arbor"
10
+ },
8
11
  "files": [
9
12
  "dist"
10
13
  ],