@sjts/ai-shared 31.0.4 → 31.0.6
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/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -0
- package/dist/utils/makeJSONBlock.d.ts.map +1 -1
- package/dist/utils/makeJSONBlock.js +1 -86
- package/dist/utils/makeXml.d.ts +2 -0
- package/dist/utils/makeXml.d.ts.map +1 -0
- package/dist/utils/makeXml.js +9 -0
- package/dist/utils/parseJsonWithComments.d.ts +2 -0
- package/dist/utils/parseJsonWithComments.d.ts.map +1 -0
- package/dist/utils/parseJsonWithComments.js +86 -0
- package/package.json +1 -1
package/dist/utils/index.d.ts
CHANGED
|
@@ -8,9 +8,11 @@ export * from './makeH4.js';
|
|
|
8
8
|
export * from './makeJSONBlock.js';
|
|
9
9
|
export * from './makeTextBlock.js';
|
|
10
10
|
export * from './makeTypescriptBlock.js';
|
|
11
|
+
export * from './makeXml.js';
|
|
11
12
|
export * from './mdAdjustHeadings.js';
|
|
12
13
|
export * from './mergePrompts.js';
|
|
13
14
|
export * from './parseJson.js';
|
|
15
|
+
export * from './parseJsonWithComments.js';
|
|
14
16
|
export * from './promptAdjustHeadings.js';
|
|
15
17
|
export * from './textJoin.js';
|
|
16
18
|
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,cAAc,CAAA;AAC5B,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"}
|
package/dist/utils/index.js
CHANGED
|
@@ -8,9 +8,11 @@ export * from './makeH4.js';
|
|
|
8
8
|
export * from './makeJSONBlock.js';
|
|
9
9
|
export * from './makeTextBlock.js';
|
|
10
10
|
export * from './makeTypescriptBlock.js';
|
|
11
|
+
export * from './makeXml.js';
|
|
11
12
|
export * from './mdAdjustHeadings.js';
|
|
12
13
|
export * from './mergePrompts.js';
|
|
13
14
|
export * from './parseJson.js';
|
|
15
|
+
export * from './parseJsonWithComments.js';
|
|
14
16
|
export * from './promptAdjustHeadings.js';
|
|
15
17
|
export * from './textJoin.js';
|
|
16
18
|
export * from './trim.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeJSONBlock.d.ts","sourceRoot":"","sources":["../../src/utils/makeJSONBlock.ts"],"names":[],"mappings":"
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"makeXml.d.ts","sourceRoot":"","sources":["../../src/utils/makeXml.ts"],"names":[],"mappings":"AAGA,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAMpD"}
|
|
@@ -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
|
+
}
|