From ebe67781aae884efe3498b8099d73116c0f37450 Mon Sep 17 00:00:00 2001 From: Endeavorance Date: Fri, 6 Jun 2025 09:50:52 -0400 Subject: [PATCH] 1.1.0 --- README.md | 95 ++++++++++++++++++++++++++++++++++++++++++---------- build.ts | 2 +- package.json | 2 +- 3 files changed, 79 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index c4323c7..57d711b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ # EMDY -Parse and serialize Markdown files with optional frontmatter +Enhanced Markdown with YAML + +EMDY makes it easy to work with markdown files like data. It provides a simple +JSON-like API for parsing and serializing objects to and from a markdown + YAML +frontmatter format. + ## Install @@ -19,33 +24,87 @@ bun add @endeavorance/emdy ``` ## Usage -EMDY exports a top level `EMDY` constant which has two functions: - -- `EMDY.parse(md: string, markdownKey = "content")` -- `EMDY.stringify(data: Object, markdownKey = "content")` - ```typescript import EMDY from "@endeavorance/emdy"; +EMDY.parse(/* ... */); -const myMDFile = ` +// -- or -- + +import { parse, stringify, parseAll } from "@endeavorance/emdy"; +parse(/* ... */); +``` +## Functions + +EMDY provides three main functions for working with markdown files. + +### `parse(content: string, markdownKey?: string): Record` + +Parses a single EMDY document. Frontmatter keys become top level properties +in the return value. The markdown content is loaded as-is into a key based +on the provided `markdownKey`. If no `markdownKey` is provided, it will default +to `content`. + +```typescript +const emdyDoc = ` --- -tags: ["fancy", "stuff"] +key: value +anotherKey: anotherValue --- -This is my markdown document! +This is my markdown content. `.trim(); -const parsed = EMDY.parse(myMDFile); - -console.log(parsed); +console.log(EMDY.parse(emdyDoc)); /* +Output: { - content: "This is my markdown document!", - tags: ["fancy", "stuff"] + "key": "value", + "anotherKey": "anotherValue", + "content": "This is my markdown content." } */ - -const stringified = EMDY.stringify(parsed); -console.log(stringified); -// Prints the original document ``` + +### `parseAll(content: string, markdownKey?: string): Record[]` + +Similar to `.parse`, but parses multiple EMDY documents from a single string, +returning an array of objects. + +Documents are separated by a line containing only three equals signs: + +```md +--- +property: value +--- + +This is the first document +=== +This is the second document +``` + +### `stringify(data: Record, markdownKey?: string): Record` + +Given an object, serializes it to a string in EMDY format. Uses the `markdownKey` +to identify which property in the object holds the markdown content. If no +`markdownKey` is provided, it will default to `content`. + +```typescript +const emdyObj = { + key: "value", + anotherKey: "anotherValue", + content: "This is my markdown content." +}; + +console.log(EMDY.stringify(emdyObj)); + +/* +Output: +--- +key: value +anotherKey: anotherValue +--- + +This is my markdown content. +*/ +``` + diff --git a/build.ts b/build.ts index ad9f7c5..452f599 100644 --- a/build.ts +++ b/build.ts @@ -6,4 +6,4 @@ await Bun.build({ minify: true, }); -export { }; +export {}; diff --git a/package.json b/package.json index 33fcbfe..b5c5a60 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@endeavorance/emdy", - "version": "1.0.0", + "version": "1.1.0", "module": "dist/index.js", "exports": { ".": {