2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-06-17 19:21:20 +03:00

feat: typescript support (#185)

* feat: initial typescript support

* feat: typescript support

* feat(plugin-helper): move files to typescript

* chore: update lock files

* feat: preset types

* fix: build

* fix: benchmark

* fix: remove pnpm cache

* fix: bench action

* fix: pnpm recursive install

* fix: nx cache

* fix: lock file

* fix: workflows

* fix: lerna support in pnpm

* fix: pnpm workspace

* fix: remove unused files

* fix: pnpm lock file

* fix: update lerna for support pnpm

* fix: lerna bootstrap

* fix: rollup build

* fix: update nx

* fix: build

* fix: add nx dep target

* fix: remove nx cache

* fix: workflow run on push only for master

* fix: test workflow run on push only for master

* fix: remove parallel for gen types

* fix: benchmark

* fix: benchmark imports

* fix: pnpm

* fix: types errors and pnpm

* fix: types

* fix: types

* refactor: parser

* fix(parser): tests

* fix: preset tests

* fix: react types

* fix: react type declarations

* fix: pnpm lock file

* fix: react preset types

* fix: lock file

* fix: vue2 types

* feat: dev container support

* fix: types

* fix: types

* refactor: rewrite pkg-task, add nx gen-types deps, fix react/render.ts

* refactor: types

* fix: types

* fix: rename gen-types to types

* fix: nx build order

* fix: nx reset

* fix: define nx deps explicit

* fix: build

* fix: nx

* fix: nx order build

* fix: nx deps

* fix: bbob cli tests

* fix: tests

* fix: cli tests and import

* fix: test cover

* fix: cli cover
This commit is contained in:
Nikolay Kost
2024-04-23 21:11:14 +02:00
committed by GitHub
parent 05246b2aea
commit 8797f7f363
149 changed files with 6102 additions and 3670 deletions
+4
View File
@@ -2,3 +2,7 @@ coverage
dist
lib
es
types
test/*.d.ts
test/*.map
tsconfig.tsbuildinfo
+1 -1
View File
@@ -1,4 +1,4 @@
package-lock.json
pnpm-lock.yaml
coverage
src
!dist
+25 -12
View File
@@ -9,14 +9,24 @@
"bbob"
],
"dependencies": {
"@bbob/core": "workspace:*",
"@bbob/plugin-helper": "workspace:*"
"@bbob/core": "*",
"@bbob/plugin-helper": "*"
},
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"browser": "dist/index.js",
"browserName": "BbobHtml",
"types": "types/index.d.ts",
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./es/index.js",
"require": "./lib/index.js",
"browser": "./dist/index.min.js",
"umd": "./dist/index.min.js"
}
},
"homepage": "https://github.com/JiLiZART/bbob",
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
"license": "MIT",
@@ -28,19 +38,22 @@
"url": "git://github.com/JiLiZART/bbob.git"
},
"scripts": {
"build:commonjs": "../../scripts/pkg-task build-commonjs",
"build:es": "../../scripts/pkg-task build-es",
"build:umd": "../../scripts/pkg-task build-umd",
"build": "npm run build:commonjs && npm run build:es && npm run build:umd",
"test": "../../scripts/pkg-task test",
"cover": "../../scripts/pkg-task cover",
"lint": "../../scripts/pkg-task lint",
"size": "../../scripts/pkg-task size",
"bundlesize": "../../scripts/pkg-task bundlesize"
"build:commonjs": "pkg-task",
"build:es": "pkg-task",
"build:umd": "pkg-task",
"build": "pkg-task",
"test": "pkg-task",
"cover": "pkg-task",
"lint": "pkg-task",
"size": "pkg-task",
"bundlesize": "pkg-task",
"types": "pkg-task",
"prepublishOnly": "npm run build"
},
"size-limit": [
{
"path": "lib/index.js"
"path": "./dist/index.min.js",
"size": "4.6 KB"
}
],
"bundlesize": [
-47
View File
@@ -1,47 +0,0 @@
import core from '@bbob/core';
import { attrsToString } from '@bbob/plugin-helper';
const SELFCLOSE_END_TAG = '/>';
const CLOSE_START_TAG = '</';
const START_TAG = '<';
const END_TAG = '>';
const renderNode = (node, { stripTags = false }) => {
if (!node) return '';
const type = typeof node;
if (type === 'string' || type === 'number') {
return node;
}
if (type === 'object') {
if (stripTags === true) {
// eslint-disable-next-line no-use-before-define
return renderNodes(node.content, { stripTags });
}
if (node.content === null) {
return [START_TAG, node.tag, attrsToString(node.attrs), SELFCLOSE_END_TAG].join('');
}
// eslint-disable-next-line no-use-before-define
return [START_TAG, node.tag, attrsToString(node.attrs), END_TAG, renderNodes(node.content), CLOSE_START_TAG, node.tag, END_TAG].join('');
}
if (Array.isArray(node)) {
// eslint-disable-next-line no-use-before-define
return renderNodes(node, { stripTags });
}
return '';
};
const renderNodes = (nodes, { stripTags = false } = {}) => []
.concat(nodes)
.reduce((r, node) => r + renderNode(node, { stripTags }), '');
const toHTML = (source, plugins, options) => core(plugins)
.process(source, { ...options, render: renderNodes }).html;
export const render = renderNodes;
export default toHTML;
+61
View File
@@ -0,0 +1,61 @@
import core, { BBobCoreOptions, BBobPlugins } from '@bbob/core';
import { attrsToString, isTagNode, TagNode, TagNodeTree } from '@bbob/plugin-helper';
const SELFCLOSE_END_TAG = '/>';
const CLOSE_START_TAG = '</';
const START_TAG = '<';
const END_TAG = '>';
export type BBobHTMLOptions = {
stripTags?: boolean
} & BBobCoreOptions
function renderNode(node?: TagNodeTree, options?: BBobHTMLOptions): string {
const { stripTags = false } = options || {}
if (typeof node === 'undefined' || node === null) {
return ''
}
if (typeof node === 'string' || typeof node === 'number') {
return String(node);
}
if (Array.isArray(node)) {
return render(node, options);
}
if (isTagNode(node)) {
if (stripTags) {
return render(node.content, options);
}
const attrs = attrsToString(node.attrs)
if (node.content === null) {
return START_TAG + node.tag + attrs + SELFCLOSE_END_TAG
}
return START_TAG + node.tag + attrs + END_TAG + render(node.content, options) + CLOSE_START_TAG + node.tag + END_TAG;
}
return '';
}
export function render(nodes: TagNodeTree, options?: BBobHTMLOptions): string {
if (Array.isArray(nodes)) {
return nodes.reduce<string>((r, node) => r + renderNode(node, options), '')
}
if (nodes) {
return renderNode(nodes, options)
}
return ''
}
export function html<InputValue = string | TagNode[]>(source: InputValue, plugins: BBobPlugins, options?: BBobHTMLOptions) {
return core<InputValue, BBobHTMLOptions>(plugins).process(source, { ...options, render: render }).html
}
export default html;
@@ -1,6 +1,6 @@
import toHTML, {render} from '../src';
import toHTML, { BBobHTMLOptions, render } from '../src';
const process = (input, params) => toHTML(input, [], params);
const process = (input: string, params?: BBobHTMLOptions) => toHTML(input, [], params);
describe('@bbob/html', () => {
test('render bbcode tag with single param as html tag', () => {
+10
View File
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"outDir": "./types"
},
"include": [
"./src/**/*"
]
}