mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-17 19:21:20 +03:00
* fix: TagNode.create with null content by default * Create five-meals-sing.md * fix: tests * fix(preset): types inference * fix: preset types * fix: preset types * fix: lock file, parser and utils * refactor: move types to separate package * fix(preset): add @bbob/core to dev deps * fix(preset): lock file * test(preset-vue): create tags * test(preset-vue): tests * chore(nx): fix nx cover deps * chore: changesets
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
import type {
|
||||
BBobCore,
|
||||
BBobCoreOptions,
|
||||
BBobCoreTagNodeTree,
|
||||
BBobPlugins,
|
||||
IterateCallback,
|
||||
NodeContent,
|
||||
PartialNodeContent
|
||||
} from "@bbob/types";
|
||||
|
||||
import { parse } from '@bbob/parser';
|
||||
import { iterate, match } from './utils';
|
||||
import { C1, C2 } from './errors'
|
||||
|
||||
import type { IterateCallback } from './utils';
|
||||
import type { NodeContent, PartialNodeContent } from "@bbob/plugin-helper";
|
||||
import type { BBobCore, BBobCoreOptions, BBobCoreTagNodeTree, BBobPlugins } from "./types";
|
||||
|
||||
export * from './types'
|
||||
|
||||
export function createTree<Options extends BBobCoreOptions = BBobCoreOptions>(tree: NodeContent[], options: Options) {
|
||||
const extendedTree = tree as BBobCoreTagNodeTree
|
||||
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
import type { ParseOptions, TagNode } from "@bbob/parser";
|
||||
import type {
|
||||
NodeContent,
|
||||
PartialNodeContent,
|
||||
TagNodeTree,
|
||||
} from "@bbob/plugin-helper";
|
||||
import type { IterateCallback, iterate } from "./utils";
|
||||
|
||||
export interface BBobCoreOptions<
|
||||
Data = unknown | null,
|
||||
Options extends ParseOptions = ParseOptions
|
||||
> extends ParseOptions {
|
||||
skipParse?: boolean;
|
||||
parser?: (source: string, options?: Options) => TagNode[];
|
||||
render?: (ast: TagNodeTree, options?: Options) => string;
|
||||
data?: Data;
|
||||
}
|
||||
|
||||
export interface BbobPluginOptions<
|
||||
Options extends ParseOptions = ParseOptions
|
||||
> {
|
||||
parse: BBobCoreOptions["parser"];
|
||||
render: (ast: TagNodeTree, options?: Options) => string;
|
||||
iterate: typeof iterate;
|
||||
data: unknown | null;
|
||||
}
|
||||
|
||||
export interface BBobPluginFunction {
|
||||
(tree: BBobCoreTagNodeTree, options: BbobPluginOptions): BBobCoreTagNodeTree;
|
||||
}
|
||||
|
||||
export interface BBobCore<
|
||||
InputValue = string | TagNode[],
|
||||
Options extends BBobCoreOptions = BBobCoreOptions
|
||||
> {
|
||||
process(
|
||||
input: InputValue,
|
||||
opts?: Options
|
||||
): {
|
||||
readonly html: string;
|
||||
tree: BBobCoreTagNodeTree;
|
||||
raw: TagNode[] | string;
|
||||
messages: unknown[];
|
||||
};
|
||||
}
|
||||
|
||||
export interface BBobCoreTagNodeTree extends Array<NodeContent> {
|
||||
messages: unknown[];
|
||||
options: BBobCoreOptions;
|
||||
walk: (cb: IterateCallback<NodeContent>) => BBobCoreTagNodeTree;
|
||||
match: (
|
||||
expression: PartialNodeContent | PartialNodeContent[],
|
||||
cb: IterateCallback<NodeContent>
|
||||
) => BBobCoreTagNodeTree;
|
||||
}
|
||||
|
||||
export type BBobPlugins = BBobPluginFunction | BBobPluginFunction[];
|
||||
@@ -1,9 +1,9 @@
|
||||
/* eslint-disable no-plusplus */
|
||||
import { IterateCallback } from "@bbob/types";
|
||||
|
||||
const isObj = (value: unknown): value is Record<string, unknown> => (typeof value === 'object' && value !== null);
|
||||
const isBool = (value: unknown): value is boolean => (typeof value === 'boolean');
|
||||
|
||||
export type IterateCallback<Content> = (node: Content) => Content
|
||||
|
||||
export function iterate<Content, Iterable = ArrayLike<Content> | Content>(t: Iterable, cb: IterateCallback<Content>): Iterable {
|
||||
const tree = t;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user