mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-20 20:00:33 +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:
@@ -0,0 +1,4 @@
|
||||
dist
|
||||
es
|
||||
lib
|
||||
test
|
||||
@@ -0,0 +1,8 @@
|
||||
coverage
|
||||
dist
|
||||
lib
|
||||
es
|
||||
types
|
||||
test/*.d.ts
|
||||
test/*.map
|
||||
tsconfig.tsbuildinfo
|
||||
@@ -0,0 +1,7 @@
|
||||
pnpm-lock.yaml
|
||||
coverage
|
||||
src
|
||||
!dist
|
||||
!lib
|
||||
!es
|
||||
*.test.js
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "@bbob/types",
|
||||
"version": "3.0.2",
|
||||
"description": "Shared Typescript types of @bbob",
|
||||
"keywords": [
|
||||
"bbcode",
|
||||
"types"
|
||||
],
|
||||
"files": [
|
||||
"dist",
|
||||
"lib",
|
||||
"src",
|
||||
"es",
|
||||
"types"
|
||||
],
|
||||
"types": "types/index.d.ts",
|
||||
"module": "types/index.d.ts",
|
||||
"homepage": "https://github.com/JiLiZART/bbob",
|
||||
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/JiLiZART/bbob/issues"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/JiLiZART/bbob.git"
|
||||
},
|
||||
"scripts": {
|
||||
"types": "pkg-task"
|
||||
},
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { ParseOptions } from "./parser";
|
||||
import { NodeContent, PartialNodeContent, TagNodeObject, TagNodeTree } from "./types";
|
||||
|
||||
export interface BBobCoreOptions<
|
||||
Data = unknown | null,
|
||||
Options extends ParseOptions = ParseOptions
|
||||
> extends ParseOptions {
|
||||
skipParse?: boolean;
|
||||
parser?: (source: string, options?: Options) => TagNodeObject[];
|
||||
render?: (ast?: TagNodeTree, options?: Options) => string;
|
||||
data?: Data;
|
||||
}
|
||||
|
||||
export type IterateCallback<Content> = (node: Content) => Content
|
||||
|
||||
export interface BBobPluginOptions<
|
||||
Options extends ParseOptions = ParseOptions,
|
||||
> {
|
||||
parse: BBobCoreOptions["parser"];
|
||||
render: (ast?: TagNodeTree, options?: Options) => string;
|
||||
iterate: <Content, Iterable = ArrayLike<Content> | Content>(t: Iterable, cb: IterateCallback<Content>) => Iterable;
|
||||
data: unknown | null;
|
||||
}
|
||||
|
||||
export interface BBobPluginFunction {
|
||||
(tree: BBobCoreTagNodeTree, options: BBobPluginOptions): BBobCoreTagNodeTree;
|
||||
}
|
||||
|
||||
export interface BBobCore<
|
||||
InputValue = string | TagNodeObject[],
|
||||
Options extends BBobCoreOptions = BBobCoreOptions
|
||||
> {
|
||||
process(
|
||||
input: InputValue,
|
||||
opts?: Options
|
||||
): {
|
||||
readonly html: string;
|
||||
tree: BBobCoreTagNodeTree;
|
||||
raw: TagNodeObject[] | 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[];
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from './types'
|
||||
export * from './parser'
|
||||
export * from './core'
|
||||
export * from './preset'
|
||||
@@ -0,0 +1,44 @@
|
||||
import { TagNodeTree } from "./types";
|
||||
|
||||
export interface ParseError {
|
||||
tagName: string;
|
||||
lineNumber: number;
|
||||
columnNumber: number;
|
||||
}
|
||||
|
||||
export interface TagNode {
|
||||
readonly tag: string
|
||||
attrs?: Record<string, unknown>
|
||||
content?: TagNodeTree
|
||||
}
|
||||
|
||||
export interface Token<TokenValue = string> {
|
||||
readonly t: number // type
|
||||
readonly v: string // value
|
||||
readonly l: number // line
|
||||
readonly r: number // row
|
||||
}
|
||||
|
||||
export interface LexerTokenizer {
|
||||
tokenize: () => Token<string>[];
|
||||
isTokenNested?: (token: Token<string>) => boolean;
|
||||
}
|
||||
|
||||
export interface LexerOptions {
|
||||
openTag?: string;
|
||||
closeTag?: string;
|
||||
onlyAllowTags?: string[];
|
||||
enableEscapeTags?: boolean;
|
||||
contextFreeTags?: string[];
|
||||
onToken?: (token?: Token<string>) => void;
|
||||
}
|
||||
|
||||
export interface ParseOptions {
|
||||
createTokenizer?: (input: string, options?: LexerOptions) => LexerTokenizer;
|
||||
openTag?: string;
|
||||
closeTag?: string;
|
||||
onlyAllowTags?: string[];
|
||||
contextFreeTags?: string[];
|
||||
enableEscapeTags?: boolean;
|
||||
onError?: (error: ParseError) => void;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
|
||||
import { BBobCoreTagNodeTree, BBobPluginFunction, BBobPluginOptions } from "./core";
|
||||
import { TagNodeObject } from "./types";
|
||||
|
||||
export type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>>
|
||||
|
||||
export type PresetTagsDefinition<Key extends string = string> = Record<Key, PresetTagFunction>
|
||||
|
||||
export type PresetOptions = Record<string, unknown>
|
||||
|
||||
export type ProcessorFunction<Tags extends PresetTagsDefinition = PresetTagsDefinition, Options extends PresetOptions = PresetOptions> = (
|
||||
tags: Tags,
|
||||
tree: BBobCoreTagNodeTree,
|
||||
core: BBobPluginOptions,
|
||||
options: Options
|
||||
) => BBobCoreTagNodeTree
|
||||
|
||||
// export type ProcessorReturnType = ReturnType<ProcessorFunction>;
|
||||
|
||||
export interface PresetTagFunction<Node extends TagNodeObject = TagNodeObject, Options extends PresetOptions = PresetOptions> {
|
||||
(
|
||||
node: Node,
|
||||
data: BBobPluginOptions,
|
||||
options: Options
|
||||
): Node
|
||||
}
|
||||
|
||||
export interface PresetExtendCallback<Tags, NewTags = Tags, Options extends PresetOptions = PresetOptions> {
|
||||
(defTags: Tags, options?: Options): NewTags
|
||||
}
|
||||
|
||||
export interface PresetExecutor<Options extends PresetOptions = PresetOptions> extends BBobPluginFunction {
|
||||
(tree: BBobCoreTagNodeTree, core?: BBobPluginOptions): BBobCoreTagNodeTree;
|
||||
options: Options;
|
||||
}
|
||||
|
||||
export interface PresetFactory<
|
||||
Tags extends PresetTagsDefinition = PresetTagsDefinition,
|
||||
RootOptions extends PresetOptions = PresetOptions,
|
||||
> {
|
||||
<Options extends RootOptions>(opts?: Options): PresetExecutor<Options>;
|
||||
options?: RootOptions;
|
||||
extend: <NewTags extends PresetTagsDefinition = PresetTagsDefinition>(
|
||||
cb: PresetExtendCallback<Tags, NewTags, RootOptions>
|
||||
) => PresetFactory<NewTags, RootOptions>;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
export type StringNode = string | number
|
||||
|
||||
export interface TagNodeObject {
|
||||
readonly tag: string
|
||||
attrs?: Record<string, unknown>
|
||||
content?: TagNodeTree
|
||||
}
|
||||
|
||||
export type NodeContent = TagNodeObject | StringNode | null
|
||||
|
||||
export type PartialNodeContent = Partial<TagNodeObject> | StringNode | null
|
||||
|
||||
export type TagNodeTree = NodeContent | NodeContent[] | null
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"outDir": "./types"
|
||||
},
|
||||
"include": [
|
||||
"./src/**/*"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user