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

[typescript] Add sections support to the gray-matter.d.ts typings #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 57 additions & 6 deletions gray-matter.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,87 @@
declare function matter<
I extends matter.Input,
O extends matter.GrayMatterOption<I, O>
>(input: I | { content: I }, options?: O): matter.GrayMatterFile<I>
>(input: I | { content: I }, options?: O): matter.GrayMatterFile<I>

declare namespace matter {
type Input = string | Buffer
interface GrayMatterOption<
I extends Input,
O extends GrayMatterOption<I, O>
> {
> {
parser?: () => void
eval?: boolean
excerpt?: boolean | ((input: I, options: O) => string)
excerpt_separator?: string
engines?: {
[index: string]:
| ((string) => object)
| { parse: (string) => object; stringify?: (object) => string }
| ((string) => object)
| { parse: (string) => object; stringify?: (object) => string }
}
language?: string
delimiters?: string | [string, string]
sections?: boolean
section?: (section: GrayMatterSection, sections?: Array<GrayMatterSection>) => void
}

/**
* Structure representing the matter section
*/
interface GrayMatterSection {
/**
* Key of the section
*/
key: string;
/**
* The object created by parsing section matter
*/
data: { [key: string]: any }
/**
* The section string, with matter stripped.
*/
content: string
}

/**
* Structure representing the result of parse or read operations
*/
interface GrayMatterFile<I extends Input> {
data: object
/**
* The object created by parsing front-matter
*/
data: { [key: string]: any }
/**
* The input string, with matter stripped.
* If sections were used, there will be in separate property
*/
content: string
/**
* An excerpt, if defined on the options
*/
excerpt?: string
/**
* The original input string (or buffer)
*/
orig: Buffer | I
/**
* The front-matter language that was parsed. yaml is the default
*/
language: string
/**
* The raw, un-parsed front-matter string
*/
matter: string
/**
* Stringify the file by converting file.data to a string in the given language, wrapping it in delimiters and prepending it to file.content.
* @param {string} `lang` front-matter language to use. Only YAML and JSON can be stringified
*/
stringify(lang: string): string
/**
* Sections, if defined on the options
*/
sections?: Array<GrayMatterSection>
}

/**
* Stringify an object to YAML or the specified language, and
* append it to the given string. By default, only YAML and JSON
Expand Down