Skip to content

Commit d4c63cd

Browse files
committed
Initial commit
0 parents  commit d4c63cd

File tree

14 files changed

+654
-0
lines changed

14 files changed

+654
-0
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.{json,remarkrc,eslintrc,sh}]
12+
indent_size = 2
13+
14+
[*.md]
15+
trim_trailing_whitespace = false

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
coverage/
2+
example.js
3+
hast-util-interactive.js
4+
hast-util-interactive.min.js

.eslintrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "eslint:recommended",
3+
"rules": {
4+
"quotes": [2, "single"]
5+
}
6+
}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
*.log
3+
coverage/
4+
node_modules/
5+
hast-util-interactive.js
6+
hast-util-interactive.min.js

.jscs.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"excludeFiles": [
3+
"coverage/",
4+
"node_modules/",
5+
"hast-util-interactive.js",
6+
"hast-util-interactive.min.js"
7+
],
8+
"preset": "crockford",
9+
"requireMultipleVarDecl": false,
10+
"disallowDanglingUnderscores": false,
11+
"requireQuotedKeysInObjects": true,
12+
"disallowKeywords": [
13+
"with"
14+
],
15+
"maximumLineLength": {
16+
"value": 79,
17+
"allExcept": [
18+
"regex",
19+
"urlComments"
20+
]
21+
},
22+
"jsDoc": {
23+
"checkAnnotations": "jsdoc3",
24+
"checkParamExistence": true,
25+
"checkParamNames": true,
26+
"checkRedundantAccess": true,
27+
"checkRedundantParams": true,
28+
"checkRedundantReturns": true,
29+
"checkReturnTypes": true,
30+
"checkTypes": "strictNativeCase",
31+
"enforceExistence": true,
32+
"requireHyphenBeforeDescription": true,
33+
"requireNewlineAfterDescription": true,
34+
"requireParamDescription": true,
35+
"requireParamTypes": true,
36+
"requireReturnDescription": true,
37+
"requireReturnTypes": true
38+
}
39+
}

.remarkrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"output": true,
3+
"plugins": [
4+
"lint",
5+
"github",
6+
"comment-config",
7+
"usage",
8+
"validate-links"
9+
],
10+
"settings": {
11+
"bullet": "*"
12+
}
13+
}

.travis.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
language: node_js
2+
node_js:
3+
- '0.10'
4+
- '0.11'
5+
- '0.12'
6+
- '4.0'
7+
- '5.0'
8+
sudo: false
9+
after_script: npm install codecov.io && cat ./coverage/lcov.info | codecov
10+
deploy:
11+
- provider: npm
12+
13+
api_key:
14+
secure: pKB5tgj3+G3p5BYlHPHiBjxzF8JzhUvmzhrsaOdQk9MGG7xkyyJRAUxFaIafcwMNncM16bWxSZ9mUB0uc56DgfAHGWb6ayAX8Hz4b4rI7HpC4bEEptApr5DpteNW3dhfIPXNc2DrYGV7CTjRh42aiivbkTBKDRH3pRwcRbBu24LgI7bFo0DATAGmjNoyVkoKdrQbj7ihIOSyF1jDnmbtFjN04MX7EB91illXTRvrF5RAazyoEhSNR25jHntjKGQYcHGVTBLHfOxPpEU597RvgpUrlujyrm/ODA/tm9mf0dpcWrr7RPvLgObdMg8hdloIVjHxwISddvZu3/pmo1Tx1HO7ggYUBsvlCnLJCbhqDaIxIWu1lt+oky2BCCHamfxA0WWHS0y8tuvDz2dgUwf2ilJToPgseCOqh2ASasJBijTK8Csh4eb3r1vd97Ib/eIpkD7NmTv+ldoMfvSTNPSX1lnu680Qf0Jl/WbgTvWYHH+WH2IKNBSWbhQrBG8OzIHnEslxW8EIQyGfFU8xCUoVkyJs1cX/yr3I4qgIYBT+7WE81kqMgueRUFK62mX0dWpnjRduJoGjoot9SEZN7NOnAYVr6CbjWAMtj6c2Ru0xobOoiTy0h78u8fBmg2jp24cyYoN6PZUkSTdLF73hT++dDrkDPmH/gk+/cPuWZ/nmoGY=
15+
on:
16+
tags: true
17+
node: '5.0'
18+
- provider: releases
19+
api_key:
20+
secure: f7TWpNAW3n3GuX13y7lAWQXp0alYrHNUV9hLlvQi5AEzNG2k2UOdKV3Zqa4l1VW+T6qbrtcSyHTXmtRiIcDp0MGoSnP7Ap0TgLTclxjH5pBMbIjLSW93bxajbuRr8kAHxpm29MHaarX27OuSlfXL2+ViK8IOwUgfctTe+Z+WfUaYAX5kBjQhhgVjIhDUntdd5EXbDXmZgiYDO9SQWaHTjFEQUVc3MMTYj/7WL0UPIiWdR1cfqT/9L8pY6+iRq6xMnCMSJEOPloF5nrygIgo94LC4uW4dLUKQjoL2qd2CScHYY2dzdK0yNFECj+CU4S3VdTQX3O4tH6lwnS6TyqdxwxzECo20Uw/TDQT9+SSSuAnuDR7bR60mhnaMXegISKTwscFR+y2E8IK1xLWXQicIvNt5yPW5z6/LdIIdmwH3IXOzPG5Cp4GTw3PULVSwSwWIjP3fjy5GJmW07vIza4U2LWiW30WvH7GppW67DOIkZTHUx/0pwY3gYa3lHkLBRs1C2+lu1SrjuSvdR3q18nlWZswDNDLQKLflAEyV5DGrwb+7pN5b5BQPVAafKldeupZ8wD3TxRD+vSBed3ZFXNR+477m9/qhK7KzpSnlJhhWvz2SWF7clSf7hHMNM5Y5nb66J4t0Qopqo5WgFrbnfZ9rXjjS4LI6TgjniqAwSDjJJ4o=
21+
file:
22+
- "hast-util-interactive.js"
23+
- "hast-util-interactive.min.js"
24+
on:
25+
tags: true

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(The MIT License)
2+
3+
Copyright (c) 2016 Titus Wormer <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
'Software'), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

example.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Dependencies:
2+
var interactive = require('./index.js');
3+
4+
// Checks:
5+
var a = interactive({
6+
'type': 'element',
7+
'tagName': 'a',
8+
'properties': {},
9+
'children': []
10+
});
11+
12+
var b = interactive({
13+
'type': 'element',
14+
'tagName': 'a',
15+
'properties': {
16+
'href': '#alpha'
17+
},
18+
'children': []
19+
});
20+
21+
22+
var c = interactive({
23+
'type': 'element',
24+
'tagName': 'video',
25+
'properties': {
26+
'controls': true
27+
},
28+
'children': []
29+
});
30+
31+
// Yields:
32+
console.log('txt', ['a: ' + a, 'b: ' + b, 'c: ' + c].join('\n'));

history.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!--remark setext-->
2+
3+
<!--lint disable no-multiple-toplevel-headings-->
4+
5+
0.0.0 / 2016-04-15
6+
==================

index.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* @author Titus Wormer
3+
* @copyright 2016 Titus Wormer
4+
* @license MIT
5+
* @module hast:util:interactive
6+
* @fileoverview Check if a node is interactive.
7+
*/
8+
9+
/* eslint-env commonjs */
10+
11+
/*
12+
* Dependencies.
13+
*/
14+
15+
var has = require('hast-util-has-property');
16+
17+
/*
18+
* Always interactive nodes.
19+
*/
20+
21+
var INTERACTIVE = [
22+
'button',
23+
'details',
24+
'embed',
25+
'iframe',
26+
'keygen',
27+
'label',
28+
'select',
29+
'textarea'
30+
];
31+
32+
/**
33+
* Check if `node` is _interactive_.
34+
*
35+
* @param {Node} node - Node to check.
36+
* @return {boolean} - Whether `node` is categorised as
37+
* interactive.
38+
*/
39+
function interactive(node) {
40+
var name;
41+
42+
if (!node || typeof node !== 'object' || node.type !== 'element') {
43+
return false;
44+
}
45+
46+
name = node.tagName;
47+
48+
return (name === 'a' && has(node, 'href')) ||
49+
(name === 'audio' && has(node, 'controls')) ||
50+
(name === 'video' && has(node, 'controls')) ||
51+
(name === 'object' && has(node, 'useMap')) ||
52+
(name === 'img' && has(node, 'useMap')) ||
53+
(name === 'input' && (node.properties || {}).type !== 'hidden') ||
54+
has(node, 'tabIndex') ||
55+
INTERACTIVE.indexOf(name) !== -1;
56+
}
57+
58+
/*
59+
* Expose.
60+
*/
61+
62+
module.exports = interactive;

package.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "hast-util-interactive",
3+
"version": "0.0.0",
4+
"description": "Check if a node is interactive",
5+
"license": "MIT",
6+
"keywords": [
7+
"hast",
8+
"html",
9+
"element",
10+
"category",
11+
"interactive"
12+
],
13+
"dependencies": {
14+
"hast-util-has-property": "^1.0.0"
15+
},
16+
"files": [
17+
"index.js"
18+
],
19+
"repository": {
20+
"type": "git",
21+
"url": "https://github.com/wooorm/hast-util-interactive.git"
22+
},
23+
"bugs": "https://github.com/wooorm/hast-util-interactive/issues",
24+
"author": "Titus Wormer <[email protected]> (http://wooorm.com)",
25+
"contributors": [
26+
"Titus Wormer <[email protected]> (http://wooorm.com)"
27+
],
28+
"devDependencies": {
29+
"browserify": "^13.0.0",
30+
"eslint": "^2.0.0",
31+
"esmangle": "^1.0.1",
32+
"istanbul": "^0.4.0",
33+
"jscs": "^3.0.0",
34+
"jscs-jsdoc": "^2.0.0",
35+
"remark": "^4.0.0",
36+
"remark-comment-config": "^3.0.0",
37+
"remark-github": "^4.0.1",
38+
"remark-lint": "^3.0.0",
39+
"remark-usage": "^3.0.0",
40+
"remark-validate-links": "^3.0.0",
41+
"tape": "^4.4.0"
42+
},
43+
"scripts": {
44+
"build-md": "remark . --quiet --frail",
45+
"build-bundle": "browserify index.js --bare -s hastUtilInteractive > hast-util-interactive.js",
46+
"build-mangle": "esmangle hast-util-interactive.js > hast-util-interactive.min.js",
47+
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
48+
"lint-api": "eslint .",
49+
"lint-style": "jscs --reporter inline .",
50+
"lint": "npm run lint-api && npm run lint-style",
51+
"test-api": "node test.js",
52+
"test-coverage": "istanbul cover test.js",
53+
"test": "npm run build && npm run lint && npm run test-coverage"
54+
}
55+
}

readme.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# hast-util-interactive [![Build Status][build-badge]][build-page] [![Coverage Status][coverage-badge]][coverage-page]
2+
3+
Check whether a [HAST node][hast] is [**interactive**][spec].
4+
5+
## Installation
6+
7+
[npm][]:
8+
9+
```bash
10+
npm install hast-util-interactive
11+
```
12+
13+
**hast-util-interactive** is also available as an AMD, CommonJS, and
14+
globals module, [uncompressed and compressed][releases].
15+
16+
## Usage
17+
18+
Dependencies:
19+
20+
```javascript
21+
var interactive = require('hast-util-interactive');
22+
```
23+
24+
Checks:
25+
26+
```javascript
27+
var a = interactive({
28+
'type': 'element',
29+
'tagName': 'a',
30+
'properties': {},
31+
'children': []
32+
});
33+
var b = interactive({
34+
'type': 'element',
35+
'tagName': 'a',
36+
'properties': {
37+
'href': '#alpha'
38+
},
39+
'children': []
40+
});
41+
var c = interactive({
42+
'type': 'element',
43+
'tagName': 'video',
44+
'properties': {
45+
'controls': true
46+
},
47+
'children': []
48+
});
49+
```
50+
51+
Yields:
52+
53+
```txt
54+
a: false
55+
b: true
56+
c: true
57+
```
58+
59+
## API
60+
61+
### `interactive(node)`
62+
63+
**Parameters**:
64+
65+
* `node` ([`Node`][node], optional) — Node to check.
66+
67+
**Returns**:
68+
69+
`boolean` — Whether `node` is an [`Element`][element] categorised
70+
as [**interactive**][spec].
71+
72+
## License
73+
74+
[MIT][license] © [Titus Wormer][author]
75+
76+
<!-- Definition -->
77+
78+
[build-badge]: https://img.shields.io/travis/wooorm/hast-util-interactive.svg
79+
80+
[build-page]: https://travis-ci.org/wooorm/hast-util-interactive
81+
82+
[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/hast-util-interactive.svg
83+
84+
[coverage-page]: https://codecov.io/github/wooorm/hast-util-interactive?branch=master
85+
86+
[npm]: https://docs.npmjs.com/cli/install
87+
88+
[releases]: https://github.com/wooorm/hast-util-interactive/releases
89+
90+
[license]: LICENSE
91+
92+
[author]: http://wooorm.com
93+
94+
[hast]: https://github.com/wooorm/hast
95+
96+
[node]: https://github.com/wooorm/hast#node
97+
98+
[element]: https://github.com/wooorm/hast#element
99+
100+
[spec]: https://html.spec.whatwg.org/#interactive-content

0 commit comments

Comments
 (0)