Skip to content

Commit dda2ef1

Browse files
committed
Initial commit
0 parents  commit dda2ef1

16 files changed

+622
-0
lines changed

.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
*.log
3+
.nyc_output/
4+
coverage/
5+
node_modules/
6+
hast-util-assert.js
7+
hast-util-assert.min.js

.travis.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
language: node_js
2+
node_js:
3+
- '0.11'
4+
- '0.12'
5+
- '4.0'
6+
- '5.0'
7+
- '6.0'
8+
after_success: bash <(curl -s https://codecov.io/bash)
9+
deploy:
10+
- provider: npm
11+
12+
api_key:
13+
secure: HHbmn1y+n37maEGQxb4VXvXz0mnLU/bXTEGExtIMW6oq3oIjjXcourQJVA7AWZR3b/cSE9eNOFANTAOssiKoW3+xWnhpU/rOVLwCsO6UWkfEq5NrKU7JuD4QannITzcJ1Ti+vF7+qBxwv+QJgZyHZ23PCWk3kxZVg/sgYyIWlJexPQqcWE08962PmgcgpbEfPqw1NR2bHsioNKLsrXgUOdtQsOgx8ezCSC6A4gXs6VzEC0ewymYpmB1n9ttSOH7sR86RITdiDm4KPX5B/pHcsNgE2RnFmadaAK6M826/BppffCLMQP1ltlsucmu8tePO8wYMVVO6fh1pP/IlnAXh+Z42I0U52Q24noUwsTzl4VKwhYqXC0QybTqzglripc4rlERlGRcm8w/kqdrrkJ9X0wPFeou8ZwuOb3Jkq4SV+ZD5B8Q/WHZc6Ljt/Ur7HziN/XSaZGQi7I+IH+T7b9gDbxwsaXVJ3jH59wMy9Ch0QEln+Hnh4i2G3VP31QRlpxlxcfWrUpWs/nx16bURHPD9AyX8NhjmdgueQ/5CXBjcxMqp5l/GkugP7Arv/OkT3Q3MVSeWR9OXLDFtrVryNSdWqUpLLmMbPSygJLvjI7t/VM1SRnQbfOdfAX9H3MzqIouTaLgbUH3bLCyhuZ2nqal+V/iKLtGWISrgIdZ46bdqOTQ=
14+
on:
15+
tags: true
16+
node: '5.0'
17+
- provider: releases
18+
api_key:
19+
secure: qr33cSy/zb/Aw1oa3fmo4X2Wi+p95/KA98xmp1woquDGRFfxnNaLaPbe8zEju/vuGUzKSZJ2olvatXuTgk1FBPUOEoStTfzVO4MK6PM4CUy2b8HOgZckOaMY+hFZSJEaLLU7pYzuucSYGV+lEP6deDbMYL6iZb9Hg0rXvjai2RRqHZWsqFEuvLG7gsbD3vT/msF27aUTf0UwICr7upmBKj7jGNDg04zSQ+GNXjSd8F/c0DmjUTtAiCxYoNHaKDw3iKhYRwA52iWDywJMxCsGJkHTMT661jY4/TlEm10i8WkqZwCMln1CiPD+vqbasKnMo10LiInE0qse4Set5AldXDTnVF4pYxPLBq3xSLt3GbcFx1e7YUlgLAbvNDqjTluw3/Dq0plQ5co6gGyYn3rMlSJlA6kTw6NmmTDKRrheccHXoq28XQYK9yiPSTuSdJRMmx0xbsWiLn+e1jWLmc5jKLp5iOpoH89jPKsMxeQSy8CVPCApNhtEjLEg7qOEGIXWxfllH5cBhrC9lER8FcJ3rGeXMLQ6O/fr341/20nWb8uvlR7p6ItkH7HEmDQsOdhIbdxxiQlsmvL5hVoeuSzBbLvWZEtVIbxGJdRwN0gzr5WmAyZsJFjeOdtYYMK2ftG7+VwLV5c3est5JuyYkS+Rgmpi/pqpcghVCRqI1GlsSEw=
20+
file:
21+
- "hast-util-assert.js"
22+
- "hast-util-assert.min.js"
23+
on:
24+
tags: true
25+
node: '6.0'

LICENSE

+22
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.

history.md

+6
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-07-25
6+
==================

index.js

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* @author Titus Wormer
3+
* @copyright 2016 Titus Wormer
4+
* @license MIT
5+
* @module hast-util-assert
6+
* @fileoverview Assert `hast` nodes.
7+
*/
8+
9+
'use strict';
10+
11+
/* Dependencies. */
12+
var assert = require('assert');
13+
var zwitch = require('zwitch');
14+
var mapz = require('mapz');
15+
var unist = require('unist-util-assert');
16+
17+
/* Construct. */
18+
var hast = zwitch('type');
19+
20+
/* Expose. */
21+
module.exports = exports = unist.wrap(hast);
22+
23+
exports.parent = unist.wrap(parent);
24+
exports.text = unist.text;
25+
exports.void = unist.void;
26+
exports.wrap = unist.wrap;
27+
exports.all = mapz(exports, {key: 'children', indices: false});
28+
29+
/* Core interface. */
30+
hast.invalid = hast.unknown = unknown;
31+
32+
/* Per-type handling. */
33+
hast.handlers = {
34+
root: unist.wrap(root),
35+
element: unist.wrap(element),
36+
doctype: unist.wrap(doctype),
37+
comment: exports.text,
38+
text: exports.text
39+
};
40+
41+
function unknown(node, ancestor) {
42+
unist(node, ancestor);
43+
}
44+
45+
function parent(node) {
46+
unist.parent(node);
47+
exports.all(node);
48+
}
49+
50+
function root(node, ancestor) {
51+
parent(node);
52+
53+
assert.equal(ancestor, undefined, '`root` should not have a parent');
54+
}
55+
56+
function element(node) {
57+
parent(node);
58+
59+
assert.equal(typeof node.tagName, 'string', '`element` should have a `tagName`');
60+
assert.notEqual(node.tagName, '', '`element.tagName` should not be empty');
61+
}
62+
63+
function doctype(node) {
64+
unist.void(node);
65+
66+
assert.equal(typeof node.name, 'string', '`doctype` should have a `name`');
67+
68+
if (node.public != null) {
69+
assert.equal(typeof node.public, 'string', '`doctype.public` should be `string`');
70+
}
71+
72+
if (node.system != null) {
73+
assert.equal(typeof node.system, 'string', '`doctype.system` should be `string`');
74+
}
75+
}

package.json

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"name": "hast-util-assert",
3+
"version": "0.0.0",
4+
"description": "Assert HAST nodes",
5+
"license": "MIT",
6+
"keywords": [
7+
"assert",
8+
"hast",
9+
"util",
10+
"utility"
11+
],
12+
"files": [
13+
"index.js"
14+
],
15+
"repository": "https://github.com/wooorm/hast-util-assert",
16+
"bugs": "https://github.com/wooorm/hast-util-assert/issues",
17+
"author": "Titus Wormer <[email protected]> (http://wooorm.com)",
18+
"contributors": [
19+
"Titus Wormer <[email protected]> (http://wooorm.com)"
20+
],
21+
"dependencies": {
22+
"mapz": "^1.0.0",
23+
"unist-util-assert": "^1.0.0",
24+
"zwitch": "^1.0.0"
25+
},
26+
"devDependencies": {
27+
"browserify": "^13.0.1",
28+
"esmangle": "^1.0.1",
29+
"nyc": "^7.0.0",
30+
"remark-cli": "^1.0.0",
31+
"remark-comment-config": "^4.0.0",
32+
"remark-github": "^5.0.0",
33+
"remark-lint": "^4.0.0",
34+
"remark-validate-links": "^4.0.0",
35+
"tape": "^4.0.0",
36+
"xo": "^0.16.0"
37+
},
38+
"scripts": {
39+
"build-md": "remark . --quiet --frail",
40+
"build-bundle": "browserify index.js -s hastUtilAssert > hast-util-assert.js",
41+
"build-mangle": "esmangle < hast-util-assert.js > hast-util-assert.min.js",
42+
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
43+
"lint": "xo",
44+
"test-api": "node test",
45+
"test-coverage": "nyc --reporter lcov tape test",
46+
"test": "npm run build && npm run lint && npm run test-coverage"
47+
},
48+
"xo": {
49+
"space": true,
50+
"rules": {
51+
"no-eq-null": "off",
52+
"eqeqeq": "off",
53+
"guard-for-in": "off"
54+
},
55+
"ignores": [
56+
"hast-util-assert.js",
57+
"hast-util-assert.min.js"
58+
]
59+
},
60+
"nyc": {
61+
"check-coverage": true,
62+
"lines": 100,
63+
"functions": 100,
64+
"branches": 100
65+
},
66+
"remarkConfig": {
67+
"output": true,
68+
"plugins": [
69+
"comment-config",
70+
"github",
71+
"lint",
72+
"validate-links"
73+
],
74+
"settings": {
75+
"bullet": "*"
76+
}
77+
}
78+
}

readme.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# hast-util-assert [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov]
2+
3+
<!--lint disable heading-increment no-duplicate-headings-->
4+
5+
Assert [HAST][] nodes.
6+
7+
## Installation
8+
9+
[npm][npm-install]:
10+
11+
```bash
12+
npm install hast-util-assert
13+
```
14+
15+
## Usage
16+
17+
```javascript
18+
var assert = require('hast-util-assert');
19+
20+
assert({type: 'root', children: []});
21+
assert({type: 'element', tagName: 'a', properties: {}, children: []});
22+
// All OK.
23+
24+
assert({children: []});
25+
// AssertionError: node should have a type: `{ children: [] }`
26+
27+
assert({type: 'element', properties: {}, children: []});
28+
// AssertionError: `element` should have a `tagName`: `{ type: 'element', properties: {}, children: [] }`
29+
```
30+
31+
## API
32+
33+
### `assert(node)`
34+
35+
Assert that `node` is a valid [HAST][] node. If `node` has `children`,
36+
all children will be asserted as well.
37+
38+
The `assert.parent`, `assert.text`, `assert.void`, and `assert.wrap`
39+
methods from [`unist-util-assert`][unist-util-assert] are also included.
40+
41+
## License
42+
43+
[MIT][license] © [Titus Wormer][author]
44+
45+
<!-- Definitions -->
46+
47+
[travis-badge]: https://img.shields.io/travis/wooorm/hast-util-assert.svg
48+
49+
[travis]: https://travis-ci.org/wooorm/hast-util-assert
50+
51+
[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/hast-util-assert.svg
52+
53+
[codecov]: https://codecov.io/github/wooorm/hast-util-assert
54+
55+
[npm-install]: https://docs.npmjs.com/cli/install
56+
57+
[license]: LICENSE
58+
59+
[author]: http://wooorm.com
60+
61+
[hast]: https://github.com/wooorm/hast
62+
63+
[unist-util-assert]: https://github.com/wooorm/unist-util-assert

test/children.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @author Titus Wormer
3+
* @copyright 2016 Titus Wormer
4+
* @license MIT
5+
* @module hast-util-assert
6+
* @fileoverview Test suite for `hast-util-assert`.
7+
*/
8+
9+
'use strict';
10+
11+
/* eslint-env node */
12+
13+
/* Dependencies. */
14+
var test = require('tape');
15+
var assert = require('..');
16+
17+
test('children', function (t) {
18+
t.throws(
19+
function () {
20+
assert({type: 'paragraph', children: {alpha: 'bravo'}});
21+
},
22+
/^AssertionError: `children` should be an array: `{ type: 'paragraph', children: { alpha: 'bravo' } }`$/,
23+
'should throw if given a non-node child in children'
24+
);
25+
26+
t.throws(
27+
function () {
28+
assert({type: 'paragraph', children: ['one']});
29+
},
30+
/^AssertionError: node should be an object: `'one'` in `{ type: 'paragraph', children: \[ 'one' \] }`$/,
31+
'should throw if given a non-node child in children'
32+
);
33+
34+
t.doesNotThrow(
35+
function () {
36+
assert({type: 'paragraph', children: [{type: 'text', value: 'alpha'}]});
37+
},
38+
'should not throw on vald children'
39+
);
40+
41+
t.throws(
42+
function () {
43+
assert({type: 'paragraph', children: [{
44+
type: 'bar',
45+
children: ['one']
46+
}]});
47+
},
48+
/^AssertionError: node should be an object: `'one'` in `{ type: 'bar', children: \[ 'one' \] }`$/,
49+
'should throw on invalid descendants'
50+
);
51+
52+
t.end();
53+
});

test/comment.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @author Titus Wormer
3+
* @copyright 2016 Titus Wormer
4+
* @license MIT
5+
* @module hast-util-assert
6+
* @fileoverview Test suite for `hast-util-assert`.
7+
*/
8+
9+
'use strict';
10+
11+
/* eslint-env node */
12+
13+
/* Dependencies. */
14+
var test = require('tape');
15+
var assert = require('..');
16+
17+
test('assert(comment)', function (t) {
18+
t.throws(
19+
function () {
20+
assert({type: 'comment'});
21+
},
22+
/^AssertionError: text should have `value`: `{ type: 'comment' }`$/,
23+
'should throw if a `comment` doesn’t have a value'
24+
);
25+
26+
t.doesNotThrow(
27+
function () {
28+
assert({type: 'comment', value: 'Alpha'});
29+
},
30+
'should allow `value`'
31+
);
32+
33+
t.end();
34+
});

0 commit comments

Comments
 (0)