From f6a24dd9f60d9abfdfd667bb2736e26aa915d45d Mon Sep 17 00:00:00 2001 From: marihachi <marihachi0620@gmail.com> Date: Sun, 11 Apr 2021 00:34:27 +0900 Subject: [PATCH] add api doc --- src/api.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/api.ts b/src/api.ts index e0c6383..140324a 100644 --- a/src/api.ts +++ b/src/api.ts @@ -4,16 +4,25 @@ import { stringifyNode, stringifyTree } from './util'; const parser: peg.Parser = require('./parser'); +/** + * generate a node tree from the MFM string. +*/ export function parse(input: string): MfmNode[] { const nodes = parser.parse(input, { startRule: 'fullParser' }); return nodes; } +/** + * generate a node tree of plain from the MFM string. +*/ export function parsePlain(input: string): MfmPlainNode[] { const nodes = parser.parse(input, { startRule: 'plainParser' }); return nodes; } +/** + * generate a MFM string from the node tree. +*/ export function toString(tree: MfmNode[]): string export function toString(node: MfmNode): string export function toString(node: MfmNode | MfmNode[]): string { @@ -25,6 +34,9 @@ export function toString(node: MfmNode | MfmNode[]): string { } } +/** + * Inspects the node tree. +*/ export function inspect(nodes: MfmNode[], action: (node: MfmNode) => void): void { for (const node of nodes) { action(node); @@ -34,6 +46,10 @@ export function inspect(nodes: MfmNode[], action: (node: MfmNode) => void): void } } +/** + * Inspects the node tree and returns as an array the nodes that match the conditions + * of the predicate function. +*/ export function extract(nodes: MfmNode[], predicate: (node: MfmNode) => boolean): MfmNode[] { const dest = [] as MfmNode[]; -- GitLab