Load and manipulate Obsidian vault data
Go to file
2024-05-09 09:46:00 -04:00
src Add more tests and readme docs 2024-05-09 09:46:00 -04:00
.eslintrc.json Initial commit 2024-05-08 11:09:37 -04:00
.gitignore Initial commit 2024-05-08 11:09:37 -04:00
.npmignore Begin adding tests 2024-05-08 15:37:54 -04:00
LICENCE.md Initial commit 2024-05-08 11:09:37 -04:00
package-lock.json Add more tests and readme docs 2024-05-09 09:46:00 -04:00
package.json Add more tests and readme docs 2024-05-09 09:46:00 -04:00
README.md Add more tests and readme docs 2024-05-09 09:46:00 -04:00
tsconfig.json Initial commit 2024-05-08 11:09:37 -04:00

Hammerstone

Load and manipulate Obsidian vault data

API

new Vault(vaultRootPath [, options])

Create a new Vault object. Searches for markdown files in the given directory, loads, and parses frontmatter for each document.

Options

Option Description Default
ignorePatterns An optional array of globs to ignore when discovering docs []

vault.process(fn)

Process all documents in the vault. Each document is passed to the provided function.

Returns a reference to the vault to allow for chaining of document processing flows.

vault.scope(fn)

Returns a VaultView containing only the documents which the provided function returns a truthy value for (similar to Array.filter()).

A VaultView has the .process() function just as a Vault does. You can also call .unscope() on a VaultView which returns a reference to the original vault, allowing you to chain processing flows which dive in and out of different filtered scopes.

vault.write()

Write all vault documents back to disk.

vault.documents

(Property) An array of all documents in this vault

vault.index

(Property) A map of document slugs to the document itself

new MarkdownDocument(filePath, vault)

A MarkdownDocument object represents a single document in the Vault. Generally, the Vault itself handles creating these objects, which can be accessed via the .documents or .index properties on the Vault.

markdownDocument.setMarkdown(markdownContent)

Set the markdown content of this document (separately from the YAML frontmatter)

markdownDocument.setFrontmatter(frontmatterShape)

Set the frontmatter content of this document (separately from the markdown)

markdownDocument.setContent(newContent)

Set the full text content of this document (raw YAML frontmatter and markdown)

markdownDocument.hasTag(tag)

Check if this document is tagged with the given tag

markdownDocument.hasTaxonomy(dirs)

Check if this document exists in the given directory structure as an array of directory names

markdownDocument.revert()

Revert any changes to this document back to its original loaded content

markdownDocument.write()

Write this file back to disk

markdownDocument.markdown

(Property) The markdown contents of this document

markdownDocument.frontmatter

(Property) The frontmatter contents of this document

markdownDocument.content

(Property) The full content of this document