@sjts/ai-shared 31.0.3 → 31.0.5

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.
@@ -1,2 +1,2 @@
1
- export declare function indent(amount: number, text: string): string;
1
+ export declare function indent(text: string): string;
2
2
  //# sourceMappingURL=indent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"indent.d.ts","sourceRoot":"","sources":["../../src/utils/indent.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAMlD"}
1
+ {"version":3,"file":"indent.d.ts","sourceRoot":"","sources":["../../src/utils/indent.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,UAMlC"}
@@ -1,8 +1,8 @@
1
- export function indent(amount, text) {
1
+ export function indent(text) {
2
2
  if (!text)
3
3
  return '';
4
4
  return text
5
5
  .split('\n')
6
- .map(line => ' '.repeat(amount) + line)
6
+ .map(line => '\t' + line)
7
7
  .join('\n');
8
8
  }
@@ -11,6 +11,7 @@ export * from './makeTypescriptBlock.js';
11
11
  export * from './mdAdjustHeadings.js';
12
12
  export * from './mergePrompts.js';
13
13
  export * from './parseJson.js';
14
+ export * from './parseJsonWithComments.js';
14
15
  export * from './promptAdjustHeadings.js';
15
16
  export * from './textJoin.js';
16
17
  export * from './trim.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,0BAA0B,CAAA;AACxC,cAAc,uBAAuB,CAAA;AACrC,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,2BAA2B,CAAA;AACzC,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,0BAA0B,CAAA;AACxC,cAAc,uBAAuB,CAAA;AACrC,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,2BAA2B,CAAA;AACzC,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA"}
@@ -11,6 +11,7 @@ export * from './makeTypescriptBlock.js';
11
11
  export * from './mdAdjustHeadings.js';
12
12
  export * from './mergePrompts.js';
13
13
  export * from './parseJson.js';
14
+ export * from './parseJsonWithComments.js';
14
15
  export * from './promptAdjustHeadings.js';
15
16
  export * from './textJoin.js';
16
17
  export * from './trim.js';
@@ -1 +1 @@
1
- {"version":3,"file":"makeJSONBlock.d.ts","sourceRoot":"","sources":["../../src/utils/makeJSONBlock.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,OAAO,EAAE,GAAG,GAAG,GAAG,EAAE,EAAE,SAAS,GAAE,MAAkB,UAQhF"}
1
+ {"version":3,"file":"makeJSONBlock.d.ts","sourceRoot":"","sources":["../../src/utils/makeJSONBlock.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,CAAC,OAAO,EAAE,GAAG,GAAG,GAAG,EAAE,EAAE,SAAS,GAAE,MAAkB,UAQhF"}
@@ -1,3 +1,4 @@
1
+ import { parseJsonWithComments } from './parseJsonWithComments';
1
2
  export function makeJSONBlock(content, emptyText = 'No data') {
2
3
  return Array.isArray(content)
3
4
  ? !content?.length
@@ -7,89 +8,3 @@ export function makeJSONBlock(content, emptyText = 'No data') {
7
8
  ? emptyText
8
9
  : '```json\n' + parseJsonWithComments(content) + '\n```';
9
10
  }
10
- function isCommentObject(obj) {
11
- return (obj !== null &&
12
- typeof obj === 'object' &&
13
- '__comment' in obj &&
14
- 'value' in obj &&
15
- Object.keys(obj).length === 2);
16
- }
17
- function parseJsonWithComments(obj, indent = 0) {
18
- const indentStr = ' '.repeat(indent);
19
- const nextIndentStr = ' '.repeat(indent + 3);
20
- // Handle comment objects at the root level
21
- if (isCommentObject(obj)) {
22
- const commentLines = obj.__comment.split('\n');
23
- const comments = commentLines.map(line => `${indentStr}// ${line}`).join('\n');
24
- return comments + '\n' + parseJsonWithComments(obj.value, indent);
25
- }
26
- if (Array.isArray(obj)) {
27
- if (obj.length === 0) {
28
- return '[]';
29
- }
30
- let result = '[\n';
31
- for (let i = 0; i < obj.length; i++) {
32
- const item = obj[i];
33
- if (isCommentObject(item)) {
34
- // Add comment lines
35
- const commentLines = item.__comment.split('\n');
36
- commentLines.forEach(line => {
37
- result += `${nextIndentStr}// ${line}\n`;
38
- });
39
- // Add the actual value
40
- result += `${nextIndentStr}${parseJsonWithComments(item.value, indent + 3)}`;
41
- }
42
- else {
43
- result += `${nextIndentStr}${parseJsonWithComments(item, indent + 3)}`;
44
- }
45
- if (i < obj.length - 1) {
46
- result += ',';
47
- }
48
- result += '\n';
49
- }
50
- result += `${indentStr}]`;
51
- return result;
52
- }
53
- if (obj !== null && typeof obj === 'object') {
54
- const keys = Object.keys(obj);
55
- if (keys.length === 0) {
56
- return '{}';
57
- }
58
- let result = '{\n';
59
- const keyCount = keys.length;
60
- let processedKeys = 0;
61
- for (const key of keys) {
62
- const value = obj[key];
63
- if (isCommentObject(value)) {
64
- // Add comment lines
65
- const commentLines = value.__comment.split('\n');
66
- commentLines.forEach(line => {
67
- result += `${nextIndentStr}// ${line}\n`;
68
- });
69
- // Add the key-value pair with quoted property name
70
- result += `${nextIndentStr}${JSON.stringify(key)}: ${parseJsonWithComments(value.value, indent + 3)}`;
71
- }
72
- else {
73
- // Quote the property name for valid JSON
74
- result += `${nextIndentStr}${JSON.stringify(key)}: ${parseJsonWithComments(value, indent + 3)}`;
75
- }
76
- processedKeys++;
77
- if (processedKeys < keyCount) {
78
- result += ',';
79
- }
80
- result += '\n';
81
- }
82
- result += `${indentStr}}`;
83
- return result;
84
- }
85
- // Handle primitive values
86
- if (typeof obj === 'string') {
87
- return JSON.stringify(obj);
88
- }
89
- else if (obj === undefined) {
90
- return 'undefined';
91
- }
92
- else {
93
- return JSON.stringify(obj);
94
- }
95
- }
@@ -0,0 +1,2 @@
1
+ export declare function parseJsonWithComments(obj: any, indent?: number): string;
2
+ //# sourceMappingURL=parseJsonWithComments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseJsonWithComments.d.ts","sourceRoot":"","sources":["../../src/utils/parseJsonWithComments.ts"],"names":[],"mappings":"AAKA,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,GAAE,MAAU,GAAG,MAAM,CA2F1E"}
@@ -0,0 +1,86 @@
1
+ export function parseJsonWithComments(obj, indent = 0) {
2
+ const indentStr = ' '.repeat(indent);
3
+ const nextIndentStr = ' '.repeat(indent + 3);
4
+ // Handle comment objects at the root level
5
+ if (isCommentObject(obj)) {
6
+ const commentLines = obj.__comment.split('\n');
7
+ const comments = commentLines.map(line => `${indentStr}// ${line}`).join('\n');
8
+ return comments + '\n' + parseJsonWithComments(obj.value, indent);
9
+ }
10
+ if (Array.isArray(obj)) {
11
+ if (obj.length === 0) {
12
+ return '[]';
13
+ }
14
+ let result = '[\n';
15
+ for (let i = 0; i < obj.length; i++) {
16
+ const item = obj[i];
17
+ if (isCommentObject(item)) {
18
+ // Add comment lines
19
+ const commentLines = item.__comment.split('\n');
20
+ commentLines.forEach(line => {
21
+ result += `${nextIndentStr}// ${line}\n`;
22
+ });
23
+ // Add the actual value
24
+ result += `${nextIndentStr}${parseJsonWithComments(item.value, indent + 3)}`;
25
+ }
26
+ else {
27
+ result += `${nextIndentStr}${parseJsonWithComments(item, indent + 3)}`;
28
+ }
29
+ if (i < obj.length - 1) {
30
+ result += ',';
31
+ }
32
+ result += '\n';
33
+ }
34
+ result += `${indentStr}]`;
35
+ return result;
36
+ }
37
+ if (obj !== null && typeof obj === 'object') {
38
+ const keys = Object.keys(obj);
39
+ if (keys.length === 0) {
40
+ return '{}';
41
+ }
42
+ let result = '{\n';
43
+ const keyCount = keys.length;
44
+ let processedKeys = 0;
45
+ for (const key of keys) {
46
+ const value = obj[key];
47
+ if (isCommentObject(value)) {
48
+ // Add comment lines
49
+ const commentLines = value.__comment.split('\n');
50
+ commentLines.forEach(line => {
51
+ result += `${nextIndentStr}// ${line}\n`;
52
+ });
53
+ // Add the key-value pair with quoted property name
54
+ result += `${nextIndentStr}${JSON.stringify(key)}: ${parseJsonWithComments(value.value, indent + 3)}`;
55
+ }
56
+ else {
57
+ // Quote the property name for valid JSON
58
+ result += `${nextIndentStr}${JSON.stringify(key)}: ${parseJsonWithComments(value, indent + 3)}`;
59
+ }
60
+ processedKeys++;
61
+ if (processedKeys < keyCount) {
62
+ result += ',';
63
+ }
64
+ result += '\n';
65
+ }
66
+ result += `${indentStr}}`;
67
+ return result;
68
+ }
69
+ // Handle primitive values
70
+ if (typeof obj === 'string') {
71
+ return JSON.stringify(obj);
72
+ }
73
+ else if (obj === undefined) {
74
+ return 'undefined';
75
+ }
76
+ else {
77
+ return JSON.stringify(obj);
78
+ }
79
+ }
80
+ function isCommentObject(obj) {
81
+ return (obj !== null &&
82
+ typeof obj === 'object' &&
83
+ '__comment' in obj &&
84
+ 'value' in obj &&
85
+ Object.keys(obj).length === 2);
86
+ }
@@ -1,2 +1,2 @@
1
- export declare function trimdent(amount: number, text: string): string;
1
+ export declare function trimdent(text: string): string;
2
2
  //# sourceMappingURL=trimdent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"trimdent.d.ts","sourceRoot":"","sources":["../../src/utils/trimdent.ts"],"names":[],"mappings":"AAGA,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAEpD"}
1
+ {"version":3,"file":"trimdent.d.ts","sourceRoot":"","sources":["../../src/utils/trimdent.ts"],"names":[],"mappings":"AAGA,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,UAEpC"}
@@ -1,5 +1,5 @@
1
1
  import { indent } from './indent';
2
2
  import { trim } from './trim';
3
- export function trimdent(amount, text) {
4
- return indent(amount, trim(text));
3
+ export function trimdent(text) {
4
+ return indent(trim(text));
5
5
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sjts/ai-shared",
3
3
  "description": "The Steve James Typescript AI Shared package",
4
- "version": "31.0.3",
4
+ "version": "31.0.5",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",