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): make Extractor helper type private #5334

Merged
merged 2 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions front_matter/_create_extractor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import { EXTRACT_REGEXP_MAP, RECOGNIZE_REGEXP_MAP } from "./_formats.ts";
import type { Format } from "./_types.ts";
import type { Extract, Extractor } from "./types.ts";
import type { Extractor, Format } from "./_types.ts";
import type { Extract } from "./types.ts";

/** Parser function type used alongside {@linkcode createExtractor}. */
export type Parser = <T = Record<string, unknown>>(str: string) => T;
Expand Down
10 changes: 10 additions & 0 deletions front_matter/_types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import type { Extract } from "./types.ts";

/**
* Supported format for front matter. `"unknown"` is used when auto format
* detection logic fails.
*/
export type Format = "yaml" | "toml" | "json" | "unknown";

/**
* Type for function that accepts an input string and returns
* {@linkcode Extract}.
*/
export type Extractor = <T = Record<string, unknown>>(
str: string,
) => Extract<T>;
4 changes: 2 additions & 2 deletions front_matter/any.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import { createExtractor, type Parser } from "./_create_extractor.ts";
import { parse as parseYaml } from "@std/yaml/parse";
import { parse as parseToml } from "@std/toml/parse";
import type { Extract, Extractor } from "./types.ts";
import type { Extract } from "./types.ts";

export type { Extract, Extractor };
export type { Extract };

const _extractor = createExtractor({
yaml: parseYaml as Parser,
Expand Down
4 changes: 2 additions & 2 deletions front_matter/json.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import { createExtractor, type Parser } from "./_create_extractor.ts";
import type { Extract, Extractor } from "./types.ts";
import type { Extract } from "./types.ts";

export type { Extract, Extractor };
export type { Extract };

const _extractor = createExtractor({
["json"]: JSON.parse as Parser,
Expand Down
4 changes: 2 additions & 2 deletions front_matter/toml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import { createExtractor, type Parser } from "./_create_extractor.ts";
import { parse } from "@std/toml/parse";
import type { Extract, Extractor } from "./types.ts";
import type { Extract } from "./types.ts";

export type { Extract, Extractor };
export type { Extract };

const _extractor = createExtractor({
["toml"]: parse as Parser,
Expand Down
8 changes: 0 additions & 8 deletions front_matter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,3 @@ export type Extract<T> = {
body: string;
attrs: T;
};

/**
* Type for function that accepts an input string and returns
* {@linkcode Extract}.
*/
export type Extractor = <T = Record<string, unknown>>(
str: string,
) => Extract<T>;
4 changes: 2 additions & 2 deletions front_matter/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import { createExtractor, type Parser } from "./_create_extractor.ts";
import { parse } from "@std/yaml/parse";
import type { Extract, Extractor } from "./types.ts";
import type { Extract } from "./types.ts";

export type { Extract, Extractor };
export type { Extract };

const _extractor = createExtractor({
["yaml"]: parse as Parser,
Expand Down