Skip to content

Commit 7431c0f

Browse files
committed
perf: move types to index
1 parent 3d1fe36 commit 7431c0f

File tree

3 files changed

+70
-70
lines changed

3 files changed

+70
-70
lines changed

src/index.ts

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,78 @@
11
// @ts-expect-error
22
import isJSON from 'is-json';
33
import {Attributes, NodeText, NodeTag} from 'posthtml-parser';
4-
import {closingSingleTagOptionEnum, closingSingleTagTypeEnum, Options, quoteStyleEnum} from '../types/index.d';
54

6-
type Node = NodeText | NodeTag & {
5+
export enum quoteStyleEnum {
6+
Smart,
7+
Single,
8+
Double
9+
}
10+
11+
export enum closingSingleTagOptionEnum {
12+
tag = 'tag',
13+
slash = 'slash',
14+
default = 'default',
15+
closeAs = 'closeAs'
16+
}
17+
18+
export enum closingSingleTagTypeEnum {
19+
tag = 'tag',
20+
slash = 'slash',
21+
default = 'default'
22+
}
23+
24+
export type Node = NodeText | NodeTag & {
725
closeAs?: closingSingleTagTypeEnum;
826
};
927

28+
export type Options = {
29+
/**
30+
* Custom single tags (selfClosing).
31+
*
32+
* @default []
33+
*/
34+
singleTags?: Array<string | RegExp>;
35+
36+
/**
37+
* Closing format for single tag.
38+
*
39+
* Formats:
40+
*
41+
* tag: `<br></br>`, slash: `<br />`, default: `<br>`
42+
*
43+
*/
44+
closingSingleTag?: closingSingleTagOptionEnum;
45+
46+
/**
47+
* If all attributes should be quoted.
48+
* Otherwise attributes will be unquoted when allowed.
49+
*
50+
* @default true
51+
*/
52+
quoteAllAttributes?: boolean;
53+
54+
/**
55+
* Replaces quotes in attribute values with `&quote;`.
56+
*
57+
* @default true
58+
*/
59+
replaceQuote?: boolean;
60+
61+
/**
62+
* Quote style
63+
*
64+
* 0 - Smart quotes
65+
* <img src="https://example.com/example.png" onload='testFunc("test")'>
66+
* 1 - Single quotes
67+
* <img src='https://example.com/example.png' onload='testFunc("test")'>
68+
* 2 - double quotes
69+
* <img src="https://example.com/example.png" onload="testFunc("test")">
70+
*
71+
* @default 2
72+
*/
73+
quoteStyle?: quoteStyleEnum;
74+
};
75+
1076
const SINGLE_TAGS: Array<string | RegExp> = [
1177
'area',
1278
'base',
@@ -229,4 +295,4 @@ function render(tree?: Node | Node[], options: Options = {}): string {
229295
}
230296
}
231297

232-
export default render;
298+
export default render;

test/test-core.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs';
22
import path from 'path';
33
import test from 'ava';
44
import render from '../src';
5-
import {closingSingleTagOptionEnum, closingSingleTagTypeEnum, quoteStyleEnum} from '../types/index.d';
5+
import {closingSingleTagOptionEnum, closingSingleTagTypeEnum, quoteStyleEnum} from '../src';
66
import parser from 'posthtml-parser';
77
import tree from './templates/parser';
88

types/index.d.ts

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)