@real1ty-obsidian-plugins/utils 2.11.0 → 2.12.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/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/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/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/string/filename-utils.ts +77 -0
- package/src/string/index.ts +1 -0
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC"}
|
package/dist/core/index.js
CHANGED
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC","sourcesContent":["export * from \"./color-utils\";\nexport * from \"./css-utils\";\nexport * from \"./evaluator\";\nexport * from \"./expression-utils\";\nexport * from \"./frontmatter-value\";\nexport * from \"./generate\";\nexport * from \"./validation\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC","sourcesContent":["export * from \"./color-utils\";\nexport * from \"./css-utils\";\nexport * from \"./evaluator\";\nexport * from \"./expression-utils\";\nexport * from \"./frontmatter-value\";\nexport * from \"./generate\";\nexport * from \"./property-renderer\";\nexport * from \"./validation\";\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface PropertyRendererConfig {
|
|
2
|
+
createLink: (text: string, path: string, isObsidianLink: boolean) => HTMLElement;
|
|
3
|
+
createText: (text: string) => HTMLElement | Text;
|
|
4
|
+
createSeparator?: () => HTMLElement | Text;
|
|
5
|
+
}
|
|
6
|
+
export declare function renderPropertyValue(container: HTMLElement, value: any, config: PropertyRendererConfig): void;
|
|
7
|
+
export declare function createTextNode(text: string): Text;
|
|
8
|
+
export declare function createDefaultSeparator(): Text;
|
|
9
|
+
//# sourceMappingURL=property-renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property-renderer.d.ts","sourceRoot":"","sources":["../../src/core/property-renderer.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,sBAAsB;IACtC,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,KAAK,WAAW,CAAC;IACjF,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,WAAW,GAAG,IAAI,CAAC;IACjD,eAAe,CAAC,EAAE,MAAM,WAAW,GAAG,IAAI,CAAC;CAC3C;AAED,wBAAgB,mBAAmB,CAClC,SAAS,EAAE,WAAW,EACtB,KAAK,EAAE,GAAG,EACV,MAAM,EAAE,sBAAsB,GAC5B,IAAI,CAqBN;AAsBD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEjD;AAED,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { getObsidianLinkAlias, getObsidianLinkPath, isObsidianLink } from "../file/link-parser";
|
|
2
|
+
export function renderPropertyValue(container, value, config) {
|
|
3
|
+
// Handle arrays - render each item separately
|
|
4
|
+
if (Array.isArray(value)) {
|
|
5
|
+
const hasClickableLinks = value.some(isObsidianLink);
|
|
6
|
+
if (hasClickableLinks) {
|
|
7
|
+
for (let index = 0; index < value.length; index++) {
|
|
8
|
+
if (index > 0 && config.createSeparator) {
|
|
9
|
+
container.appendChild(config.createSeparator());
|
|
10
|
+
}
|
|
11
|
+
renderSingleValue(container, value[index], config);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
// Plain array - just join with commas
|
|
16
|
+
const textNode = config.createText(value.join(", "));
|
|
17
|
+
container.appendChild(textNode);
|
|
18
|
+
}
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
renderSingleValue(container, value, config);
|
|
22
|
+
}
|
|
23
|
+
function renderSingleValue(container, value, config) {
|
|
24
|
+
const stringValue = String(value).trim();
|
|
25
|
+
if (isObsidianLink(stringValue)) {
|
|
26
|
+
const displayText = getObsidianLinkAlias(stringValue);
|
|
27
|
+
const linkPath = getObsidianLinkPath(stringValue);
|
|
28
|
+
const link = config.createLink(displayText, linkPath, true);
|
|
29
|
+
container.appendChild(link);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
// Regular text
|
|
33
|
+
const textNode = config.createText(stringValue);
|
|
34
|
+
container.appendChild(textNode);
|
|
35
|
+
}
|
|
36
|
+
export function createTextNode(text) {
|
|
37
|
+
return document.createTextNode(text);
|
|
38
|
+
}
|
|
39
|
+
export function createDefaultSeparator() {
|
|
40
|
+
return document.createTextNode(", ");
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=property-renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property-renderer.js","sourceRoot":"","sources":["../../src/core/property-renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,qB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WAAW,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC5D,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAC5B,OAAO;IACR,CAAC;IAED,eAAe;IACf,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IAChD,SAAS,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAY;IAC1C,OAAO,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,sBAAsB;IACrC,OAAO,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC","sourcesContent":["import { getObsidianLinkAlias, getObsidianLinkPath, isObsidianLink } from \"../file/link-parser\";\n\nexport interface PropertyRendererConfig {\n\tcreateLink: (text: string, path: string, isObsidianLink: boolean) => HTMLElement;\n\tcreateText: (text: string) => HTMLElement | Text;\n\tcreateSeparator?: () => HTMLElement | Text;\n}\n\nexport function renderPropertyValue(\n\tcontainer: HTMLElement,\n\tvalue: any,\n\tconfig: PropertyRendererConfig\n): void {\n\t// Handle arrays - render each item separately\n\tif (Array.isArray(value)) {\n\t\tconst hasClickableLinks = value.some(isObsidianLink);\n\n\t\tif (hasClickableLinks) {\n\t\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\t\tif (index > 0 && config.createSeparator) {\n\t\t\t\t\tcontainer.appendChild(config.createSeparator());\n\t\t\t\t}\n\t\t\t\trenderSingleValue(container, value[index], config);\n\t\t\t}\n\t\t} else {\n\t\t\t// Plain array - just join with commas\n\t\t\tconst textNode = config.createText(value.join(\", \"));\n\t\t\tcontainer.appendChild(textNode);\n\t\t}\n\t\treturn;\n\t}\n\n\trenderSingleValue(container, value, config);\n}\n\nfunction renderSingleValue(\n\tcontainer: HTMLElement,\n\tvalue: any,\n\tconfig: PropertyRendererConfig\n): void {\n\tconst stringValue = String(value).trim();\n\n\tif (isObsidianLink(stringValue)) {\n\t\tconst displayText = getObsidianLinkAlias(stringValue);\n\t\tconst linkPath = getObsidianLinkPath(stringValue);\n\t\tconst link = config.createLink(displayText, linkPath, true);\n\t\tcontainer.appendChild(link);\n\t\treturn;\n\t}\n\n\t// Regular text\n\tconst textNode = config.createText(stringValue);\n\tcontainer.appendChild(textNode);\n}\n\nexport function createTextNode(text: string): Text {\n\treturn document.createTextNode(text);\n}\n\nexport function createDefaultSeparator(): Text {\n\treturn document.createTextNode(\", \");\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { App } from "obsidian";
|
|
2
|
+
import { TFile } from "obsidian";
|
|
3
|
+
/**
|
|
4
|
+
* Gets a TFile by path or throws an error if not found.
|
|
5
|
+
* Useful when you need to ensure a file exists before proceeding.
|
|
6
|
+
*/
|
|
7
|
+
export declare const getTFileOrThrow: (app: App, path: string) => TFile;
|
|
8
|
+
/**
|
|
9
|
+
* Executes an operation on a file's frontmatter.
|
|
10
|
+
* Wrapper around Obsidian's processFrontMatter for more concise usage.
|
|
11
|
+
*/
|
|
12
|
+
export declare const withFrontmatter: (app: App, file: TFile, update: (fm: Record<string, unknown>) => void) => Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a backup copy of a file's frontmatter.
|
|
15
|
+
* Useful for undo/redo operations or temporary modifications.
|
|
16
|
+
*/
|
|
17
|
+
export declare const backupFrontmatter: (app: App, file: TFile) => Promise<Record<string, unknown>>;
|
|
18
|
+
/**
|
|
19
|
+
* Restores a file's frontmatter from a backup.
|
|
20
|
+
* Clears existing frontmatter and replaces with the backup.
|
|
21
|
+
*/
|
|
22
|
+
export declare const restoreFrontmatter: (app: App, file: TFile, original: Record<string, unknown>) => Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Extracts the content that appears after the frontmatter section.
|
|
25
|
+
* Returns the entire content if no frontmatter is found.
|
|
26
|
+
*/
|
|
27
|
+
export declare const extractContentAfterFrontmatter: (fullContent: string) => string;
|
|
28
|
+
//# sourceMappingURL=file-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-utils.d.ts","sourceRoot":"","sources":["../../src/file/file-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,GAAG,EAAE,MAAM,MAAM,KAAG,KAIxD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe,GAC3B,KAAK,GAAG,EACR,MAAM,KAAK,EACX,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,kBACO,CAAC;AAEtD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAU,KAAK,GAAG,EAAE,MAAM,KAAK,qCAM5D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAC9B,KAAK,GAAG,EACR,MAAM,KAAK,EACX,UAAU,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,kBAO/B,CAAC;AAEJ;;;GAGG;AACH,eAAO,MAAM,8BAA8B,GAAI,aAAa,MAAM,KAAG,MAWpE,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { TFile } from "obsidian";
|
|
3
|
+
/**
|
|
4
|
+
* Gets a TFile by path or throws an error if not found.
|
|
5
|
+
* Useful when you need to ensure a file exists before proceeding.
|
|
6
|
+
*/
|
|
7
|
+
export const getTFileOrThrow = (app, path) => {
|
|
8
|
+
const f = app.vault.getAbstractFileByPath(path);
|
|
9
|
+
if (!(f instanceof TFile))
|
|
10
|
+
throw new Error(`File not found: ${path}`);
|
|
11
|
+
return f;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Executes an operation on a file's frontmatter.
|
|
15
|
+
* Wrapper around Obsidian's processFrontMatter for more concise usage.
|
|
16
|
+
*/
|
|
17
|
+
export const withFrontmatter = (app, file, update) => __awaiter(void 0, void 0, void 0, function* () { return app.fileManager.processFrontMatter(file, update); });
|
|
18
|
+
/**
|
|
19
|
+
* Creates a backup copy of a file's frontmatter.
|
|
20
|
+
* Useful for undo/redo operations or temporary modifications.
|
|
21
|
+
*/
|
|
22
|
+
export const backupFrontmatter = (app, file) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
let copy = {};
|
|
24
|
+
yield withFrontmatter(app, file, (fm) => {
|
|
25
|
+
copy = Object.assign({}, fm);
|
|
26
|
+
});
|
|
27
|
+
return copy;
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Restores a file's frontmatter from a backup.
|
|
31
|
+
* Clears existing frontmatter and replaces with the backup.
|
|
32
|
+
*/
|
|
33
|
+
export const restoreFrontmatter = (app, file, original) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
return withFrontmatter(app, file, (fm) => {
|
|
35
|
+
for (const k of Object.keys(fm)) {
|
|
36
|
+
delete fm[k];
|
|
37
|
+
}
|
|
38
|
+
Object.assign(fm, original);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
/**
|
|
42
|
+
* Extracts the content that appears after the frontmatter section.
|
|
43
|
+
* Returns the entire content if no frontmatter is found.
|
|
44
|
+
*/
|
|
45
|
+
export const extractContentAfterFrontmatter = (fullContent) => {
|
|
46
|
+
const frontmatterRegex = /^---\s*\n([\s\S]*?)\n---\s*\n/;
|
|
47
|
+
const match = fullContent.match(frontmatterRegex);
|
|
48
|
+
if (match) {
|
|
49
|
+
// Return content after frontmatter
|
|
50
|
+
return fullContent.substring(match.index + match[0].length);
|
|
51
|
+
}
|
|
52
|
+
// If no frontmatter found, return the entire content
|
|
53
|
+
return fullContent;
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=file-utils.js.map
|
|
@@ -0,0 +1 @@
|
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,CAAC;QACd,CAAC;QACD,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAA;EAAA,CAAC;AAEJ;;;GAGG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,WAAmB,EAAU,EAAE;IAC7E,MAAM,gBAAgB,GAAG,+BAA+B,CAAC;IACzD,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAElD,IAAI,KAAK,EAAE,CAAC;QACX,mCAAmC;QACnC,OAAO,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,KAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC9D,CAAC;IAED,qDAAqD;IACrD,OAAO,WAAW,CAAC;AACpB,CAAC,CAAC","sourcesContent":["import type { App } from \"obsidian\";\nimport { TFile } from \"obsidian\";\n\n/**\n * Gets a TFile by path or throws an error if not found.\n * Useful when you need to ensure a file exists before proceeding.\n */\nexport const getTFileOrThrow = (app: App, path: string): TFile => {\n\tconst f = app.vault.getAbstractFileByPath(path);\n\tif (!(f instanceof TFile)) throw new Error(`File not found: ${path}`);\n\treturn f;\n};\n\n/**\n * Executes an operation on a file's frontmatter.\n * Wrapper around Obsidian's processFrontMatter for more concise usage.\n */\nexport const withFrontmatter = async (\n\tapp: App,\n\tfile: TFile,\n\tupdate: (fm: Record<string, unknown>) => void\n) => app.fileManager.processFrontMatter(file, update);\n\n/**\n * Creates a backup copy of a file's frontmatter.\n * Useful for undo/redo operations or temporary modifications.\n */\nexport const backupFrontmatter = async (app: App, file: TFile) => {\n\tlet copy: Record<string, unknown> = {};\n\tawait withFrontmatter(app, file, (fm) => {\n\t\tcopy = { ...fm };\n\t});\n\treturn copy;\n};\n\n/**\n * Restores a file's frontmatter from a backup.\n * Clears existing frontmatter and replaces with the backup.\n */\nexport const restoreFrontmatter = async (\n\tapp: App,\n\tfile: TFile,\n\toriginal: Record<string, unknown>\n) =>\n\twithFrontmatter(app, file, (fm) => {\n\t\tfor (const k of Object.keys(fm)) {\n\t\t\tdelete fm[k];\n\t\t}\n\t\tObject.assign(fm, original);\n\t});\n\n/**\n * Extracts the content that appears after the frontmatter section.\n * Returns the entire content if no frontmatter is found.\n */\nexport const extractContentAfterFrontmatter = (fullContent: string): string => {\n\tconst frontmatterRegex = /^---\\s*\\n([\\s\\S]*?)\\n---\\s*\\n/;\n\tconst match = fullContent.match(frontmatterRegex);\n\n\tif (match) {\n\t\t// Return content after frontmatter\n\t\treturn fullContent.substring(match.index! + match[0].length);\n\t}\n\n\t// If no frontmatter found, return the entire content\n\treturn fullContent;\n};\n"]}
|
package/dist/file/file.d.ts
CHANGED
|
@@ -257,7 +257,57 @@ export declare function getChildrenByFolder(app: App, filePath: string): string[
|
|
|
257
257
|
* ```
|
|
258
258
|
*/
|
|
259
259
|
export declare function findRootNodesInFolder(app: App, folderPath: string): string[];
|
|
260
|
-
export
|
|
260
|
+
export interface SanitizeFilenameOptions {
|
|
261
|
+
/**
|
|
262
|
+
* Style of sanitization to apply.
|
|
263
|
+
* - "kebab": Convert to lowercase, replace spaces with hyphens (default, backwards compatible)
|
|
264
|
+
* - "preserve": Preserve spaces and case, only remove invalid characters
|
|
265
|
+
*/
|
|
266
|
+
style?: "kebab" | "preserve";
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Sanitizes a string for use as a filename.
|
|
270
|
+
* Defaults to kebab-case style for backwards compatibility.
|
|
271
|
+
*
|
|
272
|
+
* @param input - String to sanitize
|
|
273
|
+
* @param options - Sanitization options
|
|
274
|
+
* @returns Sanitized filename string
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* // Default kebab-case style (backwards compatible)
|
|
278
|
+
* sanitizeForFilename("My File Name") // "my-file-name"
|
|
279
|
+
*
|
|
280
|
+
* // Preserve spaces and case
|
|
281
|
+
* sanitizeForFilename("My File Name", { style: "preserve" }) // "My File Name"
|
|
282
|
+
*/
|
|
283
|
+
export declare const sanitizeForFilename: (input: string, options?: SanitizeFilenameOptions) => string;
|
|
284
|
+
/**
|
|
285
|
+
* Sanitizes filename using kebab-case style.
|
|
286
|
+
* - Removes invalid characters
|
|
287
|
+
* - Converts to lowercase
|
|
288
|
+
* - Replaces spaces with hyphens
|
|
289
|
+
*
|
|
290
|
+
* Best for: CLI tools, URLs, slugs, technical files
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* sanitizeFilenameKebabCase("My File Name") // "my-file-name"
|
|
294
|
+
* sanitizeFilenameKebabCase("Travel Around The World") // "travel-around-the-world"
|
|
295
|
+
*/
|
|
296
|
+
export declare const sanitizeFilenameKebabCase: (input: string) => string;
|
|
297
|
+
/**
|
|
298
|
+
* Sanitizes filename while preserving spaces and case.
|
|
299
|
+
* - Removes invalid characters only
|
|
300
|
+
* - Preserves spaces and original casing
|
|
301
|
+
* - Removes trailing dots (Windows compatibility)
|
|
302
|
+
*
|
|
303
|
+
* Best for: Note titles, human-readable filenames, Obsidian notes
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* sanitizeFilenamePreserveSpaces("My File Name") // "My File Name"
|
|
307
|
+
* sanitizeFilenamePreserveSpaces("Travel Around The World") // "Travel Around The World"
|
|
308
|
+
* sanitizeFilenamePreserveSpaces("File<Invalid>Chars") // "FileInvalidChars"
|
|
309
|
+
*/
|
|
310
|
+
export declare const sanitizeFilenamePreserveSpaces: (input: string) => string;
|
|
261
311
|
export declare const getFilenameFromPath: (filePath: string) => string;
|
|
262
312
|
export declare const isFileInConfiguredDirectory: (filePath: string, directory: string) => boolean;
|
|
263
313
|
//# sourceMappingURL=file.d.ts.map
|
package/dist/file/file.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/file/file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,cAAc,EAAE,MAAM,UAAU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;GAWG;AACH,eAAO,MAAM,yBAAyB,GAAI,OAAO,MAAM,KAAG,MAczD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,8BAA8B,GAAI,OAAO,MAAM,KAAG,MAU9D,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,UAAU,MAAM,KAAG,MAEtD,CAAC;AAEF,eAAO,MAAM,2BAA2B,GAAI,UAAU,MAAM,EAAE,WAAW,MAAM,KAAG,OAGjF,CAAC"}
|
package/dist/file/file.js
CHANGED
|
@@ -445,16 +445,75 @@ export function getChildrenByFolder(app, filePath) {
|
|
|
445
445
|
export function findRootNodesInFolder(app, folderPath) {
|
|
446
446
|
return getFilesInFolder(app, folderPath).map((file) => file.path);
|
|
447
447
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
448
|
+
/**
|
|
449
|
+
* Sanitizes a string for use as a filename.
|
|
450
|
+
* Defaults to kebab-case style for backwards compatibility.
|
|
451
|
+
*
|
|
452
|
+
* @param input - String to sanitize
|
|
453
|
+
* @param options - Sanitization options
|
|
454
|
+
* @returns Sanitized filename string
|
|
455
|
+
*
|
|
456
|
+
* @example
|
|
457
|
+
* // Default kebab-case style (backwards compatible)
|
|
458
|
+
* sanitizeForFilename("My File Name") // "my-file-name"
|
|
459
|
+
*
|
|
460
|
+
* // Preserve spaces and case
|
|
461
|
+
* sanitizeForFilename("My File Name", { style: "preserve" }) // "My File Name"
|
|
462
|
+
*/
|
|
463
|
+
export const sanitizeForFilename = (input, options = {}) => {
|
|
464
|
+
const { style = "kebab" } = options;
|
|
465
|
+
if (style === "preserve") {
|
|
466
|
+
return sanitizeFilenamePreserveSpaces(input);
|
|
467
|
+
}
|
|
468
|
+
// Default: kebab-case style (legacy behavior)
|
|
469
|
+
return sanitizeFilenameKebabCase(input);
|
|
470
|
+
};
|
|
471
|
+
/**
|
|
472
|
+
* Sanitizes filename using kebab-case style.
|
|
473
|
+
* - Removes invalid characters
|
|
474
|
+
* - Converts to lowercase
|
|
475
|
+
* - Replaces spaces with hyphens
|
|
476
|
+
*
|
|
477
|
+
* Best for: CLI tools, URLs, slugs, technical files
|
|
478
|
+
*
|
|
479
|
+
* @example
|
|
480
|
+
* sanitizeFilenameKebabCase("My File Name") // "my-file-name"
|
|
481
|
+
* sanitizeFilenameKebabCase("Travel Around The World") // "travel-around-the-world"
|
|
482
|
+
*/
|
|
483
|
+
export const sanitizeFilenameKebabCase = (input) => {
|
|
484
|
+
return (input
|
|
485
|
+
// Remove invalid filename characters
|
|
486
|
+
.replace(/[<>:"/\\|?*]/g, "")
|
|
487
|
+
// Replace spaces with hyphens
|
|
488
|
+
.replace(/\s+/g, "-")
|
|
489
|
+
// Replace multiple hyphens with single
|
|
490
|
+
.replace(/-+/g, "-")
|
|
491
|
+
// Remove leading/trailing hyphens
|
|
492
|
+
.replace(/^-|-$/g, "")
|
|
493
|
+
// Convert to lowercase
|
|
494
|
+
.toLowerCase());
|
|
495
|
+
};
|
|
496
|
+
/**
|
|
497
|
+
* Sanitizes filename while preserving spaces and case.
|
|
498
|
+
* - Removes invalid characters only
|
|
499
|
+
* - Preserves spaces and original casing
|
|
500
|
+
* - Removes trailing dots (Windows compatibility)
|
|
501
|
+
*
|
|
502
|
+
* Best for: Note titles, human-readable filenames, Obsidian notes
|
|
503
|
+
*
|
|
504
|
+
* @example
|
|
505
|
+
* sanitizeFilenamePreserveSpaces("My File Name") // "My File Name"
|
|
506
|
+
* sanitizeFilenamePreserveSpaces("Travel Around The World") // "Travel Around The World"
|
|
507
|
+
* sanitizeFilenamePreserveSpaces("File<Invalid>Chars") // "FileInvalidChars"
|
|
508
|
+
*/
|
|
509
|
+
export const sanitizeFilenamePreserveSpaces = (input) => {
|
|
510
|
+
return (input
|
|
511
|
+
// Remove invalid filename characters (cross-platform compatibility)
|
|
512
|
+
.replace(/[<>:"/\\|?*]/g, "")
|
|
513
|
+
// Remove trailing dots (invalid on Windows)
|
|
514
|
+
.replace(/\.+$/g, "")
|
|
515
|
+
// Remove leading/trailing whitespace
|
|
516
|
+
.trim());
|
|
458
517
|
};
|
|
459
518
|
export const getFilenameFromPath = (filePath) => {
|
|
460
519
|
return filePath.split("/").pop() || "Unknown";
|
package/dist/file/file.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/file/file.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEhD,+EAA+E;AAC/E,uBAAuB;AACvB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,aAAa,CAAC,GAAQ,EAAE,QAAgB;IACvD,8CAA8C;IAC9C,kEAAkE;IAClE,MAAM,cAAc,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IAE/C,oDAAoD;IACpD,yEAAyE;IACzE,IAAI,OAAO,GAAG,CAAC,KAAK,CAAC,aAAa,KAAK,UAAU,EAAE,CAAC;QACnD,OAAO,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;IAChD,CAAC;IAED,MAAM,YAAY,GAAG,GAAG,CAAC,KAAK,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAAC;IAErE,OAAO,YAAY,YAAY,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5D,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAY;IACnD,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,KAAK,CAAC;AACnD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAY;IACnD,OAAO,IAAI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;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAQ,EAAE,UAAkB;IACjE,OAAO,gBAAgB,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACnE,CAAC;AAED,+EAA+E;AAC/E,8DAA8D;AAC9D,+EAA+E;AAE/E,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAa,EAAU,EAAE;IAC5D,OAAO,KAAK;SACV,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,qCAAqC;SAClE,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,8BAA8B;SACnD,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,uCAAuC;SAC3D,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,kCAAkC;SACxD,WAAW,EAAE,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,QAAgB,EAAU,EAAE;IAC/D,OAAO,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,SAAS,CAAC;AAC/C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,QAAgB,EAAE,SAAiB,EAAW,EAAE;IAC3F,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACnF,OAAO,QAAQ,CAAC,UAAU,CAAC,GAAG,aAAa,GAAG,CAAC,IAAI,QAAQ,KAAK,aAAa,CAAC;AAC/E,CAAC,CAAC","sourcesContent":["import type { App, CachedMetadata } from \"obsidian\";\nimport { normalizePath, TFile } from \"obsidian\";\n\n// ============================================================================\n// File Path Operations\n// ============================================================================\n\n/**\n * Retrieves a TFile object from the vault by its path.\n * Handles path normalization using Obsidian's normalizePath utility.\n *\n * **Important**: Obsidian file paths ALWAYS include the `.md` extension.\n * The TFile.path property returns paths like \"folder/file.md\", not \"folder/file\".\n *\n * @param app - The Obsidian App instance\n * @param filePath - Path to the file (will be normalized, should include .md extension)\n * @returns TFile if found, null otherwise\n *\n * @example\n * ```ts\n * // Correct: Include .md extension\n * const file = getFileByPath(app, \"folder/note.md\");\n *\n * // For wikilinks without extension, add .md\n * const linkPath = \"MyNote\";\n * const file = getFileByPath(app, `${linkPath}.md`);\n * ```\n */\nexport function getFileByPath(app: App, filePath: string): TFile | null {\n\t// Normalize the path using Obsidian's utility\n\t// This handles slashes, spaces, and platform-specific path issues\n\tconst normalizedPath = normalizePath(filePath);\n\n\t// Use Vault's direct lookup method (most efficient)\n\t// Prefer getFileByPath if available, otherwise use getAbstractFileByPath\n\tif (typeof app.vault.getFileByPath === \"function\") {\n\t\treturn app.vault.getFileByPath(normalizedPath);\n\t}\n\n\tconst abstractFile = app.vault.getAbstractFileByPath(normalizedPath);\n\n\treturn abstractFile instanceof TFile ? abstractFile : null;\n}\n\n/**\n * Ensures a file path includes the .md extension.\n * Use this when working with wikilinks or user input that may omit extensions.\n *\n * @param path - File path that may or may not include .md extension\n * @returns Path guaranteed to end with .md\n *\n * @example\n * ```ts\n * ensureMarkdownExtension(\"MyNote\") // \"MyNote.md\"\n * ensureMarkdownExtension(\"MyNote.md\") // \"MyNote.md\"\n * ensureMarkdownExtension(\"folder/note\") // \"folder/note.md\"\n * ```\n */\nexport function ensureMarkdownExtension(path: string): string {\n\treturn path.endsWith(\".md\") ? path : `${path}.md`;\n}\n\n/**\n * Removes the .md extension from a file path if present.\n * Useful for displaying file names or creating wikilinks.\n *\n * @param path - File path that may include .md extension\n * @returns Path without .md extension\n *\n * @example\n * ```ts\n * removeMarkdownExtension(\"folder/note.md\") // \"folder/note\"\n * removeMarkdownExtension(\"folder/note\") // \"folder/note\"\n * ```\n */\nexport function removeMarkdownExtension(path: string): string {\n\treturn path.endsWith(\".md\") ? path.slice(0, -3) : path;\n}\n\n// ============================================================================\n// File Name Extraction\n// ============================================================================\n\n/**\n * Extracts the display name from a file path or wiki link.\n *\n * Handles various formats:\n * - `[[path/to/file|Alias]]` -> returns \"Alias\"\n * - `[[path/to/file]]` -> returns \"file\"\n * - `path/to/file.md` -> returns \"file\"\n * - `file.md` -> returns \"file\"\n *\n * @param input - File path or wiki link string\n * @returns The display name to show in the UI\n */\nexport function extractDisplayName(input: string): string {\n\tif (!input) return \"\";\n\n\t// Remove any surrounding whitespace\n\tconst trimmed = input.trim();\n\n\t// Check if it's a wiki link format [[path|alias]] or [[path]]\n\tconst wikiLinkMatch = trimmed.match(/^\\[\\[([^\\]]+)\\]\\]$/);\n\n\tif (wikiLinkMatch) {\n\t\tconst innerContent = wikiLinkMatch[1];\n\n\t\t// Check if there's an alias (pipe character)\n\t\tconst pipeIndex = innerContent.indexOf(\"|\");\n\n\t\tif (pipeIndex !== -1) {\n\t\t\t// Return the alias (everything after the pipe)\n\t\t\treturn innerContent.substring(pipeIndex + 1).trim();\n\t\t}\n\n\t\t// No alias, extract filename from path\n\t\tconst path = innerContent.trim();\n\n\t\tconst lastSlashIndex = path.lastIndexOf(\"/\");\n\n\t\tconst filename = lastSlashIndex !== -1 ? path.substring(lastSlashIndex + 1) : path;\n\n\t\treturn filename.replace(/\\.md$/i, \"\");\n\t}\n\n\t// Not a wiki link, treat as regular path\n\tconst lastSlashIndex = trimmed.lastIndexOf(\"/\");\n\n\tconst filename = lastSlashIndex !== -1 ? trimmed.substring(lastSlashIndex + 1) : trimmed;\n\n\treturn filename.replace(/\\.md$/i, \"\");\n}\n\n/**\n * Extracts the actual file path from a wiki link or returns the path as-is.\n *\n * Handles:\n * - `[[path/to/file|Alias]]` -> returns \"path/to/file.md\"\n * - `[[path/to/file]]` -> returns \"path/to/file.md\"\n * - `path/to/file.md` -> returns \"path/to/file.md\"\n *\n * @param input - File path or wiki link string\n * @returns The actual file path (with .md extension)\n */\nexport function extractFilePath(input: string): string {\n\tif (!input) return \"\";\n\n\tconst trimmed = input.trim();\n\n\t// Check if it's a wiki link format [[path|alias]] or [[path]]\n\tconst wikiLinkMatch = trimmed.match(/^\\[\\[([^\\]]+)\\]\\]$/);\n\n\tif (wikiLinkMatch) {\n\t\tconst innerContent = wikiLinkMatch[1];\n\n\t\t// Check if there's an alias (pipe character)\n\t\tconst pipeIndex = innerContent.indexOf(\"|\");\n\n\t\tconst path =\n\t\t\tpipeIndex !== -1 ? innerContent.substring(0, pipeIndex).trim() : innerContent.trim();\n\n\t\t// Ensure .md extension\n\t\treturn path.endsWith(\".md\") ? path : `${path}.md`;\n\t}\n\n\t// Not a wiki link, ensure .md extension\n\treturn trimmed.endsWith(\".md\") ? trimmed : `${trimmed}.md`;\n}\n\n// ============================================================================\n// File Context\n// ============================================================================\n\nexport interface FileContext {\n\tpath: string;\n\tpathWithExt: string;\n\tbaseName: string;\n\tfile: TFile | null;\n\tfrontmatter: Record<string, any> | undefined;\n\tcache: CachedMetadata | null;\n}\n\n/**\n * Creates a comprehensive file context object containing all relevant file information.\n * Handles path normalization, file lookup, and metadata caching.\n */\nexport function getFileContext(app: App, path: string): FileContext {\n\tconst pathWithExt = ensureMarkdownExtension(path);\n\n\tconst baseName = removeMarkdownExtension(path);\n\n\tconst file = getFileByPath(app, pathWithExt);\n\n\tconst cache = file ? app.metadataCache.getFileCache(file) : null;\n\n\tconst frontmatter = cache?.frontmatter;\n\n\treturn {\n\t\tpath,\n\t\tpathWithExt,\n\t\tbaseName,\n\t\tfile,\n\t\tfrontmatter,\n\t\tcache,\n\t};\n}\n\n/**\n * Helper function to work with file context that automatically handles file not found cases.\n * Returns null if the file doesn't exist, otherwise executes the callback with the context.\n */\nexport async function withFileContext<T>(\n\tapp: App,\n\tpath: string,\n\tcallback: (context: FileContext) => Promise<T> | T\n): Promise<T | null> {\n\tconst context = getFileContext(app, path);\n\n\tif (!context.file) {\n\t\tconsole.warn(`File not found: ${context.pathWithExt}`);\n\t\treturn null;\n\t}\n\n\treturn await callback(context);\n}\n\n// ============================================================================\n// File Path Generation\n// ============================================================================\n\n/**\n * Generates a unique file path by appending a counter if the file already exists.\n * Automatically adds .md extension if not present.\n *\n * @param app - The Obsidian App instance\n * @param folder - Folder path (empty string for root, no trailing slash needed)\n * @param baseName - Base file name without extension\n * @returns Unique file path that doesn't exist in the vault\n *\n * @example\n * ```ts\n * // If \"MyNote.md\" exists, returns \"MyNote 1.md\"\n * const path = getUniqueFilePath(app, \"\", \"MyNote\");\n *\n * // With folder: \"Projects/Task.md\" -> \"Projects/Task 1.md\"\n * const path = getUniqueFilePath(app, \"Projects\", \"Task\");\n *\n * // Root folder handling\n * const path = getUniqueFilePath(app, \"/\", \"Note\"); // -> \"Note.md\"\n * ```\n */\nexport function getUniqueFilePath(app: App, folder: string, baseName: string): string {\n\tconst normalizedFolder = folder && folder !== \"/\" ? folder : \"\";\n\tconst folderPath = normalizedFolder ? `${normalizedFolder}/` : \"\";\n\n\tlet fileName = `${baseName}.md`;\n\tlet fullPath = `${folderPath}${fileName}`;\n\tlet counter = 1;\n\n\twhile (app.vault.getAbstractFileByPath(fullPath)) {\n\t\tfileName = `${baseName} ${counter}.md`;\n\t\tfullPath = `${folderPath}${fileName}`;\n\t\tcounter++;\n\t}\n\n\treturn fullPath;\n}\n\n/**\n * Generates a unique file path by appending a counter if the file already exists.\n * Supports custom file extensions.\n *\n * @param app - The Obsidian App instance\n * @param folder - Folder path (empty string for root)\n * @param baseName - Base file name without extension\n * @param extension - File extension (defaults to \"md\")\n * @returns Unique file path that doesn't exist in the vault\n */\nexport const generateUniqueFilePath = (\n\tapp: App,\n\tfolder: string,\n\tbaseName: string,\n\textension: string = \"md\"\n): string => {\n\tconst folderPath = folder ? `${folder}/` : \"\";\n\tlet filePath = `${folderPath}${baseName}.${extension}`;\n\tlet counter = 1;\n\n\twhile (app.vault.getAbstractFileByPath(filePath)) {\n\t\tfilePath = `${folderPath}${baseName} ${counter++}.${extension}`;\n\t}\n\n\treturn filePath;\n};\n\n// ============================================================================\n// Folder Note Operations\n// ============================================================================\n\n/**\n * Checks if a file is a folder note.\n * A folder note is a file whose name matches its parent folder name.\n *\n * @param filePath - Path to the file (e.g., \"tasks/tasks.md\")\n * @returns true if the file is a folder note, false otherwise\n *\n * @example\n * ```ts\n * isFolderNote(\"tasks/tasks.md\") // true\n * isFolderNote(\"tasks/subtask.md\") // false\n * isFolderNote(\"note.md\") // false (no parent folder)\n * isFolderNote(\"projects/docs/docs.md\") // true\n * ```\n */\nexport function isFolderNote(filePath: string): boolean {\n\tif (!filePath) return false;\n\n\t// Remove .md extension for comparison\n\tconst pathWithoutExt = removeMarkdownExtension(filePath);\n\n\t// Split path into segments\n\tconst segments = pathWithoutExt.split(\"/\");\n\n\t// Need at least 2 segments (folder/file)\n\tif (segments.length < 2) return false;\n\n\t// Get the file name (last segment) and parent folder name (second to last)\n\tconst fileName = segments[segments.length - 1];\n\tconst parentFolderName = segments[segments.length - 2];\n\n\t// File is a folder note if its name matches the parent folder\n\treturn fileName === parentFolderName;\n}\n\n/**\n * Gets the folder path for a file.\n *\n * @param filePath - Path to the file (e.g., \"tasks/subtask.md\")\n * @returns Folder path without trailing slash, or empty string if file is in root\n *\n * @example\n * ```ts\n * getFolderPath(\"tasks/subtask.md\") // \"tasks\"\n * getFolderPath(\"projects/docs/notes.md\") // \"projects/docs\"\n * getFolderPath(\"note.md\") // \"\"\n * ```\n */\nexport function getFolderPath(filePath: string): string {\n\tif (!filePath) return \"\";\n\n\tconst lastSlashIndex = filePath.lastIndexOf(\"/\");\n\n\tif (lastSlashIndex === -1) return \"\";\n\n\treturn filePath.substring(0, lastSlashIndex);\n}\n\n/**\n * Gets all markdown files in a specific folder (non-recursive).\n *\n * @param app - The Obsidian App instance\n * @param folderPath - Path to the folder (e.g., \"tasks\")\n * @returns Array of TFile objects in the folder\n *\n * @example\n * ```ts\n * const files = getFilesInFolder(app, \"tasks\");\n * // Returns [task1.md, task2.md, tasks.md] but not tasks/subtasks/file.md\n * ```\n */\nexport function getFilesInFolder(app: App, folderPath: string): TFile[] {\n\tconst allFiles = app.vault.getMarkdownFiles();\n\n\treturn allFiles.filter((file) => {\n\t\tconst fileFolder = getFolderPath(file.path);\n\n\t\treturn fileFolder === folderPath;\n\t});\n}\n\n/**\n * Gets all markdown files in a folder and its subfolders recursively.\n *\n * @param app - The Obsidian App instance\n * @param folderPath - Path to the folder (e.g., \"tasks\")\n * @returns Array of TFile objects in the folder tree\n *\n * @example\n * ```ts\n * const files = getAllFilesInFolderTree(app, \"tasks\");\n * // Returns all .md files in tasks/ and all its subdirectories\n * ```\n */\nexport function getAllFilesInFolderTree(app: App, folderPath: string): TFile[] {\n\tconst allFiles = app.vault.getMarkdownFiles();\n\n\tconst normalizedFolder = folderPath ? `${folderPath}/` : \"\";\n\n\treturn allFiles.filter((file) => {\n\t\tif (!normalizedFolder) return true; // Root folder includes all files\n\n\t\treturn file.path.startsWith(normalizedFolder);\n\t});\n}\n\n/**\n * Gets the parent file path based on folder structure.\n * For a file in a folder, the parent is the folder note if it exists.\n *\n * @param app - The Obsidian App instance\n * @param filePath - Path to the file\n * @returns Path to parent file, or null if no parent exists\n *\n * @example\n * ```ts\n * // If tasks/tasks.md exists\n * getParentByFolder(app, \"tasks/subtask.md\") // \"tasks/tasks.md\"\n *\n * // If parent folder note doesn't exist\n * getParentByFolder(app, \"tasks/subtask.md\") // null\n *\n * // Root level file\n * getParentByFolder(app, \"note.md\") // null\n * ```\n */\nexport function getParentByFolder(app: App, filePath: string): string | null {\n\tconst folderPath = getFolderPath(filePath);\n\n\tif (!folderPath) return null; // File is at root level\n\n\t// Check if folder note exists\n\tconst folderSegments = folderPath.split(\"/\");\n\n\tconst parentFolderName = folderSegments[folderSegments.length - 1];\n\n\tconst potentialParentPath = `${folderPath}/${parentFolderName}.md`;\n\n\tconst parentFile = getFileByPath(app, potentialParentPath);\n\n\treturn parentFile ? potentialParentPath : null;\n}\n\n/**\n * Gets all child file paths based on folder structure.\n * Works for both folder notes and regular files.\n *\n * For folder notes (e.g., \"tasks/tasks.md\"):\n * - Returns all files directly in the folder (excluding the folder note)\n * - Includes subfolder notes one level down\n *\n * For regular files (e.g., \"tasks/task1.md\"):\n * - Returns the folder note from matching subfolder if it exists (e.g., \"tasks/task1/task1.md\")\n *\n * @param app - The Obsidian App instance\n * @param filePath - Path to the file\n * @returns Array of child file paths\n *\n * @example\n * ```ts\n * // For tasks/tasks.md (folder note)\n * getChildrenByFolder(app, \"tasks/tasks.md\")\n * // Returns [\"tasks/task1.md\", \"tasks/task2.md\", \"tasks/subtasks/subtasks.md\"]\n *\n * // For tasks/task1.md (regular file with matching subfolder)\n * getChildrenByFolder(app, \"tasks/task1.md\")\n * // Returns [\"tasks/task1/task1.md\"] if it exists\n * ```\n */\nexport function getChildrenByFolder(app: App, filePath: string): string[] {\n\tconst allFiles = app.vault.getMarkdownFiles();\n\n\t// Case 1: Folder note - get all files in the folder\n\tif (isFolderNote(filePath)) {\n\t\tconst folderPath = getFolderPath(filePath);\n\n\t\tconst children: string[] = [];\n\n\t\tallFiles.forEach((file) => {\n\t\t\t// Skip the folder note itself\n\t\t\tif (file.path === filePath) return;\n\n\t\t\tconst fileFolder = getFolderPath(file.path);\n\n\t\t\t// Direct child: file is in the same folder as the folder note\n\t\t\tif (fileFolder === folderPath) {\n\t\t\t\tchildren.push(file.path);\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Subfolder note: file is a folder note one level deeper\n\t\t\t// e.g., for \"tasks/tasks.md\", include \"tasks/subtasks/subtasks.md\"\n\t\t\tif (fileFolder.startsWith(`${folderPath}/`)) {\n\t\t\t\t// Check if it's exactly one level deeper and is a folder note\n\t\t\t\tconst relativePath = fileFolder.substring(folderPath.length + 1);\n\n\t\t\t\tconst isOneLevel = !relativePath.includes(\"/\");\n\n\t\t\t\tif (isOneLevel && isFolderNote(file.path)) {\n\t\t\t\t\tchildren.push(file.path);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\treturn children;\n\t}\n\n\t// Case 2: Regular file - check for matching subfolder with folder note\n\tconst pathWithoutExt = removeMarkdownExtension(filePath);\n\n\tconst fileName = pathWithoutExt.split(\"/\").pop() || \"\";\n\n\tconst potentialChildFolder = `${pathWithoutExt}`;\n\n\tconst potentialChildPath = `${potentialChildFolder}/${fileName}.md`;\n\n\t// Check if the child folder note exists\n\tconst childFile = getFileByPath(app, potentialChildPath);\n\n\treturn childFile ? [potentialChildPath] : [];\n}\n\n/**\n * Finds all root nodes in a folder tree.\n * Root nodes are files at the top level of the folder (directly in the folder, not in subfolders).\n *\n * @param app - The Obsidian App instance\n * @param folderPath - Path to the folder\n * @returns Array of root file paths\n *\n * @example\n * ```ts\n * // For folder structure:\n * // tasks/\n * // tasks.md (folder note)\n * // task1.md\n * // subtasks/\n * // subtasks.md\n * // subtask1.md\n *\n * findRootNodesInFolder(app, \"tasks\")\n * // Returns [\"tasks/tasks.md\", \"tasks/task1.md\"]\n * // Excludes subtasks/subtasks.md and subtasks/subtask1.md (they're in subfolder)\n * ```\n */\nexport function findRootNodesInFolder(app: App, folderPath: string): string[] {\n\treturn getFilesInFolder(app, folderPath).map((file) => file.path);\n}\n\n// ============================================================================\n// Legacy Utility Functions (kept for backwards compatibility)\n// ============================================================================\n\nexport const sanitizeForFilename = (input: string): string => {\n\treturn input\n\t\t.replace(/[<>:\"/\\\\|?*]/g, \"\") // Remove invalid filename characters\n\t\t.replace(/\\s+/g, \"-\") // Replace spaces with hyphens\n\t\t.replace(/-+/g, \"-\") // Replace multiple hyphens with single\n\t\t.replace(/^-|-$/g, \"\") // Remove leading/trailing hyphens\n\t\t.toLowerCase();\n};\n\nexport const getFilenameFromPath = (filePath: string): string => {\n\treturn filePath.split(\"/\").pop() || \"Unknown\";\n};\n\nexport const isFileInConfiguredDirectory = (filePath: string, directory: string): boolean => {\n\tconst normalizedDir = directory.endsWith(\"/\") ? directory.slice(0, -1) : directory;\n\treturn filePath.startsWith(`${normalizedDir}/`) || filePath === normalizedDir;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/file/file.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEhD,+EAA+E;AAC/E,uBAAuB;AACvB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,aAAa,CAAC,GAAQ,EAAE,QAAgB;IACvD,8CAA8C;IAC9C,kEAAkE;IAClE,MAAM,cAAc,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IAE/C,oDAAoD;IACpD,yEAAyE;IACzE,IAAI,OAAO,GAAG,CAAC,KAAK,CAAC,aAAa,KAAK,UAAU,EAAE,CAAC;QACnD,OAAO,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;IAChD,CAAC;IAED,MAAM,YAAY,GAAG,GAAG,CAAC,KAAK,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAAC;IAErE,OAAO,YAAY,YAAY,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5D,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAY;IACnD,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,KAAK,CAAC;AACnD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAY;IACnD,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACxD,CAAC;AAED,+EAA+E;AAC/E,uBAAuB;A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C/C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,QAAgB,EAAE,SAAiB,EAAW,EAAE;IAC3F,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACnF,OAAO,QAAQ,CAAC,UAAU,CAAC,GAAG,aAAa,GAAG,CAAC,IAAI,QAAQ,KAAK,aAAa,CAAC;AAC/E,CAAC,CAAC","sourcesContent":["import type { App, CachedMetadata } from \"obsidian\";\nimport { normalizePath, TFile } from \"obsidian\";\n\n// ============================================================================\n// File Path Operations\n// ============================================================================\n\n/**\n * Retrieves a TFile object from the vault by its path.\n * Handles path normalization using Obsidian's normalizePath utility.\n *\n * **Important**: Obsidian file paths ALWAYS include the `.md` extension.\n * The TFile.path property returns paths like \"folder/file.md\", not \"folder/file\".\n *\n * @param app - The Obsidian App instance\n * @param filePath - Path to the file (will be normalized, should include .md extension)\n * @returns TFile if found, null otherwise\n *\n * @example\n * ```ts\n * // Correct: Include .md extension\n * const file = getFileByPath(app, \"folder/note.md\");\n *\n * // For wikilinks without extension, add .md\n * const linkPath = \"MyNote\";\n * const file = getFileByPath(app, `${linkPath}.md`);\n * ```\n */\nexport function getFileByPath(app: App, filePath: string): TFile | null {\n\t// Normalize the path using Obsidian's utility\n\t// This handles slashes, spaces, and platform-specific path issues\n\tconst normalizedPath = normalizePath(filePath);\n\n\t// Use Vault's direct lookup method (most efficient)\n\t// Prefer getFileByPath if available, otherwise use getAbstractFileByPath\n\tif (typeof app.vault.getFileByPath === \"function\") {\n\t\treturn app.vault.getFileByPath(normalizedPath);\n\t}\n\n\tconst abstractFile = app.vault.getAbstractFileByPath(normalizedPath);\n\n\treturn abstractFile instanceof TFile ? abstractFile : null;\n}\n\n/**\n * Ensures a file path includes the .md extension.\n * Use this when working with wikilinks or user input that may omit extensions.\n *\n * @param path - File path that may or may not include .md extension\n * @returns Path guaranteed to end with .md\n *\n * @example\n * ```ts\n * ensureMarkdownExtension(\"MyNote\") // \"MyNote.md\"\n * ensureMarkdownExtension(\"MyNote.md\") // \"MyNote.md\"\n * ensureMarkdownExtension(\"folder/note\") // \"folder/note.md\"\n * ```\n */\nexport function ensureMarkdownExtension(path: string): string {\n\treturn path.endsWith(\".md\") ? path : `${path}.md`;\n}\n\n/**\n * Removes the .md extension from a file path if present.\n * Useful for displaying file names or creating wikilinks.\n *\n * @param path - File path that may include .md extension\n * @returns Path without .md extension\n *\n * @example\n * ```ts\n * removeMarkdownExtension(\"folder/note.md\") // \"folder/note\"\n * removeMarkdownExtension(\"folder/note\") // \"folder/note\"\n * ```\n */\nexport function removeMarkdownExtension(path: string): string {\n\treturn path.endsWith(\".md\") ? path.slice(0, -3) : path;\n}\n\n// ============================================================================\n// File Name Extraction\n// ============================================================================\n\n/**\n * Extracts the display name from a file path or wiki link.\n *\n * Handles various formats:\n * - `[[path/to/file|Alias]]` -> returns \"Alias\"\n * - `[[path/to/file]]` -> returns \"file\"\n * - `path/to/file.md` -> returns \"file\"\n * - `file.md` -> returns \"file\"\n *\n * @param input - File path or wiki link string\n * @returns The display name to show in the UI\n */\nexport function extractDisplayName(input: string): string {\n\tif (!input) return \"\";\n\n\t// Remove any surrounding whitespace\n\tconst trimmed = input.trim();\n\n\t// Check if it's a wiki link format [[path|alias]] or [[path]]\n\tconst wikiLinkMatch = trimmed.match(/^\\[\\[([^\\]]+)\\]\\]$/);\n\n\tif (wikiLinkMatch) {\n\t\tconst innerContent = wikiLinkMatch[1];\n\n\t\t// Check if there's an alias (pipe character)\n\t\tconst pipeIndex = innerContent.indexOf(\"|\");\n\n\t\tif (pipeIndex !== -1) {\n\t\t\t// Return the alias (everything after the pipe)\n\t\t\treturn innerContent.substring(pipeIndex + 1).trim();\n\t\t}\n\n\t\t// No alias, extract filename from path\n\t\tconst path = innerContent.trim();\n\n\t\tconst lastSlashIndex = path.lastIndexOf(\"/\");\n\n\t\tconst filename = lastSlashIndex !== -1 ? path.substring(lastSlashIndex + 1) : path;\n\n\t\treturn filename.replace(/\\.md$/i, \"\");\n\t}\n\n\t// Not a wiki link, treat as regular path\n\tconst lastSlashIndex = trimmed.lastIndexOf(\"/\");\n\n\tconst filename = lastSlashIndex !== -1 ? trimmed.substring(lastSlashIndex + 1) : trimmed;\n\n\treturn filename.replace(/\\.md$/i, \"\");\n}\n\n/**\n * Extracts the actual file path from a wiki link or returns the path as-is.\n *\n * Handles:\n * - `[[path/to/file|Alias]]` -> returns \"path/to/file.md\"\n * - `[[path/to/file]]` -> returns \"path/to/file.md\"\n * - `path/to/file.md` -> returns \"path/to/file.md\"\n *\n * @param input - File path or wiki link string\n * @returns The actual file path (with .md extension)\n */\nexport function extractFilePath(input: string): string {\n\tif (!input) return \"\";\n\n\tconst trimmed = input.trim();\n\n\t// Check if it's a wiki link format [[path|alias]] or [[path]]\n\tconst wikiLinkMatch = trimmed.match(/^\\[\\[([^\\]]+)\\]\\]$/);\n\n\tif (wikiLinkMatch) {\n\t\tconst innerContent = wikiLinkMatch[1];\n\n\t\t// Check if there's an alias (pipe character)\n\t\tconst pipeIndex = innerContent.indexOf(\"|\");\n\n\t\tconst path =\n\t\t\tpipeIndex !== -1 ? innerContent.substring(0, pipeIndex).trim() : innerContent.trim();\n\n\t\t// Ensure .md extension\n\t\treturn path.endsWith(\".md\") ? path : `${path}.md`;\n\t}\n\n\t// Not a wiki link, ensure .md extension\n\treturn trimmed.endsWith(\".md\") ? trimmed : `${trimmed}.md`;\n}\n\n// ============================================================================\n// File Context\n// ============================================================================\n\nexport interface FileContext {\n\tpath: string;\n\tpathWithExt: string;\n\tbaseName: string;\n\tfile: TFile | null;\n\tfrontmatter: Record<string, any> | undefined;\n\tcache: CachedMetadata | null;\n}\n\n/**\n * Creates a comprehensive file context object containing all relevant file information.\n * Handles path normalization, file lookup, and metadata caching.\n */\nexport function getFileContext(app: App, path: string): FileContext {\n\tconst pathWithExt = ensureMarkdownExtension(path);\n\n\tconst baseName = removeMarkdownExtension(path);\n\n\tconst file = getFileByPath(app, pathWithExt);\n\n\tconst cache = file ? app.metadataCache.getFileCache(file) : null;\n\n\tconst frontmatter = cache?.frontmatter;\n\n\treturn {\n\t\tpath,\n\t\tpathWithExt,\n\t\tbaseName,\n\t\tfile,\n\t\tfrontmatter,\n\t\tcache,\n\t};\n}\n\n/**\n * Helper function to work with file context that automatically handles file not found cases.\n * Returns null if the file doesn't exist, otherwise executes the callback with the context.\n */\nexport async function withFileContext<T>(\n\tapp: App,\n\tpath: string,\n\tcallback: (context: FileContext) => Promise<T> | T\n): Promise<T | null> {\n\tconst context = getFileContext(app, path);\n\n\tif (!context.file) {\n\t\tconsole.warn(`File not found: ${context.pathWithExt}`);\n\t\treturn null;\n\t}\n\n\treturn await callback(context);\n}\n\n// ============================================================================\n// File Path Generation\n// ============================================================================\n\n/**\n * Generates a unique file path by appending a counter if the file already exists.\n * Automatically adds .md extension if not present.\n *\n * @param app - The Obsidian App instance\n * @param folder - Folder path (empty string for root, no trailing slash needed)\n * @param baseName - Base file name without extension\n * @returns Unique file path that doesn't exist in the vault\n *\n * @example\n * ```ts\n * // If \"MyNote.md\" exists, returns \"MyNote 1.md\"\n * const path = getUniqueFilePath(app, \"\", \"MyNote\");\n *\n * // With folder: \"Projects/Task.md\" -> \"Projects/Task 1.md\"\n * const path = getUniqueFilePath(app, \"Projects\", \"Task\");\n *\n * // Root folder handling\n * const path = getUniqueFilePath(app, \"/\", \"Note\"); // -> \"Note.md\"\n * ```\n */\nexport function getUniqueFilePath(app: App, folder: string, baseName: string): string {\n\tconst normalizedFolder = folder && folder !== \"/\" ? folder : \"\";\n\tconst folderPath = normalizedFolder ? `${normalizedFolder}/` : \"\";\n\n\tlet fileName = `${baseName}.md`;\n\tlet fullPath = `${folderPath}${fileName}`;\n\tlet counter = 1;\n\n\twhile (app.vault.getAbstractFileByPath(fullPath)) {\n\t\tfileName = `${baseName} ${counter}.md`;\n\t\tfullPath = `${folderPath}${fileName}`;\n\t\tcounter++;\n\t}\n\n\treturn fullPath;\n}\n\n/**\n * Generates a unique file path by appending a counter if the file already exists.\n * Supports custom file extensions.\n *\n * @param app - The Obsidian App instance\n * @param folder - Folder path (empty string for root)\n * @param baseName - Base file name without extension\n * @param extension - File extension (defaults to \"md\")\n * @returns Unique file path that doesn't exist in the vault\n */\nexport const generateUniqueFilePath = (\n\tapp: App,\n\tfolder: string,\n\tbaseName: string,\n\textension: string = \"md\"\n): string => {\n\tconst folderPath = folder ? `${folder}/` : \"\";\n\tlet filePath = `${folderPath}${baseName}.${extension}`;\n\tlet counter = 1;\n\n\twhile (app.vault.getAbstractFileByPath(filePath)) {\n\t\tfilePath = `${folderPath}${baseName} ${counter++}.${extension}`;\n\t}\n\n\treturn filePath;\n};\n\n// ============================================================================\n// Folder Note Operations\n// ============================================================================\n\n/**\n * Checks if a file is a folder note.\n * A folder note is a file whose name matches its parent folder name.\n *\n * @param filePath - Path to the file (e.g., \"tasks/tasks.md\")\n * @returns true if the file is a folder note, false otherwise\n *\n * @example\n * ```ts\n * isFolderNote(\"tasks/tasks.md\") // true\n * isFolderNote(\"tasks/subtask.md\") // false\n * isFolderNote(\"note.md\") // false (no parent folder)\n * isFolderNote(\"projects/docs/docs.md\") // true\n * ```\n */\nexport function isFolderNote(filePath: string): boolean {\n\tif (!filePath) return false;\n\n\t// Remove .md extension for comparison\n\tconst pathWithoutExt = removeMarkdownExtension(filePath);\n\n\t// Split path into segments\n\tconst segments = pathWithoutExt.split(\"/\");\n\n\t// Need at least 2 segments (folder/file)\n\tif (segments.length < 2) return false;\n\n\t// Get the file name (last segment) and parent folder name (second to last)\n\tconst fileName = segments[segments.length - 1];\n\tconst parentFolderName = segments[segments.length - 2];\n\n\t// File is a folder note if its name matches the parent folder\n\treturn fileName === parentFolderName;\n}\n\n/**\n * Gets the folder path for a file.\n *\n * @param filePath - Path to the file (e.g., \"tasks/subtask.md\")\n * @returns Folder path without trailing slash, or empty string if file is in root\n *\n * @example\n * ```ts\n * getFolderPath(\"tasks/subtask.md\") // \"tasks\"\n * getFolderPath(\"projects/docs/notes.md\") // \"projects/docs\"\n * getFolderPath(\"note.md\") // \"\"\n * ```\n */\nexport function getFolderPath(filePath: string): string {\n\tif (!filePath) return \"\";\n\n\tconst lastSlashIndex = filePath.lastIndexOf(\"/\");\n\n\tif (lastSlashIndex === -1) return \"\";\n\n\treturn filePath.substring(0, lastSlashIndex);\n}\n\n/**\n * Gets all markdown files in a specific folder (non-recursive).\n *\n * @param app - The Obsidian App instance\n * @param folderPath - Path to the folder (e.g., \"tasks\")\n * @returns Array of TFile objects in the folder\n *\n * @example\n * ```ts\n * const files = getFilesInFolder(app, \"tasks\");\n * // Returns [task1.md, task2.md, tasks.md] but not tasks/subtasks/file.md\n * ```\n */\nexport function getFilesInFolder(app: App, folderPath: string): TFile[] {\n\tconst allFiles = app.vault.getMarkdownFiles();\n\n\treturn allFiles.filter((file) => {\n\t\tconst fileFolder = getFolderPath(file.path);\n\n\t\treturn fileFolder === folderPath;\n\t});\n}\n\n/**\n * Gets all markdown files in a folder and its subfolders recursively.\n *\n * @param app - The Obsidian App instance\n * @param folderPath - Path to the folder (e.g., \"tasks\")\n * @returns Array of TFile objects in the folder tree\n *\n * @example\n * ```ts\n * const files = getAllFilesInFolderTree(app, \"tasks\");\n * // Returns all .md files in tasks/ and all its subdirectories\n * ```\n */\nexport function getAllFilesInFolderTree(app: App, folderPath: string): TFile[] {\n\tconst allFiles = app.vault.getMarkdownFiles();\n\n\tconst normalizedFolder = folderPath ? `${folderPath}/` : \"\";\n\n\treturn allFiles.filter((file) => {\n\t\tif (!normalizedFolder) return true; // Root folder includes all files\n\n\t\treturn file.path.startsWith(normalizedFolder);\n\t});\n}\n\n/**\n * Gets the parent file path based on folder structure.\n * For a file in a folder, the parent is the folder note if it exists.\n *\n * @param app - The Obsidian App instance\n * @param filePath - Path to the file\n * @returns Path to parent file, or null if no parent exists\n *\n * @example\n * ```ts\n * // If tasks/tasks.md exists\n * getParentByFolder(app, \"tasks/subtask.md\") // \"tasks/tasks.md\"\n *\n * // If parent folder note doesn't exist\n * getParentByFolder(app, \"tasks/subtask.md\") // null\n *\n * // Root level file\n * getParentByFolder(app, \"note.md\") // null\n * ```\n */\nexport function getParentByFolder(app: App, filePath: string): string | null {\n\tconst folderPath = getFolderPath(filePath);\n\n\tif (!folderPath) return null; // File is at root level\n\n\t// Check if folder note exists\n\tconst folderSegments = folderPath.split(\"/\");\n\n\tconst parentFolderName = folderSegments[folderSegments.length - 1];\n\n\tconst potentialParentPath = `${folderPath}/${parentFolderName}.md`;\n\n\tconst parentFile = getFileByPath(app, potentialParentPath);\n\n\treturn parentFile ? potentialParentPath : null;\n}\n\n/**\n * Gets all child file paths based on folder structure.\n * Works for both folder notes and regular files.\n *\n * For folder notes (e.g., \"tasks/tasks.md\"):\n * - Returns all files directly in the folder (excluding the folder note)\n * - Includes subfolder notes one level down\n *\n * For regular files (e.g., \"tasks/task1.md\"):\n * - Returns the folder note from matching subfolder if it exists (e.g., \"tasks/task1/task1.md\")\n *\n * @param app - The Obsidian App instance\n * @param filePath - Path to the file\n * @returns Array of child file paths\n *\n * @example\n * ```ts\n * // For tasks/tasks.md (folder note)\n * getChildrenByFolder(app, \"tasks/tasks.md\")\n * // Returns [\"tasks/task1.md\", \"tasks/task2.md\", \"tasks/subtasks/subtasks.md\"]\n *\n * // For tasks/task1.md (regular file with matching subfolder)\n * getChildrenByFolder(app, \"tasks/task1.md\")\n * // Returns [\"tasks/task1/task1.md\"] if it exists\n * ```\n */\nexport function getChildrenByFolder(app: App, filePath: string): string[] {\n\tconst allFiles = app.vault.getMarkdownFiles();\n\n\t// Case 1: Folder note - get all files in the folder\n\tif (isFolderNote(filePath)) {\n\t\tconst folderPath = getFolderPath(filePath);\n\n\t\tconst children: string[] = [];\n\n\t\tallFiles.forEach((file) => {\n\t\t\t// Skip the folder note itself\n\t\t\tif (file.path === filePath) return;\n\n\t\t\tconst fileFolder = getFolderPath(file.path);\n\n\t\t\t// Direct child: file is in the same folder as the folder note\n\t\t\tif (fileFolder === folderPath) {\n\t\t\t\tchildren.push(file.path);\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Subfolder note: file is a folder note one level deeper\n\t\t\t// e.g., for \"tasks/tasks.md\", include \"tasks/subtasks/subtasks.md\"\n\t\t\tif (fileFolder.startsWith(`${folderPath}/`)) {\n\t\t\t\t// Check if it's exactly one level deeper and is a folder note\n\t\t\t\tconst relativePath = fileFolder.substring(folderPath.length + 1);\n\n\t\t\t\tconst isOneLevel = !relativePath.includes(\"/\");\n\n\t\t\t\tif (isOneLevel && isFolderNote(file.path)) {\n\t\t\t\t\tchildren.push(file.path);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\treturn children;\n\t}\n\n\t// Case 2: Regular file - check for matching subfolder with folder note\n\tconst pathWithoutExt = removeMarkdownExtension(filePath);\n\n\tconst fileName = pathWithoutExt.split(\"/\").pop() || \"\";\n\n\tconst potentialChildFolder = `${pathWithoutExt}`;\n\n\tconst potentialChildPath = `${potentialChildFolder}/${fileName}.md`;\n\n\t// Check if the child folder note exists\n\tconst childFile = getFileByPath(app, potentialChildPath);\n\n\treturn childFile ? [potentialChildPath] : [];\n}\n\n/**\n * Finds all root nodes in a folder tree.\n * Root nodes are files at the top level of the folder (directly in the folder, not in subfolders).\n *\n * @param app - The Obsidian App instance\n * @param folderPath - Path to the folder\n * @returns Array of root file paths\n *\n * @example\n * ```ts\n * // For folder structure:\n * // tasks/\n * // tasks.md (folder note)\n * // task1.md\n * // subtasks/\n * // subtasks.md\n * // subtask1.md\n *\n * findRootNodesInFolder(app, \"tasks\")\n * // Returns [\"tasks/tasks.md\", \"tasks/task1.md\"]\n * // Excludes subtasks/subtasks.md and subtasks/subtask1.md (they're in subfolder)\n * ```\n */\nexport function findRootNodesInFolder(app: App, folderPath: string): string[] {\n\treturn getFilesInFolder(app, folderPath).map((file) => file.path);\n}\n\n// ============================================================================\n// Filename Sanitization\n// ============================================================================\n\nexport interface SanitizeFilenameOptions {\n\t/**\n\t * Style of sanitization to apply.\n\t * - \"kebab\": Convert to lowercase, replace spaces with hyphens (default, backwards compatible)\n\t * - \"preserve\": Preserve spaces and case, only remove invalid characters\n\t */\n\tstyle?: \"kebab\" | \"preserve\";\n}\n\n/**\n * Sanitizes a string for use as a filename.\n * Defaults to kebab-case style for backwards compatibility.\n *\n * @param input - String to sanitize\n * @param options - Sanitization options\n * @returns Sanitized filename string\n *\n * @example\n * // Default kebab-case style (backwards compatible)\n * sanitizeForFilename(\"My File Name\") // \"my-file-name\"\n *\n * // Preserve spaces and case\n * sanitizeForFilename(\"My File Name\", { style: \"preserve\" }) // \"My File Name\"\n */\nexport const sanitizeForFilename = (\n\tinput: string,\n\toptions: SanitizeFilenameOptions = {}\n): string => {\n\tconst { style = \"kebab\" } = options;\n\n\tif (style === \"preserve\") {\n\t\treturn sanitizeFilenamePreserveSpaces(input);\n\t}\n\n\t// Default: kebab-case style (legacy behavior)\n\treturn sanitizeFilenameKebabCase(input);\n};\n\n/**\n * Sanitizes filename using kebab-case style.\n * - Removes invalid characters\n * - Converts to lowercase\n * - Replaces spaces with hyphens\n *\n * Best for: CLI tools, URLs, slugs, technical files\n *\n * @example\n * sanitizeFilenameKebabCase(\"My File Name\") // \"my-file-name\"\n * sanitizeFilenameKebabCase(\"Travel Around The World\") // \"travel-around-the-world\"\n */\nexport const sanitizeFilenameKebabCase = (input: string): string => {\n\treturn (\n\t\tinput\n\t\t\t// Remove invalid filename characters\n\t\t\t.replace(/[<>:\"/\\\\|?*]/g, \"\")\n\t\t\t// Replace spaces with hyphens\n\t\t\t.replace(/\\s+/g, \"-\")\n\t\t\t// Replace multiple hyphens with single\n\t\t\t.replace(/-+/g, \"-\")\n\t\t\t// Remove leading/trailing hyphens\n\t\t\t.replace(/^-|-$/g, \"\")\n\t\t\t// Convert to lowercase\n\t\t\t.toLowerCase()\n\t);\n};\n\n/**\n * Sanitizes filename while preserving spaces and case.\n * - Removes invalid characters only\n * - Preserves spaces and original casing\n * - Removes trailing dots (Windows compatibility)\n *\n * Best for: Note titles, human-readable filenames, Obsidian notes\n *\n * @example\n * sanitizeFilenamePreserveSpaces(\"My File Name\") // \"My File Name\"\n * sanitizeFilenamePreserveSpaces(\"Travel Around The World\") // \"Travel Around The World\"\n * sanitizeFilenamePreserveSpaces(\"File<Invalid>Chars\") // \"FileInvalidChars\"\n */\nexport const sanitizeFilenamePreserveSpaces = (input: string): string => {\n\treturn (\n\t\tinput\n\t\t\t// Remove invalid filename characters (cross-platform compatibility)\n\t\t\t.replace(/[<>:\"/\\\\|?*]/g, \"\")\n\t\t\t// Remove trailing dots (invalid on Windows)\n\t\t\t.replace(/\\.+$/g, \"\")\n\t\t\t// Remove leading/trailing whitespace\n\t\t\t.trim()\n\t);\n};\n\nexport const getFilenameFromPath = (filePath: string): string => {\n\treturn filePath.split(\"/\").pop() || \"Unknown\";\n};\n\nexport const isFileInConfiguredDirectory = (filePath: string, directory: string): boolean => {\n\tconst normalizedDir = directory.endsWith(\"/\") ? directory.slice(0, -1) : directory;\n\treturn filePath.startsWith(`${normalizedDir}/`) || filePath === normalizedDir;\n};\n"]}
|
package/dist/file/index.d.ts
CHANGED
package/dist/file/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/file/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/file/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC"}
|
package/dist/file/index.js
CHANGED
package/dist/file/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/file/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC","sourcesContent":["export * from \"./child-reference\";\nexport * from \"./file\";\nexport * from \"./file-operations\";\nexport * from \"./frontmatter\";\nexport * from \"./link-parser\";\nexport * from \"./property-utils\";\nexport * from \"./templater\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/file/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC","sourcesContent":["export * from \"./child-reference\";\nexport * from \"./file\";\nexport * from \"./file-operations\";\nexport * from \"./file-utils\";\nexport * from \"./frontmatter\";\nexport * from \"./link-parser\";\nexport * from \"./property-utils\";\nexport * from \"./templater\";\n"]}
|
|
@@ -32,4 +32,32 @@ export declare function parsePropertyLinks(value: string | string[] | undefined)
|
|
|
32
32
|
* @returns The formatted wiki link with display name alias
|
|
33
33
|
*/
|
|
34
34
|
export declare function formatWikiLink(filePath: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Represents a parsed Obsidian link with its components
|
|
37
|
+
*/
|
|
38
|
+
export interface ObsidianLink {
|
|
39
|
+
raw: string;
|
|
40
|
+
path: string;
|
|
41
|
+
alias: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Checks if a value is an Obsidian internal link in the format [[...]]
|
|
45
|
+
*/
|
|
46
|
+
export declare function isObsidianLink(value: unknown): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Parses an Obsidian internal link and extracts its components
|
|
49
|
+
*
|
|
50
|
+
* Supports both formats:
|
|
51
|
+
* - Simple: [[Page Name]]
|
|
52
|
+
* - With alias: [[Path/To/Page|Display Name]]
|
|
53
|
+
*/
|
|
54
|
+
export declare function parseObsidianLink(linkString: string): ObsidianLink | null;
|
|
55
|
+
/**
|
|
56
|
+
* Gets the display alias from an Obsidian link
|
|
57
|
+
*/
|
|
58
|
+
export declare function getObsidianLinkAlias(linkString: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Gets the file path from an Obsidian link
|
|
61
|
+
*/
|
|
62
|
+
export declare function getObsidianLinkPath(linkString: string): string;
|
|
35
63
|
//# sourceMappingURL=link-parser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link-parser.d.ts","sourceRoot":"","sources":["../../src/file/link-parser.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,IAU/D,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAezD;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,EAAE,CAQjF;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAqBvD"}
|
|
1
|
+
{"version":3,"file":"link-parser.d.ts","s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