@agentmark-ai/shared-utils 0.5.0 → 0.5.1
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.js +5 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -34
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -71,53 +71,24 @@ function hexToBytes(hex) {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
// src/serialize.ts
|
|
74
|
+
import yaml from "js-yaml";
|
|
74
75
|
function toFrontMatter(content) {
|
|
75
|
-
|
|
76
|
-
let frontMatter = "";
|
|
77
|
-
const indentation = " ".repeat(indent);
|
|
78
|
-
for (const key in json) {
|
|
79
|
-
if (Object.prototype.hasOwnProperty.call(json, key)) {
|
|
80
|
-
const value = json[key];
|
|
81
|
-
if (typeof value === "object" && !Array.isArray(value)) {
|
|
82
|
-
frontMatter += `${indentation}${key}:
|
|
83
|
-
`;
|
|
84
|
-
frontMatter += jsonToFrontMatter(value, indent + 1);
|
|
85
|
-
} else if (Array.isArray(value)) {
|
|
86
|
-
frontMatter += `${indentation}${key}:
|
|
87
|
-
`;
|
|
88
|
-
value.forEach((item) => {
|
|
89
|
-
if (typeof item === "object") {
|
|
90
|
-
frontMatter += `${indentation}-
|
|
91
|
-
`;
|
|
92
|
-
frontMatter += jsonToFrontMatter(item, indent + 2);
|
|
93
|
-
} else {
|
|
94
|
-
frontMatter += `${indentation}- ${item}
|
|
95
|
-
`;
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
} else {
|
|
99
|
-
frontMatter += `${indentation}${key}: ${value}
|
|
100
|
-
`;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return frontMatter;
|
|
105
|
-
}
|
|
76
|
+
const body = Object.keys(content).length === 0 ? "" : yaml.dump(content, { lineWidth: -1, noRefs: true, skipInvalid: true });
|
|
106
77
|
return `---
|
|
107
|
-
${
|
|
78
|
+
${body}---
|
|
108
79
|
`;
|
|
109
80
|
}
|
|
110
81
|
|
|
111
82
|
// src/generate-types.ts
|
|
112
83
|
import * as fs from "fs-extra";
|
|
113
84
|
import path from "path";
|
|
114
|
-
import
|
|
85
|
+
import yaml2 from "js-yaml";
|
|
115
86
|
function extractFrontmatter(content) {
|
|
116
87
|
const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
117
88
|
if (!match) {
|
|
118
89
|
return { attributes: {} };
|
|
119
90
|
}
|
|
120
|
-
const attributes =
|
|
91
|
+
const attributes = yaml2.load(match[1]);
|
|
121
92
|
return { attributes: attributes || {} };
|
|
122
93
|
}
|
|
123
94
|
var _compile = null;
|