Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING(front-matter): remove createExtractor() #5266

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
BREAKING(front-matter): remove createExtractor()
iuioiua committed Jul 3, 2024
commit df3b044ee1c2b863fab9e3a183c79e01d0f039f9
Original file line number Diff line number Diff line change
@@ -75,86 +75,6 @@ function recognize(str: string, formats?: Format[]): Format {
*
* @param formats A descriptor containing Format-parser pairs to use for each format.
* @returns A function that extracts front matter from a string with the given parsers.
*
* @example Extract YAML front matter
* ```ts
* import { createExtractor, Parser } from "@std/front-matter";
* import { assertEquals } from "@std/assert";
* import { parse as parseYaml } from "@std/yaml/parse";
*
* const extractYaml = createExtractor({ yaml: parseYaml as Parser });
* const { attrs, body, frontMatter } = extractYaml<{ title: string }>(
* `---
* title: Three dashes marks the spot
* ---
* ferret`);
* assertEquals(attrs.title, "Three dashes marks the spot");
* assertEquals(body, "ferret");
* assertEquals(frontMatter, "title: Three dashes marks the spot");
* ```
*
* @example Extract TOML front matter
* ```ts
* import { createExtractor, Parser } from "@std/front-matter";
* import { assertEquals } from "@std/assert";
* import { parse as parseToml } from "@std/toml/parse";
*
* const extractToml = createExtractor({ toml: parseToml as Parser });
* const { attrs, body, frontMatter } = extractToml<{ title: string }>(
* `---toml
* title = 'Three dashes followed by format marks the spot'
* ---
* `);
* assertEquals(attrs.title, "Three dashes followed by format marks the spot");
* assertEquals(body, "");
* assertEquals(frontMatter, "title = 'Three dashes followed by format marks the spot'");
* ```
*
* @example Extract JSON front matter
* ```ts
* import { createExtractor, Parser } from "@std/front-matter";
* import { assertEquals } from "@std/assert";
*
* const extractJson = createExtractor({ json: JSON.parse as Parser });
* const { attrs, body, frontMatter } = extractJson<{ title: string }>(
* `---json
* {"title": "Three dashes followed by format marks the spot"}
* ---
* goat`);
* assertEquals(attrs.title, "Three dashes followed by format marks the spot");
* assertEquals(body, "goat");
* assertEquals(frontMatter, `{"title": "Three dashes followed by format marks the spot"}`);
* ```
*
* @example Extract YAML or JSON front matter
* ```ts
* import { createExtractor, Parser } from "@std/front-matter";
* import { assertEquals } from "@std/assert";
* import { parse as parseYaml } from "@std/yaml/parse";
*
* const extractYamlOrJson = createExtractor({
* yaml: parseYaml as Parser,
* json: JSON.parse as Parser,
* });
*
* let { attrs, body, frontMatter } = extractYamlOrJson<{ title: string }>(
* `---
* title: Three dashes marks the spot
* ---
* ferret`);
* assertEquals(attrs.title, "Three dashes marks the spot");
* assertEquals(body, "ferret");
* assertEquals(frontMatter, "title: Three dashes marks the spot");
*
* ({ attrs, body, frontMatter } = extractYamlOrJson<{ title: string }>(
* `---json
* {"title": "Three dashes followed by format marks the spot"}
* ---
* goat`));
* assertEquals(attrs.title, "Three dashes followed by format marks the spot");
* assertEquals(body, "goat");
* assertEquals(frontMatter, `{"title": "Three dashes followed by format marks the spot"}`);
* ```
*/
export function createExtractor(
formats: Partial<Record<Format, Parser>>,
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import {
runExtractYamlTests1,
runExtractYamlTests2,
} from "./_test_utils.ts";
import { createExtractor, type Parser } from "./create_extractor.ts";
import { createExtractor, type Parser } from "./_create_extractor.ts";

const extractYaml = createExtractor({ "yaml": parseYaml as Parser });
const extractToml = createExtractor({ "toml": parseToml as Parser });
2 changes: 1 addition & 1 deletion front_matter/any.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import {
createExtractor,
type Extractor,
type Parser,
} from "./create_extractor.ts";
} from "./_create_extractor.ts";
import { parse as parseYaml } from "@std/yaml/parse";
import { parse as parseToml } from "@std/toml/parse";

1 change: 0 additions & 1 deletion front_matter/deno.json
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@
"exports": {
".": "./mod.ts",
"./any": "./any.ts",
"./create-extractor": "./create_extractor.ts",
"./json": "./json.ts",
"./test": "./test.ts",
"./toml": "./toml.ts",
22 changes: 1 addition & 21 deletions front_matter/json.ts
Original file line number Diff line number Diff line change
@@ -4,31 +4,11 @@ import {
createExtractor,
type Extractor,
type Parser,
} from "./create_extractor.ts";
} from "./_create_extractor.ts";

/**
* Extracts and parses {@link https://www.json.org/ | JSON } from the metadata
* of front matter content.
*
* @example Extract JSON front matter
* ```ts
* import { extract } from "@std/front-matter/json";
* import { assertEquals } from "@std/assert";
*
* const output = `---json
* {
* "title": "Three dashes marks the spot"
* }
* ---
* Hello, world!`;
* const result = extract(output);
*
* assertEquals(result, {
* frontMatter: '{\n "title": "Three dashes marks the spot"\n}',
* body: "Hello, world!",
* attrs: { title: "Three dashes marks the spot" },
* });
* ```
*/
export const extract: Extractor = createExtractor({
json: JSON.parse as Parser,
1 change: 0 additions & 1 deletion front_matter/mod.ts
Original file line number Diff line number Diff line change
@@ -124,7 +124,6 @@ import { extract as extractJson } from "./json.ts";
import { extract as extractToml } from "./toml.ts";
import { extract as extractYaml } from "./yaml.ts";

export * from "./create_extractor.ts";
export * from "./test.ts";

export { extractJson, extractToml, extractYaml };
2 changes: 1 addition & 1 deletion front_matter/toml.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import {
createExtractor,
type Extractor,
type Parser,
} from "./create_extractor.ts";
} from "./_create_extractor.ts";
import { parse } from "@std/toml/parse";

/**
2 changes: 1 addition & 1 deletion front_matter/yaml.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import {
createExtractor,
type Extractor,
type Parser,
} from "./create_extractor.ts";
} from "./_create_extractor.ts";
import { parse } from "@std/yaml/parse";

/**