unist-util-is
Advanced tools
Comparing version 2.1.2 to 2.1.3
18
index.js
'use strict' | ||
/* eslint-disable max-params */ | ||
/* Expose. */ | ||
module.exports = is | ||
/* Assert if `test` passes for `node`. | ||
* When a `parent` node is known the `index` of node */ | ||
// Assert if `test` passes for `node`. When a `parent` node is known the | ||
// `index` of node. | ||
// eslint-disable-next-line max-params | ||
function is(test, node, index, parent, context) { | ||
@@ -69,4 +67,4 @@ var hasParent = parent !== null && parent !== undefined | ||
/* Utility assert each property in `test` is represented | ||
* in `node`, and each values are strictly equal. */ | ||
// Utility assert each property in `test` is represented in `node`, and each | ||
// values are strictly equal. | ||
function matchesFactory(test) { | ||
@@ -107,4 +105,4 @@ return matches | ||
/* Utility to convert a string into a function which checks | ||
* a given node’s type for said string. */ | ||
// Utility to convert a string into a function which checks a given node’s type | ||
// for said string. | ||
function typeFactory(test) { | ||
@@ -118,5 +116,5 @@ return type | ||
/* Utility to return true. */ | ||
// Utility to return true. | ||
function ok() { | ||
return true | ||
} |
{ | ||
"name": "unist-util-is", | ||
"version": "2.1.2", | ||
"version": "2.1.3", | ||
"description": "Utility to check if a node passes a test", | ||
@@ -18,5 +18,5 @@ "license": "MIT", | ||
"bugs": "https://github.com/syntax-tree/hast-util-to-html/issues", | ||
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)", | ||
"contributors": [ | ||
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)" | ||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)" | ||
], | ||
@@ -29,14 +29,14 @@ "files": [ | ||
"browserify": "^16.0.0", | ||
"esmangle": "^1.0.1", | ||
"nyc": "^11.0.0", | ||
"prettier": "^1.12.1", | ||
"remark-cli": "^5.0.0", | ||
"remark-preset-wooorm": "^4.0.0", | ||
"nyc": "^14.0.0", | ||
"prettier": "^1.0.0", | ||
"remark-cli": "^6.0.0", | ||
"remark-preset-wooorm": "^5.0.0", | ||
"tape": "^4.0.0", | ||
"xo": "^0.20.0" | ||
"tinyify": "^2.0.0", | ||
"xo": "^0.24.0" | ||
}, | ||
"scripts": { | ||
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix", | ||
"build-bundle": "browserify index.js --bare -s unistUtilIs > unist-util-is.js", | ||
"build-mangle": "esmangle < unist-util-is.js > unist-util-is.min.js", | ||
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", | ||
"build-bundle": "browserify . -s unistUtilIs > unist-util-is.js", | ||
"build-mangle": "browserify . -s unistUtilIs -p tinyify > unist-util-is.min.js", | ||
"build": "npm run build-bundle && npm run build-mangle", | ||
@@ -59,5 +59,2 @@ "test-api": "node test", | ||
"rules": { | ||
"guard-for-in": "off", | ||
"no-var": "off", | ||
"prefer-arrow-callback": "off", | ||
"unicorn/prefer-type-error": "off" | ||
@@ -64,0 +61,0 @@ }, |
@@ -1,10 +0,18 @@ | ||
# unist-util-is [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
# unist-util-is | ||
[**Unist**][unist] utility to check if a node passes a test. | ||
[![Build][build-badge]][build] | ||
[![Coverage][coverage-badge]][coverage] | ||
[![Downloads][downloads-badge]][downloads] | ||
[![Size][size-badge]][size] | ||
[![Sponsors][sponsors-badge]][collective] | ||
[![Backers][backers-badge]][collective] | ||
[![Chat][chat-badge]][chat] | ||
## Installation | ||
[**unist**][unist] utility to check if a node passes a test. | ||
## Install | ||
[npm][]: | ||
```bash | ||
```sh | ||
npm install unist-util-is | ||
@@ -48,10 +56,9 @@ ``` | ||
— When not given, checks if `node` is a [`Node`][node]. | ||
When `string`, works like passing `function (node) {return | ||
node.type === test}`. | ||
When `array`, checks any one of the subtests pass. | ||
When `string`, works like passing `node => node.type === test`. | ||
When `array`, checks if any one of the subtests pass. | ||
When `object`, checks that all keys in `test` are in `node`, | ||
and that they have (strictly) equal values | ||
and that they have strictly equal values | ||
* `node` ([`Node`][node]) — Node to check. `false` is returned | ||
* `index` (`number`, optional) — Position of `node` in `parent` | ||
* `parent` (`Node`, optional) — Parent of `node` | ||
* `index` (`number`, optional) — [Index][] of `node` in `parent` | ||
* `parent` ([`Node`][node], optional) — [Parent][] of `node` | ||
* `context` (`*`, optional) — Context object to invoke `test` with | ||
@@ -61,4 +68,4 @@ | ||
`boolean` — Whether `test` passed _and_ `node` is a [`Node`][node] (object | ||
with `type` set to non-empty `string`). | ||
`boolean` — Whether `test` passed *and* `node` is a [`Node`][node] (object | ||
with `type` set to a non-empty `string`). | ||
@@ -102,7 +109,9 @@ #### `function test(node[, index, parent])` | ||
See [`contributing.md` in `syntax-tree/unist`][contributing] for ways to get | ||
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get | ||
started. | ||
See [`support.md`][support] for ways to get help. | ||
This organisation has a [Code of Conduct][coc]. By interacting with this | ||
repository, organisation, or community you agree to abide by its terms. | ||
This project has a [Code of Conduct][coc]. | ||
By interacting with this repository, organisation, or community you agree to | ||
abide by its terms. | ||
@@ -115,16 +124,40 @@ ## License | ||
[travis-badge]: https://img.shields.io/travis/syntax-tree/unist-util-is.svg | ||
[build-badge]: https://img.shields.io/travis/syntax-tree/unist-util-is.svg | ||
[travis]: https://travis-ci.org/syntax-tree/unist-util-is | ||
[build]: https://travis-ci.org/syntax-tree/unist-util-is | ||
[codecov-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-is.svg | ||
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-is.svg | ||
[codecov]: https://codecov.io/github/syntax-tree/unist-util-is | ||
[coverage]: https://codecov.io/github/syntax-tree/unist-util-is | ||
[downloads-badge]: https://img.shields.io/npm/dm/unist-util-is.svg | ||
[downloads]: https://www.npmjs.com/package/unist-util-is | ||
[size-badge]: https://img.shields.io/bundlephobia/minzip/unist-util-is.svg | ||
[size]: https://bundlephobia.com/result?p=unist-util-is | ||
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg | ||
[backers-badge]: https://opencollective.com/unified/backers/badge.svg | ||
[collective]: https://opencollective.com/unified | ||
[chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg | ||
[chat]: https://spectrum.chat/unified/syntax-tree | ||
[npm]: https://docs.npmjs.com/cli/install | ||
[license]: LICENSE | ||
[license]: license | ||
[author]: http://wooorm.com | ||
[author]: https://wooorm.com | ||
[contributing]: https://github.com/syntax-tree/.github/blob/master/contributing.md | ||
[support]: https://github.com/syntax-tree/.github/blob/master/support.md | ||
[coc]: https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md | ||
[unist]: https://github.com/syntax-tree/unist | ||
@@ -134,6 +167,6 @@ | ||
[test]: #function-testnode-index-parent | ||
[parent]: https://github.com/syntax-tree/unist#parent-1 | ||
[contributing]: https://github.com/syntax-tree/unist/blob/master/contributing.md | ||
[index]: https://github.com/syntax-tree/unist#index | ||
[coc]: https://github.com/syntax-tree/unist/blob/master/code-of-conduct.md | ||
[test]: #function-testnode-index-parent |
10186
168
90