@frontmcp/uipack 1.10.8 → 1.10.9-rc.2

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,66 +1 @@
1
- // libs/uipack/src/utils/index.ts
2
- function safeStringify(value, space) {
3
- const seen = /* @__PURE__ */ new WeakSet();
4
- try {
5
- return JSON.stringify(
6
- value,
7
- (_key, val) => {
8
- if (typeof val === "object" && val !== null) {
9
- if (seen.has(val)) return "[Circular]";
10
- seen.add(val);
11
- }
12
- return val;
13
- },
14
- space
15
- );
16
- } catch {
17
- return JSON.stringify({ error: "Output could not be serialized" });
18
- }
19
- }
20
- function escapeHtml(str) {
21
- if (str === null || str === void 0) {
22
- return "";
23
- }
24
- const s = String(str);
25
- return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
26
- }
27
- function escapeHtmlAttr(str) {
28
- return str.replace(/&/g, "&amp;").replace(/"/g, "&quot;");
29
- }
30
- function escapeJsString(str) {
31
- return str.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
32
- }
33
- function escapeScriptClose(jsonString) {
34
- return jsonString.replace(/<\//g, "<\\/");
35
- }
36
- var SCRIPT_UNSAFE_CHARACTERS = /[<>&\u2028\u2029]/g;
37
- function toUnicodeEscape(character) {
38
- return `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`;
39
- }
40
- function safeJsonForScript(value) {
41
- if (value === void 0) {
42
- return "null";
43
- }
44
- try {
45
- const jsonString = JSON.stringify(value, (_key, val) => {
46
- if (typeof val === "bigint") {
47
- return val.toString();
48
- }
49
- return val;
50
- });
51
- if (jsonString === void 0) {
52
- return "null";
53
- }
54
- return jsonString.replace(SCRIPT_UNSAFE_CHARACTERS, toUnicodeEscape);
55
- } catch {
56
- return '{"error":"Value could not be serialized"}';
57
- }
58
- }
59
- export {
60
- escapeHtml,
61
- escapeHtmlAttr,
62
- escapeJsString,
63
- escapeScriptClose,
64
- safeJsonForScript,
65
- safeStringify
66
- };
1
+ function safeStringify(value,space){const seen=new WeakSet;try{return JSON.stringify(value,(_key,val)=>{if(typeof val==="object"&&val!==null){if(seen.has(val))return"[Circular]";seen.add(val)}return val},space)}catch{return JSON.stringify({error:"Output could not be serialized"})}}function escapeHtml(str){if(str===null||str===void 0){return""}const s=String(str);return s.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function escapeHtmlAttr(str){return str.replace(/&/g,"&amp;").replace(/"/g,"&quot;")}function escapeJsString(str){return str.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function escapeScriptClose(jsonString){return jsonString.replace(/<\//g,"<\\/")}var SCRIPT_UNSAFE_CHARACTERS=/[<>&\u2028\u2029]/g;function toUnicodeEscape(character){return`\\u${character.charCodeAt(0).toString(16).padStart(4,"0")}`}function safeJsonForScript(value){if(value===void 0){return"null"}try{const jsonString=JSON.stringify(value,(_key,val)=>{if(typeof val==="bigint"){return val.toString()}return val});if(jsonString===void 0){return"null"}return jsonString.replace(SCRIPT_UNSAFE_CHARACTERS,toUnicodeEscape)}catch{return'{"error":"Value could not be serialized"}'}}export{escapeHtml,escapeHtmlAttr,escapeJsString,escapeScriptClose,safeJsonForScript,safeStringify};