hast-util-is-element
Advanced tools
Comparing version 1.0.0 to 1.0.1
88
index.js
@@ -1,63 +0,45 @@ | ||
/** | ||
* @author Titus Wormer | ||
* @copyright 2016 Titus Wormer | ||
* @license MIT | ||
* @module rehype:lint:util:is-element | ||
*/ | ||
'use strict' | ||
'use strict'; | ||
module.exports = isElement | ||
/* eslint-env commonjs */ | ||
/** | ||
* Check if a node is a (certain) element. | ||
* | ||
* @param {*} node - Thing to check. | ||
* @param {string|Array.<string>?} [tagNames] - Name of element. | ||
* @return {boolean} - Whether a node is a (certain) element. | ||
* @throws {Error} - When `tagNames` is given but invalid. | ||
*/ | ||
/* Check if, whether `tagNames` is given, a node is an element | ||
* or an element matching `tagNames`. */ | ||
function isElement(node, tagNames) { | ||
var name; | ||
var name | ||
if ( | ||
!( | ||
tagNames === null || | ||
tagNames === undefined || | ||
typeof tagNames === 'string' || | ||
(typeof tagNames === 'object' && tagNames.length) | ||
) | ||
) { | ||
throw new Error( | ||
'Expected `string` or `Array.<string>` for ' + | ||
'`tagNames`, not `' + tagNames + '`' | ||
); | ||
} | ||
if ( | ||
!( | ||
tagNames === null || | ||
tagNames === undefined || | ||
typeof tagNames === 'string' || | ||
(typeof tagNames === 'object' && tagNames.length !== 0) | ||
) | ||
) { | ||
throw new Error( | ||
'Expected `string` or `Array.<string>` for `tagNames`, not `' + | ||
tagNames + | ||
'`' | ||
) | ||
} | ||
if ( | ||
!node || | ||
typeof node !== 'object' || | ||
node.type !== 'element' || | ||
typeof node.tagName !== 'string' | ||
) { | ||
return false; | ||
} | ||
if ( | ||
!node || | ||
typeof node !== 'object' || | ||
node.type !== 'element' || | ||
typeof node.tagName !== 'string' | ||
) { | ||
return false | ||
} | ||
if (tagNames === null || tagNames === undefined) { | ||
return true; | ||
} | ||
if (tagNames === null || tagNames === undefined) { | ||
return true | ||
} | ||
name = node.tagName; | ||
name = node.tagName | ||
if (typeof tagNames === 'string') { | ||
return name === tagNames; | ||
} | ||
if (typeof tagNames === 'string') { | ||
return name === tagNames | ||
} | ||
return tagNames.indexOf(name) !== -1; | ||
return tagNames.indexOf(name) !== -1 | ||
} | ||
/* | ||
* Expose. | ||
*/ | ||
module.exports = isElement; |
{ | ||
"name": "hast-util-is-element", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Check if a node is a (certain) element", | ||
@@ -14,11 +14,4 @@ "license": "MIT", | ||
], | ||
"dependencies": {}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/wooorm/hast-util-is-element.git" | ||
}, | ||
"bugs": "https://github.com/wooorm/hast-util-is-element/issues", | ||
"repository": "syntax-tree/hast-util-is-element", | ||
"bugs": "https://github.com/syntax-tree/hast-util-is-element/issues", | ||
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
@@ -28,29 +21,51 @@ "contributors": [ | ||
], | ||
"files": [ | ||
"index.js" | ||
], | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"browserify": "^13.0.0", | ||
"eslint": "^2.0.0", | ||
"browserify": "^16.0.0", | ||
"esmangle": "^1.0.1", | ||
"istanbul": "^0.4.0", | ||
"jscs": "^3.0.0", | ||
"jscs-jsdoc": "^2.0.0", | ||
"remark": "^4.0.0", | ||
"remark-comment-config": "^3.0.0", | ||
"remark-github": "^4.0.1", | ||
"remark-lint": "^3.0.0", | ||
"remark-usage": "^3.0.0", | ||
"remark-validate-links": "^3.0.0", | ||
"tape": "^4.4.0" | ||
"nyc": "^12.0.0", | ||
"prettier": "^1.13.5", | ||
"remark-cli": "^5.0.0", | ||
"remark-preset-wooorm": "^4.0.0", | ||
"tape": "^4.4.0", | ||
"xo": "^0.21.0" | ||
}, | ||
"scripts": { | ||
"build-md": "remark . --quiet --frail", | ||
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix", | ||
"build-bundle": "browserify index.js --bare -s hastUtilIsElement > hast-util-is-element.js", | ||
"build-mangle": "esmangle hast-util-is-element.js > hast-util-is-element.min.js", | ||
"build": "npm run build-md && npm run build-bundle && npm run build-mangle", | ||
"lint-api": "eslint .", | ||
"lint-style": "jscs --reporter inline .", | ||
"lint": "npm run lint-api && npm run lint-style", | ||
"test-api": "node test.js", | ||
"test-coverage": "istanbul cover test.js", | ||
"test": "npm run build && npm run lint && npm run test-coverage" | ||
"build": "npm run build-bundle && npm run build-mangle", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test.js", | ||
"test": "npm run format && npm run build && npm run test-coverage" | ||
}, | ||
"prettier": { | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"singleQuote": true, | ||
"bracketSpacing": false, | ||
"semi": false, | ||
"trailingComma": "none" | ||
}, | ||
"xo": { | ||
"prettier": true, | ||
"esnext": false, | ||
"ignores": [ | ||
"hast-util-is-element.js" | ||
] | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"remarkConfig": { | ||
"plugins": [ | ||
"preset-wooorm" | ||
] | ||
} | ||
} |
@@ -13,58 +13,14 @@ # hast-util-is-element [![Build Status][build-badge]][build-page] [![Coverage Status][coverage-badge]][coverage-page] | ||
**hast-util-is-element** is also available as an AMD, CommonJS, and | ||
globals module, [uncompressed and compressed][releases]. | ||
## Usage | ||
Dependencies: | ||
```javascript | ||
var isElement = require('hast-util-is-element'); | ||
``` | ||
var is = require('hast-util-is-element') | ||
Given a non-element: | ||
is({type: 'text', value: 'foo'}) // => false | ||
```javascript | ||
var result = isElement({ | ||
'type': 'text', | ||
'value': 'foo' | ||
}); | ||
``` | ||
is({type: 'element', tagName: 'a'}, 'a') // => true | ||
Yields: | ||
```js | ||
false | ||
is({type: 'element', tagName: 'a'}, ['a', 'area']) // => true | ||
``` | ||
Given a matching element: | ||
```javascript | ||
result = isElement({ | ||
'type': 'element', | ||
'tagName': 'a' | ||
}, 'a'); | ||
``` | ||
Yields: | ||
```js | ||
true | ||
``` | ||
Given multiple tagNames: | ||
```javascript | ||
result = isElement({ | ||
'type': 'element', | ||
'tagName': 'a' | ||
}, ['a', 'area']); | ||
``` | ||
Yields: | ||
```js | ||
true | ||
``` | ||
## API | ||
@@ -80,12 +36,24 @@ | ||
**Parameters**: | ||
###### Parameters | ||
* `node` (`*`) — Value to check; | ||
* `tagName` (`string`, optional) — Value `node`s `tagName` must match; | ||
* `tagNames` (`string`, optional) — Value including `node`s `tagName`. | ||
* `tagNames` (`Array.<string>`, optional) — Value including `node`s `tagName`. | ||
**Returns**: `boolean`, whether `node` passes the test. | ||
###### Returns | ||
**Throws**: when the second parameter is given but invalid. | ||
`boolean` — whether `node` passes the test. | ||
###### Throws | ||
`Error` — When the second parameter is given but invalid. | ||
## Contribute | ||
See [`contributing.md` in `syntax-tree/hast`][contributing] for ways to get | ||
started. | ||
This organisation has a [Code of Conduct][coc]. By interacting with this | ||
repository, organisation, or community you agree to abide by its terms. | ||
## License | ||
@@ -97,14 +65,12 @@ | ||
[build-badge]: https://img.shields.io/travis/wooorm/hast-util-is-element.svg | ||
[build-badge]: https://img.shields.io/travis/syntax-tree/hast-util-is-element.svg | ||
[build-page]: https://travis-ci.org/wooorm/hast-util-is-element | ||
[build-page]: https://travis-ci.org/syntax-tree/hast-util-is-element | ||
[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/hast-util-is-element.svg | ||
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-is-element.svg | ||
[coverage-page]: https://codecov.io/github/wooorm/hast-util-is-element?branch=master | ||
[coverage-page]: https://codecov.io/github/syntax-tree/hast-util-is-element?branch=master | ||
[npm]: https://docs.npmjs.com/cli/install | ||
[releases]: https://github.com/wooorm/hast-util-is-element/releases | ||
[license]: LICENSE | ||
@@ -114,6 +80,10 @@ | ||
[hast]: https://github.com/wooorm/hast | ||
[hast]: https://github.com/syntax-tree/hast | ||
[node]: https://github.com/wooorm/hast#node | ||
[node]: https://github.com/syntax-tree/unist#node | ||
[element]: https://github.com/wooorm/hast#element | ||
[element]: https://github.com/syntax-tree/hast#element | ||
[contributing]: https://github.com/syntax-tree/hast/blob/master/contributing.md | ||
[coc]: https://github.com/syntax-tree/hast/blob/master/code-of-conduct.md |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
8
5921
4
37
86
1