Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 09c4923

Browse files
committedMar 7, 2016
Initial commit
0 parents  commit 09c4923

File tree

14 files changed

+424
-0
lines changed

14 files changed

+424
-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-labelable.js
4+
hast-util-labelable.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-labelable.js
6+
hast-util-labelable.min.js

‎.jscs.json

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

‎.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+
email: tituswormer@gmail.com
13+
api_key:
14+
secure: fu+loGhnPMCso88ejeir+vcbuEMkD50XFSYNMPBqcMVg1UHrFlEoid9lG0wZ3Be7kIyal8MNmzD2lMHUsK+964jPq4Mh6hTGTdrrtuUeytXWb/1rapu/bh15aorvYFBhe7kSV684Z/6AZ/xJ2QKWW3a1XD9pLBE0xD4bWtkTLfhsM/+6QcKNIXnW+70+Yja1FumBhDLgze65nOlqblU3Wmksr+4IWS9/BhaWxH2oWY1cC0UY81HmGYbnV8Y3Q8w/+mC+wciRKE9rmUnv5ZbcUkn0nsQTpCaySaCjjNOUyIGkMdqUmqdbC8N/rUGx/Jh2X9I8YIZlm0HkiAB6eCbzJ/Xu9KgvizskJyCRGpRehPcaFGMVvIm1XRMoysc7UI0dzdDVEMQ8JYmpk9M0pfpRRKY2jjeIE1ZiEx3td+FjqGUEhSB6niTr18QCa5DNxwbLRjtTRpN6Dz6ZHG8rHhWWm2Sp3Ydu6GVg27ZbRyA12txI3fyD3JoMmYzGvrqWyJiH3AoOiP/JXf8y3Po1cUXWJ0X/7JKCj4DS/d8yEoU7pM0clpPjfFBCYxXMxcZLZD47p5+ubae5/Or9zNu/gwmHUM4AaD/+rTlCcK3tmEt064L115tQS6LAfSoawDIeQm9uh+y8XwEOPhR1i3uuk8lBKdtPJaQmtjdRo1+yllvwk+E=
15+
on:
16+
tags: true
17+
node: '5.0'
18+
- provider: releases
19+
api_key:
20+
secure: dgjUnUh3jwndStbkZKpGBML6c160rlWiU+F+PRXwrrfN+3HOJo0Vsu62r7F93BT58lEJR7Lj29x9Dw6ZxdQSFh/N5FzN04gvrUhW3St+4aYEVCGQ+Aq04q/Nmgkf7aBrRtF8cQzCzUf9L14FWXXCWF6Qd+HHAiu3vz9rq8ySN9q9VGCzverQ5OIkMwHcwL+Jorlk9h1wTg9pgqvQPJ8RgWIfCO4q3hSYg9Czaqf+74DrOt9mdfByQSajOUAVXK92ssvqbaWtwEqL/PzTwtNHK4n/TOmxcTlg9oKBy07mAaUeHJRbFujWcDSyt4GTo18I9RpjKvXQdjAZFMUTd78Q365Io1eSals8atMyWPYAwpwHVFj4qqCp5sNwuWltZEibageflwGRLBL71IDWU+YRyTQ7+SREK+WodOzm+EY7S248f/+Dcdyv6SCsaWWTGOiVX9sO6Mv01Og+cGr2DT4oocfBSuvEW5//t1r4ah317HQRuAEzvZUWOSj+6y3cL0BUtspLgV/YDQ3vJ++X1V5tteg0EBjWXiSZiXshPAe4G3J9aruAKjqXLS0Xmd2rM5okqBkACQlx12v+7m42jLehf6cCbKaH9f35zK3aRv5K9vy0qi5KkHGuT4m1cmYL3XvBbGUsdDRTfzcDLvxUeSElbt6V2ZftaI8HzfM+jdTIJi4=
21+
file:
22+
- "hast-util-labelable.js"
23+
- "hast-util-labelable.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 <tituswormer@gmail.com>
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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Dependencies:
2+
var labelable = require('./index.js');
3+
4+
var a = labelable({
5+
'type': 'element',
6+
'tagName': 'div'
7+
});
8+
9+
var b = labelable({
10+
'type': 'element',
11+
'tagName': 'input'
12+
});
13+
14+
var c = labelable({
15+
'type': 'element',
16+
'tagName': 'input',
17+
'properties': {
18+
'type': 'hidden'
19+
}
20+
});
21+
22+
// Yields:
23+
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-03-07
6+
==================

‎index.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @author Titus Wormer
3+
* @copyright 2016 Titus Wormer
4+
* @license MIT
5+
* @module hast:util:labelable
6+
* @fileoverview Check whether a node is labelable.
7+
*/
8+
9+
'use strict';
10+
11+
/* eslint-env commonjs */
12+
13+
/**
14+
* Check whether a `node` is labelable.
15+
*
16+
* @see https://html.spec.whatwg.org/#category-label
17+
*
18+
* @param {Node?} [node] - HAST node to check.
19+
* @return {boolean} - whether `node` is labelable.
20+
*/
21+
function labelable(node) {
22+
var name = node && node.type === 'element' && node.tagName;
23+
var type = name && node.properties && node.properties.type;
24+
25+
return Boolean(
26+
name &&
27+
(
28+
name === 'button' ||
29+
name === 'keygen' ||
30+
name === 'meter' ||
31+
name === 'output' ||
32+
name === 'progress' ||
33+
name === 'select' ||
34+
name === 'textarea' ||
35+
(name === 'input' && type !== 'hidden')
36+
)
37+
);
38+
}
39+
40+
/*
41+
* Expose.
42+
*/
43+
44+
module.exports = labelable;

‎package.json

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

‎readme.md

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

‎test.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* @author Titus Wormer
3+
* @copyright 2016 Titus Wormer
4+
* @license MIT
5+
* @module hast:util:labelable
6+
* @fileoverview Test suite for `hast-util-labelable`.
7+
*/
8+
9+
'use strict';
10+
11+
/* eslint-env node */
12+
13+
/*
14+
* Module dependencies.
15+
*/
16+
17+
var test = require('tape');
18+
var labelable = require('./index.js');
19+
20+
/*
21+
* Tests.
22+
*/
23+
24+
test('labelable', function (t) {
25+
t.equal(labelable(), false, 'should return `false` without node');
26+
27+
t.equal(labelable({
28+
'type': 'text',
29+
'value': 'Alpha'
30+
}), false, 'should return `false` without element');
31+
32+
t.equal(labelable({
33+
'type': 'element',
34+
'tagName': 'div'
35+
}), false, 'should return `false` for non-labelable elements');
36+
37+
t.equal(labelable({
38+
'type': 'element',
39+
'tagName': 'input'
40+
}), true, 'should return `true` for `input` elements');
41+
42+
t.equal(labelable({
43+
'type': 'element',
44+
'tagName': 'input',
45+
'properties': {
46+
'type': 'hidden'
47+
}
48+
}), false, 'should return `false` for `input[type=hidden]` elements');
49+
50+
t.equal(labelable({
51+
'type': 'element',
52+
'tagName': 'button'
53+
}), true, 'should return `true` for `button` elements');
54+
55+
t.equal(labelable({
56+
'type': 'element',
57+
'tagName': 'keygen'
58+
}), true, 'should return `true` for `keygen` elements');
59+
60+
t.equal(labelable({
61+
'type': 'element',
62+
'tagName': 'meter'
63+
}), true, 'should return `true` for `meter` elements');
64+
65+
t.equal(labelable({
66+
'type': 'element',
67+
'tagName': 'output'
68+
}), true, 'should return `true` for `output` elements');
69+
70+
t.equal(labelable({
71+
'type': 'element',
72+
'tagName': 'progress'
73+
}), true, 'should return `true` for `progress` elements');
74+
75+
t.equal(labelable({
76+
'type': 'element',
77+
'tagName': 'select'
78+
}), true, 'should return `true` for `select` elements');
79+
80+
t.equal(labelable({
81+
'type': 'element',
82+
'tagName': 'textarea'
83+
}), true, 'should return `true` for `textarea` elements');
84+
85+
t.end();
86+
});

0 commit comments

Comments
 (0)
Please sign in to comment.