total5 0.0.17-6 → 0.0.17-7
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/changelog.txt +1 -0
- package/global.js +1 -1
- package/package.json +1 -1
- package/utils.js +26 -1
package/changelog.txt
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
- added `PROXYSERVER(endpoint, socketendpoint, [logger])` method
|
|
17
17
|
- added `AIMODEL.tool(content, [merge])` method
|
|
18
18
|
- added `AIPARSER(provider)` method for parsing AI responses
|
|
19
|
+
- extended `String.prototype` by adding the `String.parseContext()` method to parse a specific text file format
|
|
19
20
|
|
|
20
21
|
========================
|
|
21
22
|
0.0.16
|
package/global.js
CHANGED
package/package.json
CHANGED
package/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Total.js Utils
|
|
2
2
|
// The MIT License
|
|
3
|
-
// Copyright 2012-
|
|
3
|
+
// Copyright 2012-2026 (c) Peter Širka <petersirka@gmail.com>
|
|
4
4
|
|
|
5
5
|
'use strict';
|
|
6
6
|
|
|
@@ -6051,6 +6051,31 @@ function extractnested(str, minDepth = 0) {
|
|
|
6051
6051
|
return { text: out, parts };
|
|
6052
6052
|
}
|
|
6053
6053
|
|
|
6054
|
+
SP.parseContext = function() {
|
|
6055
|
+
|
|
6056
|
+
const text = this;
|
|
6057
|
+
const REG = /-{20,}\s*\n([\s\S]*?)\n-{20,}\s*\n([\s\S]*?)(?=\n-{20,}\s*\n|$)/g;
|
|
6058
|
+
const output = [];
|
|
6059
|
+
|
|
6060
|
+
let match;
|
|
6061
|
+
|
|
6062
|
+
while ((match = REG.exec(text))) {
|
|
6063
|
+
const header = {};
|
|
6064
|
+
const body = match[2].trim();
|
|
6065
|
+
for (const line of match[1].split('\n')) {
|
|
6066
|
+
const index = line.indexOf(':');
|
|
6067
|
+
if (index === -1)
|
|
6068
|
+
continue;
|
|
6069
|
+
const key = line.substring(0, index).trim().toLowerCase();
|
|
6070
|
+
const value = line.substring(index + 1).trim();
|
|
6071
|
+
header[key] = value;
|
|
6072
|
+
}
|
|
6073
|
+
output.push({ ...header, body });
|
|
6074
|
+
}
|
|
6075
|
+
|
|
6076
|
+
return output;
|
|
6077
|
+
};
|
|
6078
|
+
|
|
6054
6079
|
SP.toJSONSchema = SP.parseSchema = function(name, url) {
|
|
6055
6080
|
|
|
6056
6081
|
let obj = {};
|