@real1ty-obsidian-plugins/utils 2.11.0 → 2.14.0
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/components/index.d.ts +2 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +2 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/input-managers/base.d.ts +30 -0
- package/dist/components/input-managers/base.d.ts.map +1 -0
- package/dist/components/input-managers/base.js +115 -0
- package/dist/components/input-managers/base.js.map +1 -0
- package/dist/components/input-managers/expression.d.ts +12 -0
- package/dist/components/input-managers/expression.d.ts.map +1 -0
- package/dist/components/input-managers/expression.js +56 -0
- package/dist/components/input-managers/expression.js.map +1 -0
- package/dist/components/input-managers/index.d.ts +4 -0
- package/dist/components/input-managers/index.d.ts.map +1 -0
- package/dist/components/input-managers/index.js +4 -0
- package/dist/components/input-managers/index.js.map +1 -0
- package/dist/components/input-managers/search.d.ts +6 -0
- package/dist/components/input-managers/search.d.ts.map +1 -0
- package/dist/components/input-managers/search.js +16 -0
- package/dist/components/input-managers/search.js.map +1 -0
- package/dist/core/evaluator/base.d.ts.map +1 -1
- package/dist/core/evaluator/base.js +12 -3
- package/dist/core/evaluator/base.js.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/property-renderer.d.ts +9 -0
- package/dist/core/property-renderer.d.ts.map +1 -0
- package/dist/core/property-renderer.js +42 -0
- package/dist/core/property-renderer.js.map +1 -0
- package/dist/file/file-utils.d.ts +28 -0
- package/dist/file/file-utils.d.ts.map +1 -0
- package/dist/file/file-utils.js +55 -0
- package/dist/file/file-utils.js.map +1 -0
- package/dist/file/file.d.ts +51 -1
- package/dist/file/file.d.ts.map +1 -1
- package/dist/file/file.js +69 -10
- package/dist/file/file.js.map +1 -1
- package/dist/file/index.d.ts +1 -0
- package/dist/file/index.d.ts.map +1 -1
- package/dist/file/index.js +1 -0
- package/dist/file/index.js.map +1 -1
- package/dist/file/link-parser.d.ts +28 -0
- package/dist/file/link-parser.d.ts.map +1 -1
- package/dist/file/link-parser.js +59 -0
- package/dist/file/link-parser.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/string/filename-utils.d.ts +46 -0
- package/dist/string/filename-utils.d.ts.map +1 -0
- package/dist/string/filename-utils.js +65 -0
- package/dist/string/filename-utils.js.map +1 -0
- package/dist/string/index.d.ts +1 -0
- package/dist/string/index.d.ts.map +1 -1
- package/dist/string/index.js +1 -0
- package/dist/string/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/index.ts +1 -0
- package/src/components/input-managers/base.ts +150 -0
- package/src/components/input-managers/expression.ts +92 -0
- package/src/components/input-managers/index.ts +3 -0
- package/src/components/input-managers/search.ts +25 -0
- package/src/core/evaluator/base.ts +15 -3
- package/src/core/index.ts +1 -0
- package/src/core/property-renderer.ts +62 -0
- package/src/file/file-utils.ts +67 -0
- package/src/file/file.ts +90 -8
- package/src/file/index.ts +1 -0
- package/src/file/link-parser.ts +71 -0
- package/src/index.ts +2 -0
- package/src/string/filename-utils.ts +77 -0
- package/src/string/index.ts +1 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { sanitizeFilenamePreserveSpaces } from "../file/file";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Normalizes a directory path for consistent comparison.
|
|
5
|
+
*
|
|
6
|
+
* - Trims whitespace
|
|
7
|
+
* - Removes leading and trailing slashes
|
|
8
|
+
* - Converts empty/whitespace-only strings to empty string
|
|
9
|
+
*
|
|
10
|
+
* Examples:
|
|
11
|
+
* - "tasks/" → "tasks"
|
|
12
|
+
* - "/tasks" → "tasks"
|
|
13
|
+
* - "/tasks/" → "tasks"
|
|
14
|
+
* - " tasks " → "tasks"
|
|
15
|
+
* - "" → ""
|
|
16
|
+
* - " " → ""
|
|
17
|
+
* - "tasks/homework" → "tasks/homework"
|
|
18
|
+
*/
|
|
19
|
+
export const normalizeDirectoryPath = (directory: string): string => {
|
|
20
|
+
return directory.trim().replace(/^\/+|\/+$/g, "");
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Extracts the date and suffix (everything after the date) from a physical instance filename.
|
|
25
|
+
* Physical instance format: "[title] [date]-[ZETTELID]"
|
|
26
|
+
*
|
|
27
|
+
* @param basename - The filename without extension
|
|
28
|
+
* @returns Object with dateStr and suffix, or null if no date found
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* extractDateAndSuffix("My Event 2025-01-15-ABC123") // { dateStr: "2025-01-15", suffix: "-ABC123" }
|
|
32
|
+
* extractDateAndSuffix("Invalid filename") // null
|
|
33
|
+
*/
|
|
34
|
+
export const extractDateAndSuffix = (
|
|
35
|
+
basename: string
|
|
36
|
+
): { dateStr: string; suffix: string } | null => {
|
|
37
|
+
const dateMatch = basename.match(/(\d{4}-\d{2}-\d{2})/);
|
|
38
|
+
if (!dateMatch) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const dateStr = dateMatch[1];
|
|
43
|
+
const dateIndex = basename.indexOf(dateStr);
|
|
44
|
+
const suffix = basename.substring(dateIndex + dateStr.length);
|
|
45
|
+
|
|
46
|
+
return { dateStr, suffix };
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Rebuilds a physical instance filename with a new title while preserving the date and zettel ID.
|
|
51
|
+
* Physical instance format: "[title] [date]-[ZETTELID]"
|
|
52
|
+
*
|
|
53
|
+
* @param currentBasename - Current filename without extension
|
|
54
|
+
* @param newTitle - New title (with or without zettel ID - will be stripped)
|
|
55
|
+
* @returns New filename, or null if current filename format is invalid
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* rebuildPhysicalInstanceFilename("Old Title 2025-01-15-ABC123", "New Title-XYZ789")
|
|
59
|
+
* // Returns: "New Title 2025-01-15-ABC123"
|
|
60
|
+
*/
|
|
61
|
+
export const rebuildPhysicalInstanceFilename = (
|
|
62
|
+
currentBasename: string,
|
|
63
|
+
newTitle: string
|
|
64
|
+
): string | null => {
|
|
65
|
+
const dateAndSuffix = extractDateAndSuffix(currentBasename);
|
|
66
|
+
if (!dateAndSuffix) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const { dateStr, suffix } = dateAndSuffix;
|
|
71
|
+
|
|
72
|
+
// Remove any zettel ID from the new title (just in case)
|
|
73
|
+
const newTitleClean = newTitle.replace(/-[A-Z0-9]{6}$/, "");
|
|
74
|
+
const newTitleSanitized = sanitizeFilenamePreserveSpaces(newTitleClean);
|
|
75
|
+
|
|
76
|
+
return `${newTitleSanitized} ${dateStr}${suffix}`;
|
|
77
|
+
};
|
package/src/string/index.ts
CHANGED