@real1ty-obsidian-plugins/utils 1.2.2 → 2.0.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/frontmatter-utils.d.ts +15 -0
- package/dist/frontmatter-utils.d.ts.map +1 -0
- package/dist/frontmatter-utils.js +68 -0
- package/dist/frontmatter-utils.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serializes a frontmatter value to a string representation for display in input fields.
|
|
3
|
+
* Converts arrays, objects, booleans, and numbers to their string representations.
|
|
4
|
+
*/
|
|
5
|
+
export declare function serializeFrontmatterValue(value: unknown): string;
|
|
6
|
+
/**
|
|
7
|
+
* Parses a string value back to its original frontmatter type.
|
|
8
|
+
* Detects and converts to: arrays, objects, booleans, numbers, or keeps as string.
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseFrontmatterValue(stringValue: string): unknown;
|
|
11
|
+
/**
|
|
12
|
+
* Converts a record of string values back to their original frontmatter types.
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseFrontmatterRecord(record: Record<string, string>): Record<string, unknown>;
|
|
15
|
+
//# sourceMappingURL=frontmatter-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontmatter-utils.d.ts","sourceRoot":"","sources":["../src/frontmatter-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAkBhE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAsClE;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQ9F"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serializes a frontmatter value to a string representation for display in input fields.
|
|
3
|
+
* Converts arrays, objects, booleans, and numbers to their string representations.
|
|
4
|
+
*/
|
|
5
|
+
export function serializeFrontmatterValue(value) {
|
|
6
|
+
if (value === null || value === undefined) {
|
|
7
|
+
return "";
|
|
8
|
+
}
|
|
9
|
+
if (typeof value === "string") {
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
13
|
+
return String(value);
|
|
14
|
+
}
|
|
15
|
+
if (Array.isArray(value) || typeof value === "object") {
|
|
16
|
+
return JSON.stringify(value);
|
|
17
|
+
}
|
|
18
|
+
return String(value);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Parses a string value back to its original frontmatter type.
|
|
22
|
+
* Detects and converts to: arrays, objects, booleans, numbers, or keeps as string.
|
|
23
|
+
*/
|
|
24
|
+
export function parseFrontmatterValue(stringValue) {
|
|
25
|
+
// Empty string
|
|
26
|
+
if (stringValue === "") {
|
|
27
|
+
return "";
|
|
28
|
+
}
|
|
29
|
+
// Try to parse as JSON (arrays, objects, null)
|
|
30
|
+
if ((stringValue.startsWith("[") && stringValue.endsWith("]")) ||
|
|
31
|
+
(stringValue.startsWith("{") && stringValue.endsWith("}")) ||
|
|
32
|
+
stringValue === "null") {
|
|
33
|
+
try {
|
|
34
|
+
return JSON.parse(stringValue);
|
|
35
|
+
}
|
|
36
|
+
catch (_a) {
|
|
37
|
+
// If JSON parse fails, return as string
|
|
38
|
+
return stringValue;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Parse booleans
|
|
42
|
+
if (stringValue === "true") {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (stringValue === "false") {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
// Parse numbers (including integers and floats)
|
|
49
|
+
if (/^-?\d+(\.\d+)?$/.test(stringValue)) {
|
|
50
|
+
const num = Number(stringValue);
|
|
51
|
+
if (!Number.isNaN(num)) {
|
|
52
|
+
return num;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Return as string if no other type matches
|
|
56
|
+
return stringValue;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Converts a record of string values back to their original frontmatter types.
|
|
60
|
+
*/
|
|
61
|
+
export function parseFrontmatterRecord(record) {
|
|
62
|
+
const parsed = {};
|
|
63
|
+
for (const [key, value] of Object.entries(record)) {
|
|
64
|
+
parsed[key] = parseFrontmatterValue(value);
|
|
65
|
+
}
|
|
66
|
+
return parsed;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=frontmatter-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontmatter-utils.js","sourceRoot":"","sources":["../src/frontmatter-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAC,KAAc;IACvD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC3C,OAAO,EAAE,CAAC;IACX,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC;IACd,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;QAC7D,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACvD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACtB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC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IAC5C,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * Serializes a frontmatter value to a string representation for display in input fields.\n * Converts arrays, objects, booleans, and numbers to their string representations.\n */\nexport function serializeFrontmatterValue(value: unknown): string {\n\tif (value === null || value === undefined) {\n\t\treturn \"\";\n\t}\n\n\tif (typeof value === \"string\") {\n\t\treturn value;\n\t}\n\n\tif (typeof value === \"number\" || typeof value === \"boolean\") {\n\t\treturn String(value);\n\t}\n\n\tif (Array.isArray(value) || typeof value === \"object\") {\n\t\treturn JSON.stringify(value);\n\t}\n\n\treturn String(value);\n}\n\n/**\n * Parses a string value back to its original frontmatter type.\n * Detects and converts to: arrays, objects, booleans, numbers, or keeps as string.\n */\nexport function parseFrontmatterValue(stringValue: string): unknown {\n\t// Empty string\n\tif (stringValue === \"\") {\n\t\treturn \"\";\n\t}\n\n\t// Try to parse as JSON (arrays, objects, null)\n\tif (\n\t\t(stringValue.startsWith(\"[\") && stringValue.endsWith(\"]\")) ||\n\t\t(stringValue.startsWith(\"{\") && stringValue.endsWith(\"}\")) ||\n\t\tstringValue === \"null\"\n\t) {\n\t\ttry {\n\t\t\treturn JSON.parse(stringValue);\n\t\t} catch {\n\t\t\t// If JSON parse fails, return as string\n\t\t\treturn stringValue;\n\t\t}\n\t}\n\n\t// Parse booleans\n\tif (stringValue === \"true\") {\n\t\treturn true;\n\t}\n\tif (stringValue === \"false\") {\n\t\treturn false;\n\t}\n\n\t// Parse numbers (including integers and floats)\n\tif (/^-?\\d+(\\.\\d+)?$/.test(stringValue)) {\n\t\tconst num = Number(stringValue);\n\t\tif (!Number.isNaN(num)) {\n\t\t\treturn num;\n\t\t}\n\t}\n\n\t// Return as string if no other type matches\n\treturn stringValue;\n}\n\n/**\n * Converts a record of string values back to their original frontmatter types.\n */\nexport function parseFrontmatterRecord(record: Record<string, string>): Record<string, unknown> {\n\tconst parsed: Record<string, unknown> = {};\n\n\tfor (const [key, value] of Object.entries(record)) {\n\t\tparsed[key] = parseFrontmatterValue(value);\n\t}\n\n\treturn parsed;\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./date-utils";
|
|
|
6
6
|
export * from "./evaluator-base";
|
|
7
7
|
export * from "./file-operations";
|
|
8
8
|
export * from "./file-utils";
|
|
9
|
+
export * from "./frontmatter-utils";
|
|
9
10
|
export * from "./generate";
|
|
10
11
|
export * from "./link-parser";
|
|
11
12
|
export * from "./settings-store";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./date-utils";
|
|
|
6
6
|
export * from "./evaluator-base";
|
|
7
7
|
export * from "./file-operations";
|
|
8
8
|
export * from "./file-utils";
|
|
9
|
+
export * from "./frontmatter-utils";
|
|
9
10
|
export * from "./generate";
|
|
10
11
|
export * from "./link-parser";
|
|
11
12
|
export * from "./settings-store";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC","sourcesContent":["export * from \"./async-utils\";\nexport * from \"./batch-operations\";\nexport * from \"./child-reference-utils\";\nexport * from \"./date-recurrence-utils\";\nexport * from \"./date-utils\";\nexport * from \"./evaluator-base\";\nexport * from \"./file-operations\";\nexport * from \"./file-utils\";\nexport * from \"./generate\";\nexport * from \"./link-parser\";\nexport * from \"./settings-store\";\nexport * from \"./string-utils\";\nexport * from \"./templater-utils\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC","sourcesContent":["export * from \"./async-utils\";\nexport * from \"./batch-operations\";\nexport * from \"./child-reference-utils\";\nexport * from \"./date-recurrence-utils\";\nexport * from \"./date-utils\";\nexport * from \"./evaluator-base\";\nexport * from \"./file-operations\";\nexport * from \"./file-utils\";\nexport * from \"./frontmatter-utils\";\nexport * from \"./generate\";\nexport * from \"./link-parser\";\nexport * from \"./settings-store\";\nexport * from \"./string-utils\";\nexport * from \"./templater-utils\";\n"]}
|