@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.
Files changed (75) hide show
  1. package/dist/components/index.d.ts +2 -0
  2. package/dist/components/index.d.ts.map +1 -0
  3. package/dist/components/index.js +2 -0
  4. package/dist/components/index.js.map +1 -0
  5. package/dist/components/input-managers/base.d.ts +30 -0
  6. package/dist/components/input-managers/base.d.ts.map +1 -0
  7. package/dist/components/input-managers/base.js +115 -0
  8. package/dist/components/input-managers/base.js.map +1 -0
  9. package/dist/components/input-managers/expression.d.ts +12 -0
  10. package/dist/components/input-managers/expression.d.ts.map +1 -0
  11. package/dist/components/input-managers/expression.js +56 -0
  12. package/dist/components/input-managers/expression.js.map +1 -0
  13. package/dist/components/input-managers/index.d.ts +4 -0
  14. package/dist/components/input-managers/index.d.ts.map +1 -0
  15. package/dist/components/input-managers/index.js +4 -0
  16. package/dist/components/input-managers/index.js.map +1 -0
  17. package/dist/components/input-managers/search.d.ts +6 -0
  18. package/dist/components/input-managers/search.d.ts.map +1 -0
  19. package/dist/components/input-managers/search.js +16 -0
  20. package/dist/components/input-managers/search.js.map +1 -0
  21. package/dist/core/evaluator/base.d.ts.map +1 -1
  22. package/dist/core/evaluator/base.js +12 -3
  23. package/dist/core/evaluator/base.js.map +1 -1
  24. package/dist/core/index.d.ts +1 -0
  25. package/dist/core/index.d.ts.map +1 -1
  26. package/dist/core/index.js +1 -0
  27. package/dist/core/index.js.map +1 -1
  28. package/dist/core/property-renderer.d.ts +9 -0
  29. package/dist/core/property-renderer.d.ts.map +1 -0
  30. package/dist/core/property-renderer.js +42 -0
  31. package/dist/core/property-renderer.js.map +1 -0
  32. package/dist/file/file-utils.d.ts +28 -0
  33. package/dist/file/file-utils.d.ts.map +1 -0
  34. package/dist/file/file-utils.js +55 -0
  35. package/dist/file/file-utils.js.map +1 -0
  36. package/dist/file/file.d.ts +51 -1
  37. package/dist/file/file.d.ts.map +1 -1
  38. package/dist/file/file.js +69 -10
  39. package/dist/file/file.js.map +1 -1
  40. package/dist/file/index.d.ts +1 -0
  41. package/dist/file/index.d.ts.map +1 -1
  42. package/dist/file/index.js +1 -0
  43. package/dist/file/index.js.map +1 -1
  44. package/dist/file/link-parser.d.ts +28 -0
  45. package/dist/file/link-parser.d.ts.map +1 -1
  46. package/dist/file/link-parser.js +59 -0
  47. package/dist/file/link-parser.js.map +1 -1
  48. package/dist/index.d.ts +1 -0
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +2 -0
  51. package/dist/index.js.map +1 -1
  52. package/dist/string/filename-utils.d.ts +46 -0
  53. package/dist/string/filename-utils.d.ts.map +1 -0
  54. package/dist/string/filename-utils.js +65 -0
  55. package/dist/string/filename-utils.js.map +1 -0
  56. package/dist/string/index.d.ts +1 -0
  57. package/dist/string/index.d.ts.map +1 -1
  58. package/dist/string/index.js +1 -0
  59. package/dist/string/index.js.map +1 -1
  60. package/package.json +1 -1
  61. package/src/components/index.ts +1 -0
  62. package/src/components/input-managers/base.ts +150 -0
  63. package/src/components/input-managers/expression.ts +92 -0
  64. package/src/components/input-managers/index.ts +3 -0
  65. package/src/components/input-managers/search.ts +25 -0
  66. package/src/core/evaluator/base.ts +15 -3
  67. package/src/core/index.ts +1 -0
  68. package/src/core/property-renderer.ts +62 -0
  69. package/src/file/file-utils.ts +67 -0
  70. package/src/file/file.ts +90 -8
  71. package/src/file/index.ts +1 -0
  72. package/src/file/link-parser.ts +71 -0
  73. package/src/index.ts +2 -0
  74. package/src/string/filename-utils.ts +77 -0
  75. 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
+ };
@@ -1 +1,2 @@
1
+ export * from "./filename-utils";
1
2
  export * from "./string";