unified-message-control
Advanced tools
+116
| // TypeScript Version: 3.4 | ||
| import {Node} from 'unist' | ||
| import {Transformer} from 'unified' | ||
| import {Test} from 'unist-util-is' | ||
| declare namespace messageControl { | ||
| /** | ||
| * A comment marker. | ||
| */ | ||
| interface Marker<N extends Node> { | ||
| /** | ||
| * Name of marker | ||
| */ | ||
| name: string | ||
| /** | ||
| * Value after name | ||
| */ | ||
| attributes: string | ||
| /** | ||
| * Parsed attributes | ||
| */ | ||
| parameters: Record<string, unknown> | ||
| /** | ||
| * Reference to given node | ||
| */ | ||
| node: N | ||
| } | ||
| /** | ||
| * Parse a possible comment marker node to a Marker | ||
| */ | ||
| type MarkerParser<N extends Node> = (node: N) => Marker<N> | null | ||
| interface MessageControlOptionsWithReset<T extends Node> | ||
| extends BaseMessageControlOptions<T> { | ||
| /** | ||
| * Whether to treat all messages as turned off initially | ||
| */ | ||
| reset: true | ||
| /** | ||
| * List of `ruleId`s to initially turn on. | ||
| */ | ||
| enable?: string[] | ||
| } | ||
| interface MessageControlOptionsWithoutReset<T extends Node> | ||
| extends BaseMessageControlOptions<T> { | ||
| /** | ||
| * Whether to treat all messages as turned off initially | ||
| */ | ||
| reset?: false | ||
| /** | ||
| * List of `ruleId`s to turn off | ||
| */ | ||
| disable?: string[] | ||
| } | ||
| interface BaseMessageControlOptions<T extends Node> { | ||
| /** | ||
| * Name of markers that can control the message sources. | ||
| * | ||
| * For example. `{name: 'alpha'}` controls `alpha` markers: | ||
| * | ||
| * `<!--alpha ignore-->` | ||
| */ | ||
| name: string | ||
| /** | ||
| * Test for possible markers | ||
| */ | ||
| test: Test<T> | ||
| /** | ||
| * Parse a possible marker to a comment marker object (Marker) | ||
| * if possible the marker isn't a marker, should return `null`. | ||
| */ | ||
| marker: MarkerParser<T> | ||
| /** | ||
| * List of allowed `ruleId`s. When given a warning is shown | ||
| * when someone tries to control an unknown rule. | ||
| * | ||
| * For example, `{name: 'alpha', known: ['bravo']}` results | ||
| * in a warning if `charlie is configured: | ||
| * | ||
| * `<!--alpha ignore charlie-->` | ||
| */ | ||
| known?: string[] | ||
| /** | ||
| * Sources that can be controlled with `name` markers. | ||
| * | ||
| * @defaultValue `MessageControlOptions.name` | ||
| */ | ||
| sources?: string | string[] | ||
| } | ||
| type MessageControlOptions<T extends Node> = | ||
| | MessageControlOptionsWithoutReset<T> | ||
| | MessageControlOptionsWithReset<T> | ||
| } | ||
| /** | ||
| * Enable, disable, and ignore messages with unified. | ||
| */ | ||
| declare function messageControl<T extends Node>( | ||
| options?: messageControl.MessageControlOptions<T> | ||
| ): Transformer | ||
| export = messageControl |
+10
-15
@@ -9,10 +9,11 @@ 'use strict' | ||
| function messageControl(options) { | ||
| var name = options && options.name | ||
| var marker = options && options.marker | ||
| var test = options && options.test | ||
| var sources | ||
| var known | ||
| var reset | ||
| var enable | ||
| var disable | ||
| var opts = options || {} | ||
| var name = opts.name | ||
| var marker = opts.marker | ||
| var test = opts.test | ||
| var sources = opts.source | ||
| var known = opts.known | ||
| var reset = opts.reset | ||
| var enable = opts.enable || [] | ||
| var disable = opts.disable || [] | ||
@@ -27,8 +28,2 @@ if (!name) { | ||
| known = options.known | ||
| reset = options.reset | ||
| enable = options.enable || [] | ||
| disable = options.disable || [] | ||
| sources = options.source | ||
| if (!sources) { | ||
@@ -64,3 +59,3 @@ sources = [name] | ||
| if (!mark || mark.name !== options.name) { | ||
| if (!mark || mark.name !== name) { | ||
| return | ||
@@ -67,0 +62,0 @@ } |
+27
-13
| { | ||
| "name": "unified-message-control", | ||
| "version": "2.0.0", | ||
| "version": "3.0.0", | ||
| "description": "Enable, disable, and ignore messages from unified processors", | ||
@@ -15,29 +15,41 @@ "license": "MIT", | ||
| "bugs": "https://github.com/unifiedjs/unified-message-control/issues", | ||
| "funding": { | ||
| "type": "opencollective", | ||
| "url": "https://opencollective.com/unified" | ||
| }, | ||
| "author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)", | ||
| "contributors": [ | ||
| "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)", | ||
| "Christian Murphy <christian.murphy.42@gmail.com> (https://github.com/ChristianMurphy)" | ||
| "Christian Murphy <christian.murphy.42@gmail.com> (https://github.com/ChristianMurphy)", | ||
| "Thomas 'zemnmez' Shadwell (https://github.com/zemnmez)" | ||
| ], | ||
| "files": [ | ||
| "index.js" | ||
| "index.js", | ||
| "index.d.ts" | ||
| ], | ||
| "dependencies": { | ||
| "unist-util-visit": "^1.0.0", | ||
| "vfile-location": "^2.0.0" | ||
| "unist-util-visit": "^2.0.0", | ||
| "vfile-location": "^3.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/hast": "^2.0.0", | ||
| "@types/mdast": "^3.0.0", | ||
| "@types/unist": "^2.0.0", | ||
| "browserify": "^16.0.0", | ||
| "dtslint": "^2.0.0", | ||
| "esmangle": "^1.0.0", | ||
| "mdast-comment-marker": "^1.0.0", | ||
| "nyc": "^14.0.0", | ||
| "nyc": "^15.0.0", | ||
| "prettier": "^1.0.0", | ||
| "remark": "^10.0.0", | ||
| "remark-cli": "^6.0.0", | ||
| "remark-preset-wooorm": "^5.0.0", | ||
| "remark-toc": "^5.0.0", | ||
| "remark": "^11.0.0", | ||
| "remark-cli": "^7.0.0", | ||
| "remark-preset-wooorm": "^6.0.0", | ||
| "remark-toc": "^7.0.0", | ||
| "tape": "^4.0.0", | ||
| "xo": "^0.24.0" | ||
| "unified": "^8.0.0", | ||
| "unist-util-is": "^4.0.0", | ||
| "xo": "^0.25.0" | ||
| }, | ||
| "scripts": { | ||
| "format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", | ||
| "format": "remark . -qfo && prettier --write '**/*.{js,ts}' && xo --fix", | ||
| "build-bundle": "browserify index.js --bare -s unifiedMessageControl > unified-message-control.js", | ||
@@ -48,3 +60,4 @@ "build-mangle": "esmangle unified-message-control.js > unified-message-control.min.js", | ||
| "test-coverage": "nyc --reporter lcov tape test.js", | ||
| "test": "npm run format && npm run build && npm run test-coverage" | ||
| "test-types": "dtslint", | ||
| "test": "npm run test-types && npm run format && npm run build && npm run test-coverage" | ||
| }, | ||
@@ -69,2 +82,3 @@ "nyc": { | ||
| "rules": { | ||
| "unicorn/prefer-includes": "off", | ||
| "guard-for-in": "off" | ||
@@ -71,0 +85,0 @@ }, |
+2
-2
@@ -162,7 +162,7 @@ # unified-message-control | ||
| ```md | ||
| ```markdown | ||
| <!--lint ignore list-item-bullet-indent strong-marker--> | ||
| * **foo** | ||
| * __bar__ | ||
| * __bar__ | ||
| ``` | ||
@@ -169,0 +169,0 @@ |
18418
18.67%5
25%334
39.17%17
54.55%+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
Updated
Updated