Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

posthtml

Package Overview
Dependencies
Maintainers
4
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

posthtml - npm Package Compare versions

Comparing version 0.11.5 to 0.11.6

12

CHANGELOG.md

@@ -5,2 +5,14 @@ # Changelog

### [0.11.6](https://github.com/posthtml/posthtml/compare/v0.11.5...v0.11.6) (2019-08-30)
### Bug Fixes
* typings ([97d89ad](https://github.com/posthtml/posthtml/commit/97d89ad))
### Features
* **typings:** Type-inference for node.prototype.match ([90d3c48](https://github.com/posthtml/posthtml/commit/90d3c48))
### [0.11.5](https://github.com/posthtml/posthtml/compare/v0.11.4...v0.11.5) (2019-08-27)

@@ -7,0 +19,0 @@

4

package.json
{
"name": "posthtml",
"version": "0.11.5",
"version": "0.11.6",
"description": "HTML/XML processor",

@@ -37,3 +37,3 @@ "keywords": [

"nyc": "^14.1.1",
"standard": "^14.0.2",
"standard": "^14.1.0",
"standard-version": "^7.0.0"

@@ -40,0 +40,0 @@ },

@@ -1,50 +0,105 @@

export interface NodeAttributes {
[attribute: string]: string;
}
type Maybe<T> = void | T;
type MaybeArray<T> = T | T[];
export type NodeContent = Array<Node | PostHTMLTree | PostHTMLTree[]>;
export namespace PostHTML {
type StringMatcher = string | RegExp;
type AttrMatcher = Record<string, StringMatcher>;
type ContentMatcher =
| StringMatcher[]
| {
tag?: StringMatcher;
attrs?: AttrMatcher;
content?: ContentMatcher[];
};
// T - Tag name
// A - Attributes
export interface Node<T = string, A = NodeAttributes> {
tag?: T;
attrs?: A;
content?: NodeContent;
}
export type Matcher<
TTag extends StringMatcher,
TAttrs extends Maybe<AttrMatcher>
> =
| StringMatcher
| {
tag?: TTag;
attrs?: TAttrs;
content?: ContentMatcher[];
};
type Matcher = string | RegExp | object;
type Expression = Matcher | Matcher[];
type CallbackNode = (node: Node) => Node | Node[];
export type Expression<
TTag extends StringMatcher,
TAttrs extends Maybe<AttrMatcher>
> = MaybeArray<Matcher<TTag, TAttrs>>;
export interface PostHTMLTree {
walk: (cb: CallbackNode) => PostHTMLTree;
match: (expression: Expression, cb: CallbackNode) => CallbackNode;
}
export type NodeCallback<
TTag extends Maybe<string> = Maybe<string>,
TAttrs extends Maybe<NodeAttributes> = Maybe<NodeAttributes>
> = (node: Node<TTag, TAttrs>) => MaybeArray<Node | RawNode>;
export interface PostHTMLOptions {
sync?: boolean;
parser?: Function;
render?: Function;
skipParse?: boolean;
}
export type NodeAttributes = Record<string, Maybe<string>>;
type Plugin<T> = (tree: PostHTMLTree) => void | PostHTMLTree | ThisType<T>;
interface NodeAPI {
walk: (cb: NodeCallback) => Node;
match: <
TTag extends StringMatcher,
TAttrs extends Maybe<AttrMatcher>,
TTagResult extends Maybe<string> = TTag extends string
? TTag
: TTag extends void
? Maybe<string>
: string,
TAttrResult extends Maybe<NodeAttributes> = TAttrs extends void
? Maybe<NodeAttributes>
: {
[P in keyof TAttrs]: string;
} &
NodeAttributes
>(
expression: Expression<TTag, TAttrs>,
cb: NodeCallback<TTagResult, TAttrResult>
) => Node<TTagResult, TAttrResult>[];
}
interface Result<M> {
html: string;
tree: PostHTMLTree;
messages: M[];
}
export interface RawNode<
TTag extends Maybe<string> = Maybe<string>,
TAttrs extends Maybe<NodeAttributes> = Maybe<NodeAttributes>
> {
tag: TTag;
attrs: TAttrs;
content?: Array<string | RawNode>;
}
declare class PostHTML<T, M> {
version: string;
name: 'posthtml';
plugins: Plugin<T>[];
messages: M[];
use<T>(plugins: Plugin<T> | Plugin<T>[]): this;
process(html: string, options?: PostHTMLOptions): Promise<Result<M>>;
export interface Node<
TTag extends Maybe<string> = Maybe<string>,
TAttrs extends Maybe<NodeAttributes> = Maybe<NodeAttributes>
> extends NodeAPI, RawNode<TTag, TAttrs> {
content?: Array<string | Node>;
}
export interface Options {
sync?: boolean;
parser?: Function;
render?: Function;
skipParse?: boolean;
}
export type Plugin<TThis> = (
tree: Node
) => void | Node | RawNode | ThisType<TThis>;
export interface Result<TMessage> {
html: string;
tree: Node;
messages: TMessage[];
}
export interface PostHTML<TThis, TMessage> {
version: string;
name: "";
plugins: Plugin<TThis>[];
messages: TMessage[];
use<TThis>(plugins: MaybeArray<Plugin<TThis>>): this;
process(html: string, options?: Options): Promise<Result<TMessage>>;
}
}
declare function posthtml<T, M>(plugins?: Plugin<T>[]): PostHTML<T, M>;
export default posthtml;
export default function posthtml<TThis, TMessage>(
plugins?: PostHTML.Plugin<TThis>[]
): PostHTML.PostHTML<TThis, TMessage>;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc