@arbor-css/util 0.0.109 → 0.0.111

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/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './convertStructure.js';
2
2
  export * from './deepMerge.js';
3
3
  export * from './keys.js';
4
+ export * from './replaceTopLevelTerms.js';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,2BAA2B,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './convertStructure.js';
2
2
  export * from './deepMerge.js';
3
3
  export * from './keys.js';
4
+ export * from './replaceTopLevelTerms.js';
4
5
  //# 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,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,2BAA2B,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Generalized util for walking through a string and
3
+ * finding (and replacing) "terms" - substrings separated
4
+ * by whitespace, but respecting parentheses. So for example, with input
5
+ *`foo(bar(baz)) qux (a b)`
6
+ * you would visit `foo(bar(baz))`, `qux`, and `(a b)`.
7
+ */
8
+ export declare function replaceTopLevelTerms(input: string, replacer: (term: string) => string): string;
9
+ //# sourceMappingURL=replaceTopLevelTerms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replaceTopLevelTerms.d.ts","sourceRoot":"","sources":["../src/replaceTopLevelTerms.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAChC,MAAM,CA8BR"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Generalized util for walking through a string and
3
+ * finding (and replacing) "terms" - substrings separated
4
+ * by whitespace, but respecting parentheses. So for example, with input
5
+ *`foo(bar(baz)) qux (a b)`
6
+ * you would visit `foo(bar(baz))`, `qux`, and `(a b)`.
7
+ */
8
+ export function replaceTopLevelTerms(input, replacer) {
9
+ let result = '';
10
+ let currentTerm = '';
11
+ let parenDepth = 0;
12
+ for (let i = 0; i < input.length; i++) {
13
+ const char = input[i];
14
+ if (char === '(') {
15
+ parenDepth++;
16
+ currentTerm += char;
17
+ }
18
+ else if (char === ')') {
19
+ parenDepth--;
20
+ currentTerm += char;
21
+ }
22
+ else if (/\s/.test(char) && parenDepth === 0) {
23
+ if (currentTerm) {
24
+ result += replacer(currentTerm);
25
+ currentTerm = '';
26
+ }
27
+ result += char; // preserve whitespace
28
+ }
29
+ else {
30
+ currentTerm += char;
31
+ }
32
+ }
33
+ if (currentTerm) {
34
+ result += replacer(currentTerm);
35
+ }
36
+ return result;
37
+ }
38
+ //# sourceMappingURL=replaceTopLevelTerms.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replaceTopLevelTerms.js","sourceRoot":"","sources":["../src/replaceTopLevelTerms.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CACnC,KAAa,EACb,QAAkC;IAElC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,WAAW,GAAG,EAAE,CAAC;IACrB,IAAI,UAAU,GAAG,CAAC,CAAC;IAEnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAEtB,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YAClB,UAAU,EAAE,CAAC;YACb,WAAW,IAAI,IAAI,CAAC;QACrB,CAAC;aAAM,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACzB,UAAU,EAAE,CAAC;YACb,WAAW,IAAI,IAAI,CAAC;QACrB,CAAC;aAAM,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;YAChD,IAAI,WAAW,EAAE,CAAC;gBACjB,MAAM,IAAI,QAAQ,CAAC,WAAW,CAAC,CAAC;gBAChC,WAAW,GAAG,EAAE,CAAC;YAClB,CAAC;YACD,MAAM,IAAI,IAAI,CAAC,CAAC,sBAAsB;QACvC,CAAC;aAAM,CAAC;YACP,WAAW,IAAI,IAAI,CAAC;QACrB,CAAC;IACF,CAAC;IAED,IAAI,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,QAAQ,CAAC,WAAW,CAAC,CAAC;IACjC,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=replaceTopLevelTerms.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replaceTopLevelTerms.test.d.ts","sourceRoot":"","sources":["../src/replaceTopLevelTerms.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ import { expect, it } from 'vitest';
2
+ import { replaceTopLevelTerms } from './replaceTopLevelTerms.js';
3
+ it('replaces top-level terms in a string', () => {
4
+ const input = 'foo(bar( baz )) qux (a b)';
5
+ const result = replaceTopLevelTerms(input, (term) => `<<${term}>>`);
6
+ expect(result).toBe('<<foo(bar( baz ))>> <<qux>> <<(a b)>>');
7
+ });
8
+ it('preserves whitespace', () => {
9
+ const input = ' foo bar ';
10
+ const result = replaceTopLevelTerms(input, (term) => `<<${term}>>`);
11
+ expect(result).toBe(' <<foo>> <<bar>> ');
12
+ });
13
+ it('handles empty input', () => {
14
+ const input = '';
15
+ const result = replaceTopLevelTerms(input, (term) => `<<${term}>>`);
16
+ expect(result).toBe('');
17
+ });
18
+ //# sourceMappingURL=replaceTopLevelTerms.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replaceTopLevelTerms.test.js","sourceRoot":"","sources":["../src/replaceTopLevelTerms.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;IAC/C,MAAM,KAAK,GAAG,2BAA2B,CAAC;IAC1C,MAAM,MAAM,GAAG,oBAAoB,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC;IACpE,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;AAC9D,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,sBAAsB,EAAE,GAAG,EAAE;IAC/B,MAAM,KAAK,GAAG,eAAe,CAAC;IAC9B,MAAM,MAAM,GAAG,oBAAoB,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC;IACpE,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;AAC9C,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,qBAAqB,EAAE,GAAG,EAAE;IAC9B,MAAM,KAAK,GAAG,EAAE,CAAC;IACjB,MAAM,MAAM,GAAG,oBAAoB,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC;IACpE,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACzB,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arbor-css/util",
3
- "version": "0.0.109",
3
+ "version": "0.0.111",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -28,11 +28,14 @@
28
28
  "sideEffects": false,
29
29
  "devDependencies": {
30
30
  "@types/node": "^25.9.1",
31
- "typescript": "^6.0.3"
31
+ "typescript": "^6.0.3",
32
+ "vitest": "^4.1.7"
32
33
  },
33
34
  "dependencies": {},
34
35
  "scripts": {
35
36
  "build": "tsc",
36
- "dev": "tsc -w --preserveWatchOutput"
37
+ "dev": "tsc -w --preserveWatchOutput",
38
+ "test": "vitest",
39
+ "test:ci": "vitest --run"
37
40
  }
38
41
  }