From bc845a77de7d18b72c896f94c950b3243439a0e3 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 21 Nov 2016 18:18:46 +0100 Subject: [PATCH 01/85] Update Node in Travis --- .travis.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index d890149..7362e41 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,8 @@ language: node_js node_js: -- '0.11' -- '0.12' - '4.0' -- '5.0' -- '6.0' -after_success: bash <(curl -s https://codecov.io/bash) +- '7.0' +after_script: bash <(curl -s https://codecov.io/bash) deploy: - provider: npm email: tituswormer@gmail.com @@ -13,7 +10,7 @@ deploy: secure: YnwZlIth5sFwvits1uGnF5T7/NTkGtYaO/DI4dVkCzirrZ/LAcKObu+1LHuV6x8JwrsNEkxOZojrXy1M6/uLG5JI2i7uCTqkZeDj5GCvnHYS9fnHIXW7tNFPCrhXPHz9AVM2wH1YHL4io+WEDwcmj8+NSgW+NpT2w1VZebNionKeyVxKNHxcefvkKIcQkyfhhMTBtZizgQDFXBYns46KK2Z7K3T3RpKYUVQHCaKbsBe9gnORx/TYJCEisEFuRSAfX2q2BbLIhx3b24lPn2YnTP7CJtmHQBMBah0Q2qfADoVGDwBdYVat+zZixvV/1cwMb+sBAWZJaaLNCsvj6yCyDRThlrX85qduvD0X8k74H3KXXp9DygBtzg+33Ntk4J8dqwvgoa65hpCZxFHZvLmA7yFvZTgbQV3kQ0T0fXE6K16xd0j2OMMOJChIkbTKuq2g51WHmPQCdU2Iyk+OTB1/8cTVq0nRu7ASGNiJlAulqZPLxIo1bDZXM5kdCmrXCWOLJPQCV+S0tKRbO8Re2jB6LOWcD5pduR7DvhABd+tx2eFw8ZrCkhwcji3oadv0INLgJuT0BLYPrtVs+I+Xq7gxz/hc2PxbY1EC/4XqUIAuFxRNWFF2PwA10qvQDKLx79NafSJ7tVIVCchMjsTZza8b57Oaecw2+Q58nGnz98wZds4= on: tags: true - node: '5.0' + node: '4.0' - provider: releases api_key: secure: qHdUT4ioWdJk8Vsk1QcWRU88miY/VEOHUSaRMYGs66/KwjKJZTXwwEpaU0O10AZvlX+xGwvg2omzrc0MY6YMu6Zol/PiGcI0yDD06LAOIW2J+X2877vw5YvQBZMW2iSL7bF8utOt5SpxtYEIV58tNHZwbFCS0zTDpqj62chKlFHOi+c95fqV33upRUx3vjVCbz0VdGIjsgyg++4Us2qZawfilhfsvNqG1UoJTdZqG5qvEJJ10IxnJqRTylrzzn+h2wP3RODmuWTYOhSQj8maE+jdlTb5bt0vd2Omo/Rd8dsAOWY87qsaL8x2hTcQO3dM9p07QjyhVu62YLfEqMP0TclnHb0L4t9mu5FVkp8aNs7ocL2tqh8B0RBTZSx1m0IVfOe6HSDNsGuMxZai2Zk9dZLxQyWO9Y66ohH3wv34MPtFvrdBBCB60Kcc4DjRNjSirFqU716zF0PzmkKLA55z2Txbqcqp3qBnMUojuDtuSkfquy5+/30q6ssfQV6czy/Sp/4zZMyb2X3Oq2smk/cb593rVQ/KtJIkjNByw+WZk90z6tXMQvxkhftNVjZxmBXZC70igV+zaWNAYwXQMGPkp+dcu5IkeX3GTfry50Z4BKfHmkJzgT3l4d6FpeO0yynzmHH6jSHxXsbnoo32CDWyhYTpdZPq/0LL1afWd13h9rk= @@ -22,4 +19,4 @@ deploy: - "unist-util-assert.min.js" on: tags: true - node: '6.0' + node: '7.0' From 6197a53a11e538e456e5f64b1c0260b48e868391 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 21 Nov 2016 18:18:52 +0100 Subject: [PATCH 02/85] Remove `history.md` --- history.md | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 history.md diff --git a/history.md b/history.md deleted file mode 100644 index 0cb6404..0000000 --- a/history.md +++ /dev/null @@ -1,6 +0,0 @@ - - - - -1.0.0 / 2016-07-19 -================== From c933403ae46927c398b3bcd791ec6ddd484107dc Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 21 Nov 2016 18:20:21 +0100 Subject: [PATCH 03/85] Update dev-dependencies --- package.json | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 8e2f78c..7751109 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,6 @@ "util", "utility" ], - "files": [ - "index.js" - ], "repository": "https://github.com/wooorm/unist-util-assert", "bugs": "https://github.com/wooorm/unist-util-assert/issues", "author": "Titus Wormer (http://wooorm.com)", @@ -22,20 +19,20 @@ "x-is-array": "^0.1.0", "x-is-object": "^0.1.0" }, + "files": [ + "index.js" + ], "devDependencies": { "browserify": "^13.0.1", "esmangle": "^1.0.1", - "nyc": "^7.0.0", - "remark-cli": "^1.0.0", - "remark-comment-config": "^4.0.0", - "remark-github": "^5.0.0", - "remark-lint": "^4.0.0", - "remark-validate-links": "^4.0.0", + "nyc": "^9.0.1", + "remark-cli": "^2.0.0", + "remark-preset-wooorm": "^1.0.0", "tape": "^4.0.0", - "xo": "^0.16.0" + "xo": "^0.17.0" }, "scripts": { - "build-md": "remark . --quiet --frail", + "build-md": "remark . -qfo", "build-bundle": "browserify index.js -s unistUtilAssert > unist-util-assert.js", "build-mangle": "esmangle < unist-util-assert.js > unist-util-assert.min.js", "build": "npm run build-md && npm run build-bundle && npm run build-mangle", @@ -51,8 +48,7 @@ "eqeqeq": "off" }, "ignores": [ - "unist-util-assert.js", - "unist-util-assert.min.js" + "unist-util-assert.js" ] }, "nyc": { @@ -62,15 +58,6 @@ "branches": 100 }, "remarkConfig": { - "output": true, - "plugins": [ - "comment-config", - "github", - "lint", - "validate-links" - ], - "settings": { - "bullet": "*" - } + "presets": "wooorm" } } From 580780add1753dc029de8dfd0963772df3925907 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 21 Nov 2016 18:25:08 +0100 Subject: [PATCH 04/85] Remove superfluous comments --- index.js | 94 +++++++-------------------------------------- test/children.js | 15 +------- test/index.js | 13 +------ test/node.js | 12 ------ test/non-defined.js | 14 +------ test/parent.js | 11 ------ test/position.js | 12 ------ test/text.js | 13 +------ test/type.js | 14 +------ test/value.js | 11 ------ test/void.js | 2 +- 11 files changed, 21 insertions(+), 190 deletions(-) diff --git a/index.js b/index.js index 4bb18d7..37bf1dc 100644 --- a/index.js +++ b/index.js @@ -1,16 +1,5 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module unist-util-assert - * @fileoverview Assert `unist` nodes. - */ - 'use strict'; -/* eslint-env commonjs */ -/* eslint-disable no-useless-concat */ - /* Dependencies. */ var assert = require('assert'); var array = require('x-is-array'); @@ -19,6 +8,7 @@ var object = require('x-is-object'); var inspect; try { + // eslint-disable-next-line import/no-dynamic-require, no-useless-concat inspect = require('ut' + 'il').inspect; } catch (err) { /* Empty. */ } @@ -36,14 +26,8 @@ var ID = '__unist__'; /* List of specced properties. */ var defined = ['type', 'value', 'children', 'position']; -/** - * Wrapper around `Node` which adds the current node - * (and parent, if available), to the message. - * - * @param {Node} node - Node to checl. - * @param {Node?} [parent] - Parent of `node`. - * @throws {Error} - Prettified error. - */ +/* Wrapper around `Node` which adds the current node + * (and parent, if available), to the message. */ function wrap(fn) { return wrapped; @@ -66,13 +50,7 @@ function wrap(fn) { } } -/** - * Assert. - * - * @param {Node} node - Value to assert. - * @throws {Error} - If the given value doesn’t adhere to - * unist. - */ +/* Assert. */ function unist(node) { var type; var children; @@ -114,15 +92,8 @@ function unist(node) { } } -/** - * Assert `value` (which lives at `key`) can be stringified - * and re-parsed to the same (deep) value. - * - * @param {*} value - Value to assert. - * @param {string} key - Property at which `value` lives. - * @throws {Error} - If the given value doesn’t adhere to - * `Parent`. - */ +/* Assert `value` (which lives at `key`) can be stringified + * and re-parsed to the same (deep) value. */ function vanilla(key, value) { try { assert.deepEqual(value, JSON.parse(JSON.stringify(value))); @@ -131,16 +102,9 @@ function vanilla(key, value) { } } -/** - * Stringify a value to inspect it. Tries `JSON.stringify()`, +/* Stringify a value to inspect it. Tries `JSON.stringify()`, * and if that fails uses `String()` instead. If `stringify()` - * works, `` - * - * @param {*} value - Value to assert. - * @param {string} key - Property at which `value` lives. - * @throws {Error} - If the given value doesn’t adhere to - * `Parent`. - */ + * works. */ function view(value) { try { /* eslint-disable no-else-return */ @@ -156,13 +120,7 @@ function view(value) { } } -/** - * Assert `node` is a parent node. - * - * @param {Node} node - Value to assert. - * @throws {Error} - If the given value doesn’t adhere to - * `Parent`. - */ +/* Assert `node` is a parent node. */ function parent(node) { unist(node); @@ -170,13 +128,7 @@ function parent(node) { assert.ok('children' in node, 'parent should have `children`'); } -/** - * Assert `node` is a text node. - * - * @param {Node} node - Value to assert. - * @throws {Error} - If the given value doesn’t adhere to - * `Text`. - */ +/* Assert `node` is a text node. */ function text(node) { unist(node); @@ -184,14 +136,8 @@ function text(node) { assert.ok('value' in node, 'text should have `value`'); } -/** - * Assert `node` is a Unist node, but neither parent nor - * text. - * - * @param {Node} node - Value to assert. - * @throws {Error} - If the given value doesn’t adhere to - * Unist, is a `Parent`, or a `Text`. - */ +/* Assert `node` is a Unist node, but neither parent nor + * text. */ function empty(node) { unist(node); @@ -199,13 +145,7 @@ function empty(node) { assert.equal('children' in node, false, 'void should not have `children`'); } -/** - * Assert `location` is a Unist Location. - * - * @param {Location} location - Location to assert. - * @throws {Error} - If the given value doesn’t adhere to - * Unist Location. - */ +/* Assert `location` is a Unist Location. */ function location(location) { if (location != null) { assert.ok(object(location), '`position` should be an object'); @@ -215,13 +155,7 @@ function location(location) { } } -/** - * Assert `location` is a Unist Location. - * - * @param {Location} location - Location to assert. - * @throws {Error} - If the given value doesn’t adhere to - * Unist Location. - */ +/* Assert `location` is a Unist Location. */ function position(position, name) { if (position != null) { assert.ok(object(position), '`' + name + '` should be an object'); diff --git a/test/children.js b/test/children.js index bdbc6b8..5f2f498 100644 --- a/test/children.js +++ b/test/children.js @@ -1,16 +1,5 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module unist-util-assert - * @fileoverview Test suite for `unist-util-assert`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var assert = require('..'); @@ -27,7 +16,7 @@ test('children', function (t) { function () { assert({type: 'foo', children: ['one']}); }, - /^AssertionError: node should be an object: `'one'` in `{ type: 'foo', children: \[ 'one' \] }`$/, + /^AssertionError: node should be an object: `'one'` in `{ type: 'foo', children: \[ 'one' ] }`$/, 'should throw if given a non-node child in children' ); @@ -45,7 +34,7 @@ test('children', function (t) { children: ['one'] }]}); }, - /^AssertionError: node should be an object: `'one'` in `{ type: 'bar', children: \[ 'one' \] }`$/, + /^AssertionError: node should be an object: `'one'` in `{ type: 'bar', children: \[ 'one' ] }`$/, 'should throw on invalid descendants' ); diff --git a/test/index.js b/test/index.js index d8b5d89..f227a59 100644 --- a/test/index.js +++ b/test/index.js @@ -1,18 +1,7 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module unist-util-assert - * @fileoverview Test suite for `unist-util-assert`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ +/* eslint-disable import/no-unassigned-import */ -/* Tests. */ require('./node'); require('./type'); require('./value'); diff --git a/test/node.js b/test/node.js index 63284af..9d347bf 100644 --- a/test/node.js +++ b/test/node.js @@ -1,20 +1,8 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module unist-util-assert - * @fileoverview Test suite for `unist-util-assert`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var assert = require('..'); -/* Tests. */ test('node', function (t) { t.throws( function () { diff --git a/test/non-defined.js b/test/non-defined.js index f91031b..e057fc5 100644 --- a/test/non-defined.js +++ b/test/non-defined.js @@ -1,20 +1,8 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module unist-util-assert - * @fileoverview Test suite for `unist-util-assert`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var assert = require('..'); -/* Tests. */ test('non-defined', function (t) { t.doesNotThrow( function () { @@ -41,7 +29,7 @@ test('non-defined', function (t) { data: {foo: Function} }); }, - /^AssertionError: non-specced property `data` should be JSON: `{ type: 'break', data: { foo: \[Function: Function\] } }`$/, + /^AssertionError: non-specced property `data` should be JSON: `{ type: 'break', data: { foo: \[Function: Function] } }`$/, 'should throw if non-defined properties are not serialisable' ); diff --git a/test/parent.js b/test/parent.js index 346b197..85b8582 100644 --- a/test/parent.js +++ b/test/parent.js @@ -1,16 +1,5 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module unist-util-assert - * @fileoverview Test suite for `unist-util-assert`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var assert = require('..'); diff --git a/test/position.js b/test/position.js index f9f68ca..4963861 100644 --- a/test/position.js +++ b/test/position.js @@ -1,20 +1,8 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module unist-util-assert - * @fileoverview Test suite for `unist-util-assert`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var assert = require('..'); -/* Tests. */ test('position', function (t) { t.throws( function () { diff --git a/test/text.js b/test/text.js index 02ff727..c647a94 100644 --- a/test/text.js +++ b/test/text.js @@ -1,16 +1,5 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module unist-util-assert - * @fileoverview Test suite for `unist-util-assert`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var assert = require('..'); @@ -27,7 +16,7 @@ test('assert.text()', function (t) { function () { assert.text({type: 'strong', children: []}); }, - /^AssertionError: text should not have `children`: `{ type: 'strong', children: \[\] }`$/, + /^AssertionError: text should not have `children`: `{ type: 'strong', children: \[] }`$/, 'should throw if the given node has `children`' ); diff --git a/test/type.js b/test/type.js index 97c4074..bf91d7a 100644 --- a/test/type.js +++ b/test/type.js @@ -1,26 +1,14 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module unist-util-assert - * @fileoverview Test suite for `unist-util-assert`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var assert = require('..'); -/* Tests. */ test('type', function (t) { t.throws( function () { assert([1, 5]); }, - /^AssertionError: node should have a type: `\[ 1, 5 \]`$/, + /^AssertionError: node should have a type: `\[ 1, 5 ]`$/, 'should throw if not given a `type` (#1)' ); diff --git a/test/value.js b/test/value.js index 7d2698b..ab86185 100644 --- a/test/value.js +++ b/test/value.js @@ -1,16 +1,5 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module unist-util-assert - * @fileoverview Test suite for `unist-util-assert`. - */ - 'use strict'; -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape'); var assert = require('..'); diff --git a/test/void.js b/test/void.js index 5648948..cda419c 100644 --- a/test/void.js +++ b/test/void.js @@ -35,7 +35,7 @@ test('assert.void()', function (t) { function () { assert.void({type: 'strong', children: []}); }, - /^AssertionError: void should not have `children`: `{ type: 'strong', children: \[\] }`$/, + /^AssertionError: void should not have `children`: `{ type: 'strong', children: \[] }`$/, 'should throw if the given node has `children`' ); From cedb716b0cdbe8bb24e4dde61d8947ea901f1ea6 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 21 Nov 2016 18:26:10 +0100 Subject: [PATCH 05/85] Refactor docs --- readme.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 130d3cb..666a97e 100644 --- a/readme.md +++ b/readme.md @@ -1,12 +1,10 @@ # unist-util-assert [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] - - Assert [Unist][] nodes. ## Installation -[npm][npm-install]: +[npm][]: ```bash npm install unist-util-assert @@ -86,7 +84,7 @@ the node (and the parent, when given). [codecov]: https://codecov.io/github/wooorm/unist-util-assert -[npm-install]: https://docs.npmjs.com/cli/install +[npm]: https://docs.npmjs.com/cli/install [license]: LICENSE From 3c3b1d768994a8e0bea9db353b6c5bfb83f1d012 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 20 Dec 2016 19:13:22 +0100 Subject: [PATCH 06/85] Migrate to `syntax-tree` --- package.json | 4 ++-- readme.md | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 7751109..129b8a2 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ "util", "utility" ], - "repository": "https://github.com/wooorm/unist-util-assert", - "bugs": "https://github.com/wooorm/unist-util-assert/issues", + "repository": "https://github.com/syntax-tree/unist-util-assert", + "bugs": "https://github.com/syntax-tree/unist-util-assert/issues", "author": "Titus Wormer (http://wooorm.com)", "contributors": [ "Titus Wormer (http://wooorm.com)" diff --git a/readme.md b/readme.md index 666a97e..c05689e 100644 --- a/readme.md +++ b/readme.md @@ -76,13 +76,13 @@ the node (and the parent, when given). -[travis-badge]: https://img.shields.io/travis/wooorm/unist-util-assert.svg +[travis-badge]: https://img.shields.io/travis/syntax-tree/unist-util-assert.svg -[travis]: https://travis-ci.org/wooorm/unist-util-assert +[travis]: https://travis-ci.org/syntax-tree/unist-util-assert -[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/unist-util-assert.svg +[codecov-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-assert.svg -[codecov]: https://codecov.io/github/wooorm/unist-util-assert +[codecov]: https://codecov.io/github/syntax-tree/unist-util-assert [npm]: https://docs.npmjs.com/cli/install @@ -90,10 +90,10 @@ the node (and the parent, when given). [author]: http://wooorm.com -[unist]: https://github.com/wooorm/unist +[unist]: https://github.com/syntax-tree/unist -[parent]: https://github.com/wooorm/unist#parent +[parent]: https://github.com/syntax-tree/unist#parent -[text]: https://github.com/wooorm/unist#text +[text]: https://github.com/syntax-tree/unist#text -[mdast-util-assert]: https://github.com/wooorm/mdast-util-assert +[mdast-util-assert]: https://github.com/syntax-tree/mdast-util-assert From dc5a732c53b63b58ffedc398d5fd44a58ec2ab96 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 12 Jun 2017 19:54:20 +0200 Subject: [PATCH 07/85] Update dev-dependencies --- index.js | 3 ++- package.json | 15 +++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 37bf1dc..4a44ef7 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,8 @@ try { } catch (err) { /* Empty. */ } /* Expose. */ -module.exports = exports = wrap(unist); +exports = wrap(unist); +module.exports = exports; exports.parent = wrap(parent); exports.text = wrap(text); diff --git a/package.json b/package.json index 129b8a2..8abbd62 100644 --- a/package.json +++ b/package.json @@ -23,13 +23,13 @@ "index.js" ], "devDependencies": { - "browserify": "^13.0.1", + "browserify": "^14.0.1", "esmangle": "^1.0.1", - "nyc": "^9.0.1", - "remark-cli": "^2.0.0", - "remark-preset-wooorm": "^1.0.0", + "nyc": "^11.0.0", + "remark-cli": "^3.0.0", + "remark-preset-wooorm": "^3.0.0", "tape": "^4.0.0", - "xo": "^0.17.0" + "xo": "^0.18.0" }, "scripts": { "build-md": "remark . -qfo", @@ -43,6 +43,7 @@ }, "xo": { "space": true, + "esnext": false, "rules": { "no-eq-null": "off", "eqeqeq": "off" @@ -58,6 +59,8 @@ "branches": 100 }, "remarkConfig": { - "presets": "wooorm" + "plugins": [ + "preset-wooorm" + ] } } From bdff2bbae1520f5878290bd6390b04d0bd8e3598 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 12 Jun 2017 19:54:35 +0200 Subject: [PATCH 08/85] Update Node in Travis --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7362e41..28c9a50 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js node_js: - '4.0' -- '7.0' +- '8.0' after_script: bash <(curl -s https://codecov.io/bash) deploy: - provider: npm @@ -19,4 +19,4 @@ deploy: - "unist-util-assert.min.js" on: tags: true - node: '7.0' + node: '8.0' From d4fb2f9e244889c2a3270ea4a9ffc9acb1ff1eff Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 12 Jun 2017 19:56:43 +0200 Subject: [PATCH 09/85] Add list of related projects --- readme.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/readme.md b/readme.md index c05689e..557a773 100644 --- a/readme.md +++ b/readme.md @@ -70,6 +70,15 @@ Wraps a function (which is passed a node, and an optional parent node), so that any errors thrown inside it will contain information regarding the node (and the parent, when given). +## Related + +* [`mdast-util-assert`](https://github.com/syntax-tree/mdast-util-assert) + — Check [mdast](https://github.com/syntax-tree/mdast) nodes +* [`hast-util-assert`](https://github.com/syntax-tree/hast-util-assert) + — Check [hast](https://github.com/syntax-tree/hast) nodes +* [`nlcst-test`](https://github.com/syntax-tree/nlcst-test) + — Check [nlcst](https://github.com/syntax-tree/nlcst) nodes + ## License [MIT][license] © [Titus Wormer][author] From 172ca7e4fdb701a0f4dc30953d3cb1795a936074 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 12 Jun 2017 20:34:33 +0200 Subject: [PATCH 10/85] Update tests for Node@8 --- test/children.js | 6 +++--- test/node.js | 8 ++++---- test/non-defined.js | 2 +- test/parent.js | 6 +++--- test/position.js | 14 +++++++------- test/text.js | 6 +++--- test/type.js | 8 ++++---- test/value.js | 2 +- test/void.js | 6 +++--- 9 files changed, 29 insertions(+), 29 deletions(-) diff --git a/test/children.js b/test/children.js index 5f2f498..e0d8aba 100644 --- a/test/children.js +++ b/test/children.js @@ -8,7 +8,7 @@ test('children', function (t) { function () { assert({type: 'foo', children: {alpha: 'bravo'}}); }, - /^AssertionError: `children` should be an array: `{ type: 'foo', children: { alpha: 'bravo' } }`$/, + /`children` should be an array: `{ type: 'foo', children: { alpha: 'bravo' } }`$/, 'should throw if given a non-node child in children' ); @@ -16,7 +16,7 @@ test('children', function (t) { function () { assert({type: 'foo', children: ['one']}); }, - /^AssertionError: node should be an object: `'one'` in `{ type: 'foo', children: \[ 'one' ] }`$/, + /node should be an object: `'one'` in `{ type: 'foo', children: \[ 'one' ] }`$/, 'should throw if given a non-node child in children' ); @@ -34,7 +34,7 @@ test('children', function (t) { children: ['one'] }]}); }, - /^AssertionError: node should be an object: `'one'` in `{ type: 'bar', children: \[ 'one' ] }`$/, + /node should be an object: `'one'` in `{ type: 'bar', children: \[ 'one' ] }`$/, 'should throw on invalid descendants' ); diff --git a/test/node.js b/test/node.js index 9d347bf..86f12d2 100644 --- a/test/node.js +++ b/test/node.js @@ -8,7 +8,7 @@ test('node', function (t) { function () { assert(); }, - /^AssertionError: node should be an object: `undefined`$/, + /node should be an object: `undefined`$/, 'should throw if not given a node (#1)' ); @@ -16,7 +16,7 @@ test('node', function (t) { function () { assert(null); }, - /^AssertionError: node should be an object: `null`$/, + /node should be an object: `null`$/, 'should throw if not given a node (#2)' ); @@ -24,7 +24,7 @@ test('node', function (t) { function () { assert('foo'); }, - /^AssertionError: node should be an object: `'foo'`$/, + /node should be an object: `'foo'`$/, 'should throw if given a non-node (#1)' ); @@ -32,7 +32,7 @@ test('node', function (t) { function () { assert(6); }, - /^AssertionError: node should be an object: `6`$/, + /node should be an object: `6`$/, 'should throw if not given a non-node (#2)' ); diff --git a/test/non-defined.js b/test/non-defined.js index e057fc5..61102cc 100644 --- a/test/non-defined.js +++ b/test/non-defined.js @@ -29,7 +29,7 @@ test('non-defined', function (t) { data: {foo: Function} }); }, - /^AssertionError: non-specced property `data` should be JSON: `{ type: 'break', data: { foo: \[Function: Function] } }`$/, + /non-specced property `data` should be JSON: `{ type: 'break', data: { foo: \[Function: Function] } }`$/, 'should throw if non-defined properties are not serialisable' ); diff --git a/test/parent.js b/test/parent.js index 85b8582..de3d893 100644 --- a/test/parent.js +++ b/test/parent.js @@ -8,7 +8,7 @@ test('assert.parent()', function (t) { function () { assert.parent({}); }, - /^AssertionError: node should have a type: `{}`$/, + /node should have a type: `{}`$/, 'should throw the same errors as `assert()`' ); @@ -16,7 +16,7 @@ test('assert.parent()', function (t) { function () { assert.parent({type: 'text', value: 'foo'}); }, - /^AssertionError: parent should not have `value`: `{ type: 'text', value: 'foo' }`$/, + /parent should not have `value`: `{ type: 'text', value: 'foo' }`$/, 'should throw if the given node has a `value`' ); @@ -24,7 +24,7 @@ test('assert.parent()', function (t) { function () { assert.parent({type: 'break'}); }, - /^AssertionError: parent should have `children`: `{ type: 'break' }`$/, + /parent should have `children`: `{ type: 'break' }`$/, 'should throw if the given node has `children`' ); diff --git a/test/position.js b/test/position.js index 4963861..02940ad 100644 --- a/test/position.js +++ b/test/position.js @@ -8,7 +8,7 @@ test('position', function (t) { function () { assert({type: 'foo', position: 1}); }, - /^AssertionError: `position` should be an object: `{ type: 'foo', position: 1 }`$/, + /`position` should be an object: `{ type: 'foo', position: 1 }`$/, 'should throw if given a non-object `position`' ); @@ -30,7 +30,7 @@ test('position', function (t) { function () { assert({type: 'foo', position: {start: 1}}); }, - /^AssertionError: `position.start` should be an object: `{ type: 'foo', position: { start: 1 } }`$/, + /`position.start` should be an object: `{ type: 'foo', position: { start: 1 } }`$/, 'should throw if given a non-object `position.start`' ); @@ -52,7 +52,7 @@ test('position', function (t) { function () { assert({type: 'foo', position: {end: 1}}); }, - /^AssertionError: `position.end` should be an object: `{ type: 'foo', position: { end: 1 } }`$/, + /`position.end` should be an object: `{ type: 'foo', position: { end: 1 } }`$/, 'should throw if given a non-object `position.end`' ); @@ -102,7 +102,7 @@ test('position', function (t) { function () { assert({type: 'foo', position: {start: {line: 0}}}); }, - /^AssertionError: `position.start.line` should be gte `1`: `{ type: 'foo', position: { start: { line: 0 } } }`$/, + /`position.start.line` should be gte `1`: `{ type: 'foo', position: { start: { line: 0 } } }`$/, 'should throw if `position.start.line` is less than 1' ); @@ -110,7 +110,7 @@ test('position', function (t) { function () { assert({type: 'foo', position: {start: {column: 0}}}); }, - /^AssertionError: `position.start.column` should be gte `1`: `{ type: 'foo', position: { start: { column: 0 } } }`$/, + /`position.start.column` should be gte `1`: `{ type: 'foo', position: { start: { column: 0 } } }`$/, 'should throw if `position.start.column` is less than 1' ); @@ -118,7 +118,7 @@ test('position', function (t) { function () { assert({type: 'foo', position: {end: {line: 0}}}); }, - /^AssertionError: `position.end.line` should be gte `1`: `{ type: 'foo', position: { end: { line: 0 } } }`$/, + /`position.end.line` should be gte `1`: `{ type: 'foo', position: { end: { line: 0 } } }`$/, 'should throw if `position.end.line` is less than 1' ); @@ -126,7 +126,7 @@ test('position', function (t) { function () { assert({type: 'foo', position: {end: {column: 0}}}); }, - /^AssertionError: `position.end.column` should be gte `1`: `{ type: 'foo', position: { end: { column: 0 } } }`$/, + /`position.end.column` should be gte `1`: `{ type: 'foo', position: { end: { column: 0 } } }`$/, 'should throw if `position.end.column` is less than 1' ); diff --git a/test/text.js b/test/text.js index c647a94..875b00e 100644 --- a/test/text.js +++ b/test/text.js @@ -8,7 +8,7 @@ test('assert.text()', function (t) { function () { assert.text({}); }, - /^AssertionError: node should have a type: `{}`$/, + /node should have a type: `{}`$/, 'should throw the same errors as `assert()`' ); @@ -16,7 +16,7 @@ test('assert.text()', function (t) { function () { assert.text({type: 'strong', children: []}); }, - /^AssertionError: text should not have `children`: `{ type: 'strong', children: \[] }`$/, + /text should not have `children`: `{ type: 'strong', children: \[] }`$/, 'should throw if the given node has `children`' ); @@ -24,7 +24,7 @@ test('assert.text()', function (t) { function () { assert.text({type: 'break'}); }, - /^AssertionError: text should have `value`: `{ type: 'break' }`$/, + /text should have `value`: `{ type: 'break' }`$/, 'should throw if the given node has no `value`' ); diff --git a/test/type.js b/test/type.js index bf91d7a..09b26f1 100644 --- a/test/type.js +++ b/test/type.js @@ -8,7 +8,7 @@ test('type', function (t) { function () { assert([1, 5]); }, - /^AssertionError: node should have a type: `\[ 1, 5 ]`$/, + /node should have a type: `\[ 1, 5 ]`$/, 'should throw if not given a `type` (#1)' ); @@ -16,7 +16,7 @@ test('type', function (t) { function () { assert({value: 'foo'}); }, - /^AssertionError: node should have a type: `{ value: 'foo' }`$/, + /node should have a type: `{ value: 'foo' }`$/, 'should throw if not given a type (#2)' ); @@ -24,7 +24,7 @@ test('type', function (t) { function () { assert({type: 1}); }, - /^AssertionError: `type` should be a string: `{ type: 1 }`$/, + /`type` should be a string: `{ type: 1 }`$/, 'should throw if not given a non-string type' ); @@ -32,7 +32,7 @@ test('type', function (t) { function () { assert({type: ''}); }, - /^AssertionError: `type` should not be empty: `{ type: '' }`$/, + /`type` should not be empty: `{ type: '' }`$/, 'should throw if given an empty string type' ); diff --git a/test/value.js b/test/value.js index ab86185..4da0cb4 100644 --- a/test/value.js +++ b/test/value.js @@ -8,7 +8,7 @@ test('value', function (t) { function () { assert({type: 'foo', value: 1}); }, - /^AssertionError: `value` should be a string: `{ type: 'foo', value: 1 }`$/, + /`value` should be a string: `{ type: 'foo', value: 1 }`$/, 'should throw if given a non-string `value`' ); diff --git a/test/void.js b/test/void.js index cda419c..68a3043 100644 --- a/test/void.js +++ b/test/void.js @@ -19,7 +19,7 @@ test('assert.void()', function (t) { function () { assert.void({}); }, - /^AssertionError: node should have a type: `{}`$/, + /node should have a type: `{}`$/, 'should throw the same errors as `assert()`' ); @@ -27,7 +27,7 @@ test('assert.void()', function (t) { function () { assert.void({type: 'text', value: 'foo'}); }, - /^AssertionError: void should not have `value`: `{ type: 'text', value: 'foo' }`$/, + /void should not have `value`: `{ type: 'text', value: 'foo' }`$/, 'should throw if the given node has a `value`' ); @@ -35,7 +35,7 @@ test('assert.void()', function (t) { function () { assert.void({type: 'strong', children: []}); }, - /^AssertionError: void should not have `children`: `{ type: 'strong', children: \[] }`$/, + /void should not have `children`: `{ type: 'strong', children: \[] }`$/, 'should throw if the given node has `children`' ); From 61050f0b639c8d87e7205ae190f26b8551c8ec19 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 12 Jun 2017 20:34:38 +0200 Subject: [PATCH 11/85] 1.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8abbd62..9ef1fa8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unist-util-assert", - "version": "1.0.0", + "version": "1.0.1", "description": "Assert Unist nodes", "license": "MIT", "keywords": [ From 4fdee201bbc0219629908643d62d83567fc3a342 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sat, 18 Nov 2017 10:54:04 -0500 Subject: [PATCH 12/85] Update `remark-cli` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9ef1fa8..4f09537 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "browserify": "^14.0.1", "esmangle": "^1.0.1", "nyc": "^11.0.0", - "remark-cli": "^3.0.0", + "remark-cli": "^4.0.0", "remark-preset-wooorm": "^3.0.0", "tape": "^4.0.0", "xo": "^0.18.0" From 5c96a2f3746623ec041799dca98dbfb365ab2c2d Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sat, 18 Nov 2017 10:59:48 -0500 Subject: [PATCH 13/85] Add `Contribute` section to `readme.md` --- readme.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/readme.md b/readme.md index 557a773..eec31b3 100644 --- a/readme.md +++ b/readme.md @@ -79,6 +79,14 @@ the node (and the parent, when given). * [`nlcst-test`](https://github.com/syntax-tree/nlcst-test) — Check [nlcst](https://github.com/syntax-tree/nlcst) nodes +## Contribute + +See [`contribute.md` in `syntax-tree/unist`][contribute] 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 [MIT][license] © [Titus Wormer][author] @@ -106,3 +114,7 @@ the node (and the parent, when given). [text]: https://github.com/syntax-tree/unist#text [mdast-util-assert]: https://github.com/syntax-tree/mdast-util-assert + +[contribute]: https://github.com/syntax-tree/unist/blob/master/contributing.md + +[coc]: https://github.com/syntax-tree/unist/blob/master/code-of-conduct.md From e0e71f891e06dfb9d47661374d3a43e7f75ada5a Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sat, 18 Nov 2017 11:00:12 -0500 Subject: [PATCH 14/85] Update Node in Travis --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 28c9a50..10e5c99 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js node_js: - '4.0' -- '8.0' +- '9.0' after_script: bash <(curl -s https://codecov.io/bash) deploy: - provider: npm @@ -10,7 +10,7 @@ deploy: secure: YnwZlIth5sFwvits1uGnF5T7/NTkGtYaO/DI4dVkCzirrZ/LAcKObu+1LHuV6x8JwrsNEkxOZojrXy1M6/uLG5JI2i7uCTqkZeDj5GCvnHYS9fnHIXW7tNFPCrhXPHz9AVM2wH1YHL4io+WEDwcmj8+NSgW+NpT2w1VZebNionKeyVxKNHxcefvkKIcQkyfhhMTBtZizgQDFXBYns46KK2Z7K3T3RpKYUVQHCaKbsBe9gnORx/TYJCEisEFuRSAfX2q2BbLIhx3b24lPn2YnTP7CJtmHQBMBah0Q2qfADoVGDwBdYVat+zZixvV/1cwMb+sBAWZJaaLNCsvj6yCyDRThlrX85qduvD0X8k74H3KXXp9DygBtzg+33Ntk4J8dqwvgoa65hpCZxFHZvLmA7yFvZTgbQV3kQ0T0fXE6K16xd0j2OMMOJChIkbTKuq2g51WHmPQCdU2Iyk+OTB1/8cTVq0nRu7ASGNiJlAulqZPLxIo1bDZXM5kdCmrXCWOLJPQCV+S0tKRbO8Re2jB6LOWcD5pduR7DvhABd+tx2eFw8ZrCkhwcji3oadv0INLgJuT0BLYPrtVs+I+Xq7gxz/hc2PxbY1EC/4XqUIAuFxRNWFF2PwA10qvQDKLx79NafSJ7tVIVCchMjsTZza8b57Oaecw2+Q58nGnz98wZds4= on: tags: true - node: '4.0' + node: '9.0' - provider: releases api_key: secure: qHdUT4ioWdJk8Vsk1QcWRU88miY/VEOHUSaRMYGs66/KwjKJZTXwwEpaU0O10AZvlX+xGwvg2omzrc0MY6YMu6Zol/PiGcI0yDD06LAOIW2J+X2877vw5YvQBZMW2iSL7bF8utOt5SpxtYEIV58tNHZwbFCS0zTDpqj62chKlFHOi+c95fqV33upRUx3vjVCbz0VdGIjsgyg++4Us2qZawfilhfsvNqG1UoJTdZqG5qvEJJ10IxnJqRTylrzzn+h2wP3RODmuWTYOhSQj8maE+jdlTb5bt0vd2Omo/Rd8dsAOWY87qsaL8x2hTcQO3dM9p07QjyhVu62YLfEqMP0TclnHb0L4t9mu5FVkp8aNs7ocL2tqh8B0RBTZSx1m0IVfOe6HSDNsGuMxZai2Zk9dZLxQyWO9Y66ohH3wv34MPtFvrdBBCB60Kcc4DjRNjSirFqU716zF0PzmkKLA55z2Txbqcqp3qBnMUojuDtuSkfquy5+/30q6ssfQV6czy/Sp/4zZMyb2X3Oq2smk/cb593rVQ/KtJIkjNByw+WZk90z6tXMQvxkhftNVjZxmBXZC70igV+zaWNAYwXQMGPkp+dcu5IkeX3GTfry50Z4BKfHmkJzgT3l4d6FpeO0yynzmHH6jSHxXsbnoo32CDWyhYTpdZPq/0LL1afWd13h9rk= @@ -19,4 +19,4 @@ deploy: - "unist-util-assert.min.js" on: tags: true - node: '8.0' + node: '9.0' From 92d343068cb8acceffac3e6331b59f370a4ac587 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sat, 18 Nov 2017 11:00:26 -0500 Subject: [PATCH 15/85] Add `skip_cleanup` to Travis --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 10e5c99..20629ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ node_js: after_script: bash <(curl -s https://codecov.io/bash) deploy: - provider: npm + skip_cleanup: true email: tituswormer@gmail.com api_key: secure: YnwZlIth5sFwvits1uGnF5T7/NTkGtYaO/DI4dVkCzirrZ/LAcKObu+1LHuV6x8JwrsNEkxOZojrXy1M6/uLG5JI2i7uCTqkZeDj5GCvnHYS9fnHIXW7tNFPCrhXPHz9AVM2wH1YHL4io+WEDwcmj8+NSgW+NpT2w1VZebNionKeyVxKNHxcefvkKIcQkyfhhMTBtZizgQDFXBYns46KK2Z7K3T3RpKYUVQHCaKbsBe9gnORx/TYJCEisEFuRSAfX2q2BbLIhx3b24lPn2YnTP7CJtmHQBMBah0Q2qfADoVGDwBdYVat+zZixvV/1cwMb+sBAWZJaaLNCsvj6yCyDRThlrX85qduvD0X8k74H3KXXp9DygBtzg+33Ntk4J8dqwvgoa65hpCZxFHZvLmA7yFvZTgbQV3kQ0T0fXE6K16xd0j2OMMOJChIkbTKuq2g51WHmPQCdU2Iyk+OTB1/8cTVq0nRu7ASGNiJlAulqZPLxIo1bDZXM5kdCmrXCWOLJPQCV+S0tKRbO8Re2jB6LOWcD5pduR7DvhABd+tx2eFw8ZrCkhwcji3oadv0INLgJuT0BLYPrtVs+I+Xq7gxz/hc2PxbY1EC/4XqUIAuFxRNWFF2PwA10qvQDKLx79NafSJ7tVIVCchMjsTZza8b57Oaecw2+Q58nGnz98wZds4= @@ -12,6 +13,7 @@ deploy: tags: true node: '9.0' - provider: releases + skip_cleanup: true api_key: secure: qHdUT4ioWdJk8Vsk1QcWRU88miY/VEOHUSaRMYGs66/KwjKJZTXwwEpaU0O10AZvlX+xGwvg2omzrc0MY6YMu6Zol/PiGcI0yDD06LAOIW2J+X2877vw5YvQBZMW2iSL7bF8utOt5SpxtYEIV58tNHZwbFCS0zTDpqj62chKlFHOi+c95fqV33upRUx3vjVCbz0VdGIjsgyg++4Us2qZawfilhfsvNqG1UoJTdZqG5qvEJJ10IxnJqRTylrzzn+h2wP3RODmuWTYOhSQj8maE+jdlTb5bt0vd2Omo/Rd8dsAOWY87qsaL8x2hTcQO3dM9p07QjyhVu62YLfEqMP0TclnHb0L4t9mu5FVkp8aNs7ocL2tqh8B0RBTZSx1m0IVfOe6HSDNsGuMxZai2Zk9dZLxQyWO9Y66ohH3wv34MPtFvrdBBCB60Kcc4DjRNjSirFqU716zF0PzmkKLA55z2Txbqcqp3qBnMUojuDtuSkfquy5+/30q6ssfQV6czy/Sp/4zZMyb2X3Oq2smk/cb593rVQ/KtJIkjNByw+WZk90z6tXMQvxkhftNVjZxmBXZC70igV+zaWNAYwXQMGPkp+dcu5IkeX3GTfry50Z4BKfHmkJzgT3l4d6FpeO0yynzmHH6jSHxXsbnoo32CDWyhYTpdZPq/0LL1afWd13h9rk= file: From 55c86f196eeb78c23e0410612aec29e27e4c9b69 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sat, 18 Nov 2017 11:00:46 -0500 Subject: [PATCH 16/85] Refactor `repository` in `package.json` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4f09537..02ca790 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "util", "utility" ], - "repository": "https://github.com/syntax-tree/unist-util-assert", + "repository": "syntax-tree/unist-util-assert", "bugs": "https://github.com/syntax-tree/unist-util-assert/issues", "author": "Titus Wormer (http://wooorm.com)", "contributors": [ From 39e3037c3dfc4bbf2771b24b4493e72108c6a103 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 2 May 2018 10:52:08 +0200 Subject: [PATCH 17/85] Remove npm deployment from Travis --- .travis.yml | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 20629ee..0d8ee0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,21 +4,13 @@ node_js: - '9.0' after_script: bash <(curl -s https://codecov.io/bash) deploy: - - provider: npm - skip_cleanup: true - email: tituswormer@gmail.com - api_key: - secure: YnwZlIth5sFwvits1uGnF5T7/NTkGtYaO/DI4dVkCzirrZ/LAcKObu+1LHuV6x8JwrsNEkxOZojrXy1M6/uLG5JI2i7uCTqkZeDj5GCvnHYS9fnHIXW7tNFPCrhXPHz9AVM2wH1YHL4io+WEDwcmj8+NSgW+NpT2w1VZebNionKeyVxKNHxcefvkKIcQkyfhhMTBtZizgQDFXBYns46KK2Z7K3T3RpKYUVQHCaKbsBe9gnORx/TYJCEisEFuRSAfX2q2BbLIhx3b24lPn2YnTP7CJtmHQBMBah0Q2qfADoVGDwBdYVat+zZixvV/1cwMb+sBAWZJaaLNCsvj6yCyDRThlrX85qduvD0X8k74H3KXXp9DygBtzg+33Ntk4J8dqwvgoa65hpCZxFHZvLmA7yFvZTgbQV3kQ0T0fXE6K16xd0j2OMMOJChIkbTKuq2g51WHmPQCdU2Iyk+OTB1/8cTVq0nRu7ASGNiJlAulqZPLxIo1bDZXM5kdCmrXCWOLJPQCV+S0tKRbO8Re2jB6LOWcD5pduR7DvhABd+tx2eFw8ZrCkhwcji3oadv0INLgJuT0BLYPrtVs+I+Xq7gxz/hc2PxbY1EC/4XqUIAuFxRNWFF2PwA10qvQDKLx79NafSJ7tVIVCchMjsTZza8b57Oaecw2+Q58nGnz98wZds4= - on: - tags: true - node: '9.0' - - provider: releases - skip_cleanup: true - api_key: - secure: qHdUT4ioWdJk8Vsk1QcWRU88miY/VEOHUSaRMYGs66/KwjKJZTXwwEpaU0O10AZvlX+xGwvg2omzrc0MY6YMu6Zol/PiGcI0yDD06LAOIW2J+X2877vw5YvQBZMW2iSL7bF8utOt5SpxtYEIV58tNHZwbFCS0zTDpqj62chKlFHOi+c95fqV33upRUx3vjVCbz0VdGIjsgyg++4Us2qZawfilhfsvNqG1UoJTdZqG5qvEJJ10IxnJqRTylrzzn+h2wP3RODmuWTYOhSQj8maE+jdlTb5bt0vd2Omo/Rd8dsAOWY87qsaL8x2hTcQO3dM9p07QjyhVu62YLfEqMP0TclnHb0L4t9mu5FVkp8aNs7ocL2tqh8B0RBTZSx1m0IVfOe6HSDNsGuMxZai2Zk9dZLxQyWO9Y66ohH3wv34MPtFvrdBBCB60Kcc4DjRNjSirFqU716zF0PzmkKLA55z2Txbqcqp3qBnMUojuDtuSkfquy5+/30q6ssfQV6czy/Sp/4zZMyb2X3Oq2smk/cb593rVQ/KtJIkjNByw+WZk90z6tXMQvxkhftNVjZxmBXZC70igV+zaWNAYwXQMGPkp+dcu5IkeX3GTfry50Z4BKfHmkJzgT3l4d6FpeO0yynzmHH6jSHxXsbnoo32CDWyhYTpdZPq/0LL1afWd13h9rk= - file: - - "unist-util-assert.js" - - "unist-util-assert.min.js" - on: - tags: true - node: '9.0' + provider: releases + skip_cleanup: true + api_key: + secure: qHdUT4ioWdJk8Vsk1QcWRU88miY/VEOHUSaRMYGs66/KwjKJZTXwwEpaU0O10AZvlX+xGwvg2omzrc0MY6YMu6Zol/PiGcI0yDD06LAOIW2J+X2877vw5YvQBZMW2iSL7bF8utOt5SpxtYEIV58tNHZwbFCS0zTDpqj62chKlFHOi+c95fqV33upRUx3vjVCbz0VdGIjsgyg++4Us2qZawfilhfsvNqG1UoJTdZqG5qvEJJ10IxnJqRTylrzzn+h2wP3RODmuWTYOhSQj8maE+jdlTb5bt0vd2Omo/Rd8dsAOWY87qsaL8x2hTcQO3dM9p07QjyhVu62YLfEqMP0TclnHb0L4t9mu5FVkp8aNs7ocL2tqh8B0RBTZSx1m0IVfOe6HSDNsGuMxZai2Zk9dZLxQyWO9Y66ohH3wv34MPtFvrdBBCB60Kcc4DjRNjSirFqU716zF0PzmkKLA55z2Txbqcqp3qBnMUojuDtuSkfquy5+/30q6ssfQV6czy/Sp/4zZMyb2X3Oq2smk/cb593rVQ/KtJIkjNByw+WZk90z6tXMQvxkhftNVjZxmBXZC70igV+zaWNAYwXQMGPkp+dcu5IkeX3GTfry50Z4BKfHmkJzgT3l4d6FpeO0yynzmHH6jSHxXsbnoo32CDWyhYTpdZPq/0LL1afWd13h9rk= + file: + - "unist-util-assert.js" + - "unist-util-assert.min.js" + on: + tags: true + node: '9.0' From 14c0e7936a378c7bbb9a929c79d75df739c8bb8c Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 2 May 2018 10:52:23 +0200 Subject: [PATCH 18/85] Update Node in Travis --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0d8ee0b..adc8d34 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js node_js: -- '4.0' -- '9.0' +- lts/boron +- node after_script: bash <(curl -s https://codecov.io/bash) deploy: provider: releases @@ -13,4 +13,3 @@ deploy: - "unist-util-assert.min.js" on: tags: true - node: '9.0' From 1e7f36e564f005b1b6e6cfc1d90bcbdb2032d36a Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 2 May 2018 10:52:31 +0200 Subject: [PATCH 19/85] Add `.npmrc` --- .npmrc | 1 + 1 file changed, 1 insertion(+) create mode 100644 .npmrc diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false From 92ef1ed42f8ab024beb6294e858d7b60acf094bb Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 2 May 2018 10:52:42 +0200 Subject: [PATCH 20/85] Add `yarn.lock` to `.gitignore` --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0213936..d007bef 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ coverage/ node_modules/ unist-util-assert.js unist-util-assert.min.js +yarn.lock From 035a0fa38809f98cfd160c2fa81164bbefe83cc0 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 2 May 2018 10:54:11 +0200 Subject: [PATCH 21/85] Update dev-dependencies --- package.json | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 02ca790..d568ff4 100644 --- a/package.json +++ b/package.json @@ -23,13 +23,13 @@ "index.js" ], "devDependencies": { - "browserify": "^14.0.1", + "browserify": "^16.0.0", "esmangle": "^1.0.1", "nyc": "^11.0.0", - "remark-cli": "^4.0.0", - "remark-preset-wooorm": "^3.0.0", + "remark-cli": "^5.0.0", + "remark-preset-wooorm": "^4.0.0", "tape": "^4.0.0", - "xo": "^0.18.0" + "xo": "^0.20.0" }, "scripts": { "build-md": "remark . -qfo", @@ -45,6 +45,9 @@ "space": true, "esnext": false, "rules": { + "guard-for-in": "off", + "no-var": "off", + "prefer-arrow-callback": "off", "no-eq-null": "off", "eqeqeq": "off" }, From 6f51df617c4d02ca24e32ce7658b550e0396ed1d Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 2 May 2018 10:54:36 +0200 Subject: [PATCH 22/85] Fix typo --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index eec31b3..dfb3804 100644 --- a/readme.md +++ b/readme.md @@ -81,7 +81,7 @@ the node (and the parent, when given). ## Contribute -See [`contribute.md` in `syntax-tree/unist`][contribute] for ways to get +See [`contributing.md` in `syntax-tree/unist`][contributing] for ways to get started. This organisation has a [Code of Conduct][coc]. By interacting with this @@ -115,6 +115,6 @@ repository, organisation, or community you agree to abide by its terms. [mdast-util-assert]: https://github.com/syntax-tree/mdast-util-assert -[contribute]: https://github.com/syntax-tree/unist/blob/master/contributing.md +[contributing]: https://github.com/syntax-tree/unist/blob/master/contributing.md [coc]: https://github.com/syntax-tree/unist/blob/master/code-of-conduct.md From a379060fe6c4136be08b8621bb13386d07f07dc9 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 2 May 2018 10:56:43 +0200 Subject: [PATCH 23/85] Refactor code-style --- .prettierignore | 3 + index.js | 131 +++++++++++++++++++++------------------- package.json | 18 ++++-- readme.md | 18 +++--- test/children.js | 50 +++++++-------- test/index.js | 20 +++--- test/node.js | 36 +++++------ test/non-defined.js | 49 +++++++-------- test/parent.js | 39 ++++++------ test/position.js | 144 ++++++++++++++++++-------------------------- test/text.js | 39 ++++++------ test/type.js | 45 +++++++------- test/value.js | 54 +++++++---------- test/void.js | 39 ++++++------ 14 files changed, 323 insertions(+), 362 deletions(-) create mode 100644 .prettierignore diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..c2357ce --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +coverage/ +unist-util-assert.js +unist-util-assert.min.js diff --git a/index.js b/index.js index 4a44ef7..fcf58c1 100644 --- a/index.js +++ b/index.js @@ -1,94 +1,96 @@ -'use strict'; +'use strict' /* Dependencies. */ -var assert = require('assert'); -var array = require('x-is-array'); -var object = require('x-is-object'); +var assert = require('assert') +var array = require('x-is-array') +var object = require('x-is-object') -var inspect; +var inspect try { // eslint-disable-next-line import/no-dynamic-require, no-useless-concat - inspect = require('ut' + 'il').inspect; -} catch (err) { /* Empty. */ } + inspect = require('ut' + 'il').inspect +} catch (err) { + /* Empty. */ +} /* Expose. */ -exports = wrap(unist); -module.exports = exports; +exports = wrap(unist) +module.exports = exports -exports.parent = wrap(parent); -exports.text = wrap(text); -exports.void = wrap(empty); -exports.wrap = wrap; +exports.parent = wrap(parent) +exports.text = wrap(text) +exports.void = wrap(empty) +exports.wrap = wrap /* Identifier to check if a value is seen. */ -var ID = '__unist__'; +var ID = '__unist__' /* List of specced properties. */ -var defined = ['type', 'value', 'children', 'position']; +var defined = ['type', 'value', 'children', 'position'] /* Wrapper around `Node` which adds the current node * (and parent, if available), to the message. */ function wrap(fn) { - return wrapped; + return wrapped function wrapped(node, parent) { try { - fn(node, parent); + fn(node, parent) } catch (err) { if (!err[ID]) { - err[ID] = true; + err[ID] = true - err.message += ': `' + view(node) + '`'; + err.message += ': `' + view(node) + '`' if (parent) { - err.message += ' in `' + view(parent) + '`'; + err.message += ' in `' + view(parent) + '`' } } - throw err; + throw err } } } /* Assert. */ function unist(node) { - var type; - var children; - var value; - var key; - var index; - var length; + var type + var children + var value + var key + var index + var length - assert.ok(object(node), 'node should be an object'); + assert.ok(object(node), 'node should be an object') - type = node.type; - children = node.children; - value = node.value; + type = node.type + children = node.children + value = node.value - assert.ok('type' in node, 'node should have a type'); - assert.equal(typeof type, 'string', '`type` should be a string'); - assert.notEqual(type, '', '`type` should not be empty'); + assert.ok('type' in node, 'node should have a type') + assert.equal(typeof type, 'string', '`type` should be a string') + assert.notEqual(type, '', '`type` should not be empty') if (value != null) { - assert.equal(typeof value, 'string', '`value` should be a string'); + assert.equal(typeof value, 'string', '`value` should be a string') } - location(node.position); + location(node.position) for (key in node) { if (defined.indexOf(key) === -1) { - vanilla(key, node[key]); + vanilla(key, node[key]) } } if (children != null) { - assert.ok(array(children), '`children` should be an array'); - index = -1; - length = children.length; + assert.ok(array(children), '`children` should be an array') + index = -1 + length = children.length while (++index < length) { - exports(children[index], node); + exports(children[index], node) } } } @@ -97,9 +99,9 @@ function unist(node) { * and re-parsed to the same (deep) value. */ function vanilla(key, value) { try { - assert.deepEqual(value, JSON.parse(JSON.stringify(value))); + assert.deepEqual(value, JSON.parse(JSON.stringify(value))) } catch (err) { - assert.fail('', '', 'non-specced property `' + key + '` should be JSON'); + assert.fail('', '', 'non-specced property `' + key + '` should be JSON') } } @@ -111,64 +113,67 @@ function view(value) { /* eslint-disable no-else-return */ /* istanbul ignore else - Browser. */ if (inspect) { - return inspect(value, {colors: false}); + return inspect(value, {colors: false}) } else { - return JSON.stringify(value); + return JSON.stringify(value) } } catch (err) { /* istanbul ignore next - Cyclical. */ - return String(value); + return String(value) } } /* Assert `node` is a parent node. */ function parent(node) { - unist(node); + unist(node) - assert.equal('value' in node, false, 'parent should not have `value`'); - assert.ok('children' in node, 'parent should have `children`'); + assert.equal('value' in node, false, 'parent should not have `value`') + assert.ok('children' in node, 'parent should have `children`') } /* Assert `node` is a text node. */ function text(node) { - unist(node); + unist(node) - assert.equal('children' in node, false, 'text should not have `children`'); - assert.ok('value' in node, 'text should have `value`'); + assert.equal('children' in node, false, 'text should not have `children`') + assert.ok('value' in node, 'text should have `value`') } /* Assert `node` is a Unist node, but neither parent nor * text. */ function empty(node) { - unist(node); + unist(node) - assert.equal('value' in node, false, 'void should not have `value`'); - assert.equal('children' in node, false, 'void should not have `children`'); + assert.equal('value' in node, false, 'void should not have `value`') + assert.equal('children' in node, false, 'void should not have `children`') } /* Assert `location` is a Unist Location. */ function location(location) { if (location != null) { - assert.ok(object(location), '`position` should be an object'); + assert.ok(object(location), '`position` should be an object') - position(location.start, 'position.start'); - position(location.end, 'position.end'); + position(location.start, 'position.start') + position(location.end, 'position.end') } } /* Assert `location` is a Unist Location. */ function position(position, name) { if (position != null) { - assert.ok(object(position), '`' + name + '` should be an object'); + assert.ok(object(position), '`' + name + '` should be an object') if (position.line != null) { - assert.ok('line' in position, '`' + name + '` should have numeric `line`'); - assert.ok(position.line >= 1, '`' + name + '.line` should be gte `1`'); + assert.ok('line' in position, '`' + name + '` should have numeric `line`') + assert.ok(position.line >= 1, '`' + name + '.line` should be gte `1`') } if (position.column != null) { - assert.ok('column' in position, '`' + name + '` should have numeric `column`'); - assert.ok(position.column >= 1, '`' + name + '.column` should be gte `1`'); + assert.ok( + 'column' in position, + '`' + name + '` should have numeric `column`' + ) + assert.ok(position.column >= 1, '`' + name + '.column` should be gte `1`') } } } diff --git a/package.json b/package.json index d568ff4..0b3652b 100644 --- a/package.json +++ b/package.json @@ -26,23 +26,31 @@ "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", "tape": "^4.0.0", "xo": "^0.20.0" }, "scripts": { - "build-md": "remark . -qfo", + "format": "remark . -qfo && prettier --write '**/*.js' && xo --fix", "build-bundle": "browserify index.js -s unistUtilAssert > unist-util-assert.js", "build-mangle": "esmangle < unist-util-assert.js > unist-util-assert.min.js", - "build": "npm run build-md && npm run build-bundle && npm run build-mangle", - "lint": "xo", + "build": "npm run build-bundle && npm run build-mangle", "test-api": "node test", "test-coverage": "nyc --reporter lcov tape test", - "test": "npm run build && npm run lint && npm run test-coverage" + "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": { - "space": true, + "prettier": true, "esnext": false, "rules": { "guard-for-in": "off", diff --git a/readme.md b/readme.md index dfb3804..bc6f526 100644 --- a/readme.md +++ b/readme.md @@ -13,26 +13,26 @@ npm install unist-util-assert ## Usage ```javascript -var assert = require('unist-util-assert'); +var assert = require('unist-util-assert') -assert({type: 'root', children: []}); -assert({type: 'break'}); -assert({type: 'element', properties: {}, children: []}); +assert({type: 'root', children: []}) +assert({type: 'break'}) +assert({type: 'element', properties: {}, children: []}) // All OK. -assert({children: []}); +assert({children: []}) // AssertionError: node should have a type: `{ children: [] }` -assert.parent({type: 'break'}); +assert.parent({type: 'break'}) // AssertionError: parent should have `children`: `{ type: 'break' }` -assert({type: 'element', properties: function () {}}); +assert({type: 'element', properties: function() {}}) // AssertionError: non-specced property `properties` should be JSON: `{ type: 'element', properties: [Function] }` -assert.void({type: 'text', value: 'Alpha'}); +assert.void({type: 'text', value: 'Alpha'}) // AssertionError: void should not have `value`: `{ type: 'text', value: 'Alpha' }` -assert({type: 'paragraph', children: ['foo']}); +assert({type: 'paragraph', children: ['foo']}) // AssertionError: node should be an object: `'foo'` in `{ type: 'paragraph', children: [ 'foo' ] }` ``` diff --git a/test/children.js b/test/children.js index e0d8aba..eddfb6a 100644 --- a/test/children.js +++ b/test/children.js @@ -1,42 +1,44 @@ -'use strict'; +'use strict' -var test = require('tape'); -var assert = require('..'); +var test = require('tape') +var assert = require('..') -test('children', function (t) { +test('children', function(t) { t.throws( - function () { - assert({type: 'foo', children: {alpha: 'bravo'}}); + function() { + assert({type: 'foo', children: {alpha: 'bravo'}}) }, /`children` should be an array: `{ type: 'foo', children: { alpha: 'bravo' } }`$/, 'should throw if given a non-node child in children' - ); + ) t.throws( - function () { - assert({type: 'foo', children: ['one']}); + function() { + assert({type: 'foo', children: ['one']}) }, /node should be an object: `'one'` in `{ type: 'foo', children: \[ 'one' ] }`$/, 'should throw if given a non-node child in children' - ); + ) - t.doesNotThrow( - function () { - assert({type: 'parent', children: [{type: 'text', value: 'alpha'}]}); - }, - 'should not throw on vald children' - ); + t.doesNotThrow(function() { + assert({type: 'parent', children: [{type: 'text', value: 'alpha'}]}) + }, 'should not throw on vald children') t.throws( - function () { - assert({type: 'foo', children: [{ - type: 'bar', - children: ['one'] - }]}); + function() { + assert({ + type: 'foo', + children: [ + { + type: 'bar', + children: ['one'] + } + ] + }) }, /node should be an object: `'one'` in `{ type: 'bar', children: \[ 'one' ] }`$/, 'should throw on invalid descendants' - ); + ) - t.end(); -}); + t.end() +}) diff --git a/test/index.js b/test/index.js index f227a59..6e1dfaa 100644 --- a/test/index.js +++ b/test/index.js @@ -1,13 +1,13 @@ -'use strict'; +'use strict' /* eslint-disable import/no-unassigned-import */ -require('./node'); -require('./type'); -require('./value'); -require('./children'); -require('./position'); -require('./non-defined'); -require('./parent'); -require('./text'); -require('./void'); +require('./node') +require('./type') +require('./value') +require('./children') +require('./position') +require('./non-defined') +require('./parent') +require('./text') +require('./void') diff --git a/test/node.js b/test/node.js index 86f12d2..7f1ff79 100644 --- a/test/node.js +++ b/test/node.js @@ -1,40 +1,40 @@ -'use strict'; +'use strict' -var test = require('tape'); -var assert = require('..'); +var test = require('tape') +var assert = require('..') -test('node', function (t) { +test('node', function(t) { t.throws( - function () { - assert(); + function() { + assert() }, /node should be an object: `undefined`$/, 'should throw if not given a node (#1)' - ); + ) t.throws( - function () { - assert(null); + function() { + assert(null) }, /node should be an object: `null`$/, 'should throw if not given a node (#2)' - ); + ) t.throws( - function () { - assert('foo'); + function() { + assert('foo') }, /node should be an object: `'foo'`$/, 'should throw if given a non-node (#1)' - ); + ) t.throws( - function () { - assert(6); + function() { + assert(6) }, /node should be an object: `6`$/, 'should throw if not given a non-node (#2)' - ); + ) - t.end(); -}); + t.end() +}) diff --git a/test/non-defined.js b/test/non-defined.js index 61102cc..ed72e2c 100644 --- a/test/non-defined.js +++ b/test/non-defined.js @@ -1,37 +1,34 @@ -'use strict'; +'use strict' -var test = require('tape'); -var assert = require('..'); +var test = require('tape') +var assert = require('..') -test('non-defined', function (t) { - t.doesNotThrow( - function () { - assert({ - type: 'element', - properties: { - className: ['alpha'], - id: 'bravo' - }, - children: [], - position: {}, - data: { - charlie: 'delta' - } - }); - }, - 'should not throw if non-defined properties are found' - ); +test('non-defined', function(t) { + t.doesNotThrow(function() { + assert({ + type: 'element', + properties: { + className: ['alpha'], + id: 'bravo' + }, + children: [], + position: {}, + data: { + charlie: 'delta' + } + }) + }, 'should not throw if non-defined properties are found') t.throws( - function () { + function() { assert({ type: 'break', data: {foo: Function} - }); + }) }, /non-specced property `data` should be JSON: `{ type: 'break', data: { foo: \[Function: Function] } }`$/, 'should throw if non-defined properties are not serialisable' - ); + ) - t.end(); -}); + t.end() +}) diff --git a/test/parent.js b/test/parent.js index de3d893..ba62c49 100644 --- a/test/parent.js +++ b/test/parent.js @@ -1,39 +1,36 @@ -'use strict'; +'use strict' -var test = require('tape'); -var assert = require('..'); +var test = require('tape') +var assert = require('..') -test('assert.parent()', function (t) { +test('assert.parent()', function(t) { t.throws( - function () { - assert.parent({}); + function() { + assert.parent({}) }, /node should have a type: `{}`$/, 'should throw the same errors as `assert()`' - ); + ) t.throws( - function () { - assert.parent({type: 'text', value: 'foo'}); + function() { + assert.parent({type: 'text', value: 'foo'}) }, /parent should not have `value`: `{ type: 'text', value: 'foo' }`$/, 'should throw if the given node has a `value`' - ); + ) t.throws( - function () { - assert.parent({type: 'break'}); + function() { + assert.parent({type: 'break'}) }, /parent should have `children`: `{ type: 'break' }`$/, 'should throw if the given node has `children`' - ); + ) - t.doesNotThrow( - function () { - assert.parent({type: 'strong', children: []}); - }, - 'should not throw on valid void nodes' - ); + t.doesNotThrow(function() { + assert.parent({type: 'strong', children: []}) + }, 'should not throw on valid void nodes') - t.end(); -}); + t.end() +}) diff --git a/test/position.js b/test/position.js index 02940ad..dde618a 100644 --- a/test/position.js +++ b/test/position.js @@ -1,134 +1,104 @@ -'use strict'; +'use strict' -var test = require('tape'); -var assert = require('..'); +var test = require('tape') +var assert = require('..') -test('position', function (t) { +test('position', function(t) { t.throws( - function () { - assert({type: 'foo', position: 1}); + function() { + assert({type: 'foo', position: 1}) }, /`position` should be an object: `{ type: 'foo', position: 1 }`$/, 'should throw if given a non-object `position`' - ); + ) - t.doesNotThrow( - function () { - assert({type: 'foo', position: null}); - }, - 'should not throw if given a null `position`' - ); + t.doesNotThrow(function() { + assert({type: 'foo', position: null}) + }, 'should not throw if given a null `position`') - t.doesNotThrow( - function () { - assert({type: 'foo', position: {}}); - }, - 'should not throw if given an empty `position` object' - ); + t.doesNotThrow(function() { + assert({type: 'foo', position: {}}) + }, 'should not throw if given an empty `position` object') t.throws( - function () { - assert({type: 'foo', position: {start: 1}}); + function() { + assert({type: 'foo', position: {start: 1}}) }, /`position.start` should be an object: `{ type: 'foo', position: { start: 1 } }`$/, 'should throw if given a non-object `position.start`' - ); + ) - t.doesNotThrow( - function () { - assert({type: 'foo', position: {start: null}}); - }, - 'should not throw if given a null `position.start`' - ); + t.doesNotThrow(function() { + assert({type: 'foo', position: {start: null}}) + }, 'should not throw if given a null `position.start`') - t.doesNotThrow( - function () { - assert({type: 'foo', position: {start: {}}}); - }, - 'should not throw if given an empty `position.start` object' - ); + t.doesNotThrow(function() { + assert({type: 'foo', position: {start: {}}}) + }, 'should not throw if given an empty `position.start` object') t.throws( - function () { - assert({type: 'foo', position: {end: 1}}); + function() { + assert({type: 'foo', position: {end: 1}}) }, /`position.end` should be an object: `{ type: 'foo', position: { end: 1 } }`$/, 'should throw if given a non-object `position.end`' - ); + ) - t.doesNotThrow( - function () { - assert({type: 'foo', position: {end: null}}); - }, - 'should not throw if given a null `position.end`' - ); + t.doesNotThrow(function() { + assert({type: 'foo', position: {end: null}}) + }, 'should not throw if given a null `position.end`') - t.doesNotThrow( - function () { - assert({type: 'foo', position: {end: {}}}); - }, - 'should not throw if given an empty `position.end` object' - ); + t.doesNotThrow(function() { + assert({type: 'foo', position: {end: {}}}) + }, 'should not throw if given an empty `position.end` object') - t.doesNotThrow( - function () { - assert({type: 'foo', position: {start: {line: null}}}); - }, - 'should not throw if given a `position.start.line` to `null`' - ); + t.doesNotThrow(function() { + assert({type: 'foo', position: {start: {line: null}}}) + }, 'should not throw if given a `position.start.line` to `null`') - t.doesNotThrow( - function () { - assert({type: 'foo', position: {start: {column: null}}}); - }, - 'should not throw if given a `position.start.column` to `null`' - ); + t.doesNotThrow(function() { + assert({type: 'foo', position: {start: {column: null}}}) + }, 'should not throw if given a `position.start.column` to `null`') - t.doesNotThrow( - function () { - assert({type: 'foo', position: {end: {line: null}}}); - }, - 'should not throw if given a `position.end.line` to `null`' - ); + t.doesNotThrow(function() { + assert({type: 'foo', position: {end: {line: null}}}) + }, 'should not throw if given a `position.end.line` to `null`') - t.doesNotThrow( - function () { - assert({type: 'foo', position: {end: {column: null}}}); - }, - 'should not throw if given a `position.end.column` to `null`' - ); + t.doesNotThrow(function() { + assert({type: 'foo', position: {end: {column: null}}}) + }, 'should not throw if given a `position.end.column` to `null`') t.throws( - function () { - assert({type: 'foo', position: {start: {line: 0}}}); + function() { + assert({type: 'foo', position: {start: {line: 0}}}) }, /`position.start.line` should be gte `1`: `{ type: 'foo', position: { start: { line: 0 } } }`$/, 'should throw if `position.start.line` is less than 1' - ); + ) t.throws( - function () { - assert({type: 'foo', position: {start: {column: 0}}}); + function() { + assert({type: 'foo', position: {start: {column: 0}}}) }, /`position.start.column` should be gte `1`: `{ type: 'foo', position: { start: { column: 0 } } }`$/, 'should throw if `position.start.column` is less than 1' - ); + ) t.throws( - function () { - assert({type: 'foo', position: {end: {line: 0}}}); + function() { + assert({type: 'foo', position: {end: {line: 0}}}) }, /`position.end.line` should be gte `1`: `{ type: 'foo', position: { end: { line: 0 } } }`$/, 'should throw if `position.end.line` is less than 1' - ); + ) t.throws( - function () { - assert({type: 'foo', position: {end: {column: 0}}}); + function() { + assert({type: 'foo', position: {end: {column: 0}}}) }, /`position.end.column` should be gte `1`: `{ type: 'foo', position: { end: { column: 0 } } }`$/, 'should throw if `position.end.column` is less than 1' - ); + ) - t.end(); -}); + t.end() +}) diff --git a/test/text.js b/test/text.js index 875b00e..889e0f3 100644 --- a/test/text.js +++ b/test/text.js @@ -1,39 +1,36 @@ -'use strict'; +'use strict' -var test = require('tape'); -var assert = require('..'); +var test = require('tape') +var assert = require('..') -test('assert.text()', function (t) { +test('assert.text()', function(t) { t.throws( - function () { - assert.text({}); + function() { + assert.text({}) }, /node should have a type: `{}`$/, 'should throw the same errors as `assert()`' - ); + ) t.throws( - function () { - assert.text({type: 'strong', children: []}); + function() { + assert.text({type: 'strong', children: []}) }, /text should not have `children`: `{ type: 'strong', children: \[] }`$/, 'should throw if the given node has `children`' - ); + ) t.throws( - function () { - assert.text({type: 'break'}); + function() { + assert.text({type: 'break'}) }, /text should have `value`: `{ type: 'break' }`$/, 'should throw if the given node has no `value`' - ); + ) - t.doesNotThrow( - function () { - assert.text({type: 'text', value: 'foo'}); - }, - 'should not throw on valid text nodes' - ); + t.doesNotThrow(function() { + assert.text({type: 'text', value: 'foo'}) + }, 'should not throw on valid text nodes') - t.end(); -}); + t.end() +}) diff --git a/test/type.js b/test/type.js index 09b26f1..d328eaa 100644 --- a/test/type.js +++ b/test/type.js @@ -1,47 +1,44 @@ -'use strict'; +'use strict' -var test = require('tape'); -var assert = require('..'); +var test = require('tape') +var assert = require('..') -test('type', function (t) { +test('type', function(t) { t.throws( - function () { - assert([1, 5]); + function() { + assert([1, 5]) }, /node should have a type: `\[ 1, 5 ]`$/, 'should throw if not given a `type` (#1)' - ); + ) t.throws( - function () { - assert({value: 'foo'}); + function() { + assert({value: 'foo'}) }, /node should have a type: `{ value: 'foo' }`$/, 'should throw if not given a type (#2)' - ); + ) t.throws( - function () { - assert({type: 1}); + function() { + assert({type: 1}) }, /`type` should be a string: `{ type: 1 }`$/, 'should throw if not given a non-string type' - ); + ) t.throws( - function () { - assert({type: ''}); + function() { + assert({type: ''}) }, /`type` should not be empty: `{ type: '' }`$/, 'should throw if given an empty string type' - ); + ) - t.doesNotThrow( - function () { - assert({type: 'foo'}); - }, - 'should not throw if given a non-empty type string' - ); + t.doesNotThrow(function() { + assert({type: 'foo'}) + }, 'should not throw if given a non-empty type string') - t.end(); -}); + t.end() +}) diff --git a/test/value.js b/test/value.js index 4da0cb4..c7c3f45 100644 --- a/test/value.js +++ b/test/value.js @@ -1,44 +1,32 @@ -'use strict'; +'use strict' -var test = require('tape'); -var assert = require('..'); +var test = require('tape') +var assert = require('..') -test('value', function (t) { +test('value', function(t) { t.throws( - function () { - assert({type: 'foo', value: 1}); + function() { + assert({type: 'foo', value: 1}) }, /`value` should be a string: `{ type: 'foo', value: 1 }`$/, 'should throw if given a non-string `value`' - ); + ) - t.doesNotThrow( - function () { - assert({type: 'foo', value: ''}); - }, - 'should not throw if given an empty string `value`' - ); + t.doesNotThrow(function() { + assert({type: 'foo', value: ''}) + }, 'should not throw if given an empty string `value`') - t.doesNotThrow( - function () { - assert({type: 'foo', value: 'foo'}); - }, - 'should not throw if given an string `value`' - ); + t.doesNotThrow(function() { + assert({type: 'foo', value: 'foo'}) + }, 'should not throw if given an string `value`') - t.doesNotThrow( - function () { - assert({type: 'foo', value: undefined}); - }, - 'should not throw if given an undefined `value`' - ); + t.doesNotThrow(function() { + assert({type: 'foo', value: undefined}) + }, 'should not throw if given an undefined `value`') - t.doesNotThrow( - function () { - assert({type: 'foo', value: null}); - }, - 'should not throw if given an null `value`' - ); + t.doesNotThrow(function() { + assert({type: 'foo', value: null}) + }, 'should not throw if given an null `value`') - t.end(); -}); + t.end() +}) diff --git a/test/void.js b/test/void.js index 68a3043..eef6ef3 100644 --- a/test/void.js +++ b/test/void.js @@ -6,45 +6,42 @@ * @fileoverview Test suite for `unist-util-assert`. */ -'use strict'; +'use strict' /* eslint-env node */ /* Dependencies. */ -var test = require('tape'); -var assert = require('..'); +var test = require('tape') +var assert = require('..') -test('assert.void()', function (t) { +test('assert.void()', function(t) { t.throws( - function () { - assert.void({}); + function() { + assert.void({}) }, /node should have a type: `{}`$/, 'should throw the same errors as `assert()`' - ); + ) t.throws( - function () { - assert.void({type: 'text', value: 'foo'}); + function() { + assert.void({type: 'text', value: 'foo'}) }, /void should not have `value`: `{ type: 'text', value: 'foo' }`$/, 'should throw if the given node has a `value`' - ); + ) t.throws( - function () { - assert.void({type: 'strong', children: []}); + function() { + assert.void({type: 'strong', children: []}) }, /void should not have `children`: `{ type: 'strong', children: \[] }`$/, 'should throw if the given node has `children`' - ); + ) - t.doesNotThrow( - function () { - assert.void({type: 'break'}); - }, - 'should not throw on valid void nodes' - ); + t.doesNotThrow(function() { + assert.void({type: 'break'}) + }, 'should not throw on valid void nodes') - t.end(); -}); + t.end() +}) From 308a7ba6691afdbb13dca67e964cca4003c734ef Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 2 May 2018 10:56:58 +0200 Subject: [PATCH 24/85] 1.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0b3652b..53ebd3f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unist-util-assert", - "version": "1.0.1", + "version": "1.0.2", "description": "Assert Unist nodes", "license": "MIT", "keywords": [ From 62a03e5fccf33c31166e36400da628e667500374 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 1 Nov 2018 10:52:56 +0100 Subject: [PATCH 25/85] Move `LICENSE` > `license` --- LICENSE => license | 0 readme.md | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename LICENSE => license (100%) diff --git a/LICENSE b/license similarity index 100% rename from LICENSE rename to license diff --git a/readme.md b/readme.md index bc6f526..7d3f10c 100644 --- a/readme.md +++ b/readme.md @@ -103,7 +103,7 @@ repository, organisation, or community you agree to abide by its terms. [npm]: https://docs.npmjs.com/cli/install -[license]: LICENSE +[license]: license [author]: http://wooorm.com From 88ca0436e7138018edafad03419127ce9ae81173 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 1 Nov 2018 10:53:19 +0100 Subject: [PATCH 26/85] Move URLs to HTTPS --- package.json | 4 ++-- readme.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 53ebd3f..cfe62ad 100644 --- a/package.json +++ b/package.json @@ -11,9 +11,9 @@ ], "repository": "syntax-tree/unist-util-assert", "bugs": "https://github.com/syntax-tree/unist-util-assert/issues", - "author": "Titus Wormer (http://wooorm.com)", + "author": "Titus Wormer (https://wooorm.com)", "contributors": [ - "Titus Wormer (http://wooorm.com)" + "Titus Wormer (https://wooorm.com)" ], "dependencies": { "x-is-array": "^0.1.0", diff --git a/readme.md b/readme.md index 7d3f10c..4aa9d69 100644 --- a/readme.md +++ b/readme.md @@ -105,7 +105,7 @@ repository, organisation, or community you agree to abide by its terms. [license]: license -[author]: http://wooorm.com +[author]: https://wooorm.com [unist]: https://github.com/syntax-tree/unist From b64984c6caa87579dab7d5dbecac8edb6cd0ef78 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 1 Nov 2018 10:57:47 +0100 Subject: [PATCH 27/85] Update dev-dependencies --- index.js | 44 ++++++++++++++++++++++++++------------------ package.json | 6 +++--- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/index.js b/index.js index fcf58c1..97f2d34 100644 --- a/index.js +++ b/index.js @@ -10,7 +10,7 @@ var inspect try { // eslint-disable-next-line import/no-dynamic-require, no-useless-concat inspect = require('ut' + 'il').inspect -} catch (err) { +} catch (error) { /* Empty. */ } @@ -37,18 +37,18 @@ function wrap(fn) { function wrapped(node, parent) { try { fn(node, parent) - } catch (err) { - if (!err[ID]) { - err[ID] = true + } catch (error) { + if (!error[ID]) { + error[ID] = true - err.message += ': `' + view(node) + '`' + error.message += ': `' + view(node) + '`' if (parent) { - err.message += ' in `' + view(parent) + '`' + error.message += ' in `' + view(parent) + '`' } } - throw err + throw error } } } @@ -69,11 +69,11 @@ function unist(node) { value = node.value assert.ok('type' in node, 'node should have a type') - assert.equal(typeof type, 'string', '`type` should be a string') - assert.notEqual(type, '', '`type` should not be empty') + assert.strictEqual(typeof type, 'string', '`type` should be a string') + assert.notStrictEqual(type, '', '`type` should not be empty') if (value != null) { - assert.equal(typeof value, 'string', '`value` should be a string') + assert.strictEqual(typeof value, 'string', '`value` should be a string') } location(node.position) @@ -99,9 +99,9 @@ function unist(node) { * and re-parsed to the same (deep) value. */ function vanilla(key, value) { try { - assert.deepEqual(value, JSON.parse(JSON.stringify(value))) - } catch (err) { - assert.fail('', '', 'non-specced property `' + key + '` should be JSON') + assert.deepStrictEqual(value, JSON.parse(JSON.stringify(value))) + } catch (error) { + assert.fail('non-specced property `' + key + '` should be JSON') } } @@ -117,7 +117,7 @@ function view(value) { } else { return JSON.stringify(value) } - } catch (err) { + } catch (error) { /* istanbul ignore next - Cyclical. */ return String(value) } @@ -127,7 +127,7 @@ function view(value) { function parent(node) { unist(node) - assert.equal('value' in node, false, 'parent should not have `value`') + assert.strictEqual('value' in node, false, 'parent should not have `value`') assert.ok('children' in node, 'parent should have `children`') } @@ -135,7 +135,11 @@ function parent(node) { function text(node) { unist(node) - assert.equal('children' in node, false, 'text should not have `children`') + assert.strictEqual( + 'children' in node, + false, + 'text should not have `children`' + ) assert.ok('value' in node, 'text should have `value`') } @@ -144,8 +148,12 @@ function text(node) { function empty(node) { unist(node) - assert.equal('value' in node, false, 'void should not have `value`') - assert.equal('children' in node, false, 'void should not have `children`') + assert.strictEqual('value' in node, false, 'void should not have `value`') + assert.strictEqual( + 'children' in node, + false, + 'void should not have `children`' + ) } /* Assert `location` is a Unist Location. */ diff --git a/package.json b/package.json index cfe62ad..65f8f08 100644 --- a/package.json +++ b/package.json @@ -25,12 +25,12 @@ "devDependencies": { "browserify": "^16.0.0", "esmangle": "^1.0.1", - "nyc": "^11.0.0", + "nyc": "^13.0.0", "prettier": "^1.12.1", - "remark-cli": "^5.0.0", + "remark-cli": "^6.0.0", "remark-preset-wooorm": "^4.0.0", "tape": "^4.0.0", - "xo": "^0.20.0" + "xo": "^0.23.0" }, "scripts": { "format": "remark . -qfo && prettier --write '**/*.js' && xo --fix", From ba845cc1cfec88db0e1975a52724f9b59da36538 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 1 Nov 2018 10:58:45 +0100 Subject: [PATCH 28/85] Update build scripts --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 65f8f08..b495750 100644 --- a/package.json +++ b/package.json @@ -24,18 +24,18 @@ ], "devDependencies": { "browserify": "^16.0.0", - "esmangle": "^1.0.1", "nyc": "^13.0.0", "prettier": "^1.12.1", "remark-cli": "^6.0.0", "remark-preset-wooorm": "^4.0.0", "tape": "^4.0.0", + "tinyify": "^2.4.3", "xo": "^0.23.0" }, "scripts": { "format": "remark . -qfo && prettier --write '**/*.js' && xo --fix", - "build-bundle": "browserify index.js -s unistUtilAssert > unist-util-assert.js", - "build-mangle": "esmangle < unist-util-assert.js > unist-util-assert.min.js", + "build-bundle": "browserify . -s unistUtilAssert > unist-util-assert.js", + "build-mangle": "browserify . -s unistUtilAssert -p tinyify > unist-util-assert.min.js", "build": "npm run build-bundle && npm run build-mangle", "test-api": "node test", "test-coverage": "nyc --reporter lcov tape test", From ba2c1921f069e48546b4a2e00c6755db7f36a345 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 1 Nov 2018 10:59:47 +0100 Subject: [PATCH 29/85] 1.0.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b495750..373117d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unist-util-assert", - "version": "1.0.2", + "version": "1.0.3", "description": "Assert Unist nodes", "license": "MIT", "keywords": [ From 48aaa49b034947a3e13b25dea3b35318bcaf2381 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 22 May 2019 10:48:13 +0200 Subject: [PATCH 30/85] Fix tests on Windows --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 373117d..85f0f93 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "xo": "^0.23.0" }, "scripts": { - "format": "remark . -qfo && prettier --write '**/*.js' && xo --fix", + "format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", "build-bundle": "browserify . -s unistUtilAssert > unist-util-assert.js", "build-mangle": "browserify . -s unistUtilAssert -p tinyify > unist-util-assert.min.js", "build": "npm run build-bundle && npm run build-mangle", From 9d4a9575d0933b56c449629fcd58e799809bf155 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 22 May 2019 10:48:26 +0200 Subject: [PATCH 31/85] Update Node in Travis --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index adc8d34..9512fbb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js node_js: -- lts/boron -- node + - lts/dubnium + - node after_script: bash <(curl -s https://codecov.io/bash) deploy: provider: releases @@ -9,7 +9,7 @@ deploy: api_key: secure: qHdUT4ioWdJk8Vsk1QcWRU88miY/VEOHUSaRMYGs66/KwjKJZTXwwEpaU0O10AZvlX+xGwvg2omzrc0MY6YMu6Zol/PiGcI0yDD06LAOIW2J+X2877vw5YvQBZMW2iSL7bF8utOt5SpxtYEIV58tNHZwbFCS0zTDpqj62chKlFHOi+c95fqV33upRUx3vjVCbz0VdGIjsgyg++4Us2qZawfilhfsvNqG1UoJTdZqG5qvEJJ10IxnJqRTylrzzn+h2wP3RODmuWTYOhSQj8maE+jdlTb5bt0vd2Omo/Rd8dsAOWY87qsaL8x2hTcQO3dM9p07QjyhVu62YLfEqMP0TclnHb0L4t9mu5FVkp8aNs7ocL2tqh8B0RBTZSx1m0IVfOe6HSDNsGuMxZai2Zk9dZLxQyWO9Y66ohH3wv34MPtFvrdBBCB60Kcc4DjRNjSirFqU716zF0PzmkKLA55z2Txbqcqp3qBnMUojuDtuSkfquy5+/30q6ssfQV6czy/Sp/4zZMyb2X3Oq2smk/cb593rVQ/KtJIkjNByw+WZk90z6tXMQvxkhftNVjZxmBXZC70igV+zaWNAYwXQMGPkp+dcu5IkeX3GTfry50Z4BKfHmkJzgT3l4d6FpeO0yynzmHH6jSHxXsbnoo32CDWyhYTpdZPq/0LL1afWd13h9rk= file: - - "unist-util-assert.js" - - "unist-util-assert.min.js" + - 'unist-util-assert.js' + - 'unist-util-assert.min.js' on: tags: true From 8a01a9416b4866c0f63a93fa5d42cd5a5ca76b0c Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 22 May 2019 10:48:52 +0200 Subject: [PATCH 32/85] Update dev-dependencies --- index.js | 3 ++- package.json | 10 +++++----- test/index.js | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 97f2d34..3fba115 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,7 @@ var object = require('x-is-object') var inspect try { - // eslint-disable-next-line import/no-dynamic-require, no-useless-concat + // eslint-disable-next-line no-useless-concat inspect = require('ut' + 'il').inspect } catch (error) { /* Empty. */ @@ -117,6 +117,7 @@ function view(value) { } else { return JSON.stringify(value) } + /* eslint-enable no-else-return */ } catch (error) { /* istanbul ignore next - Cyclical. */ return String(value) diff --git a/package.json b/package.json index 85f0f93..b7d0011 100644 --- a/package.json +++ b/package.json @@ -24,13 +24,13 @@ ], "devDependencies": { "browserify": "^16.0.0", - "nyc": "^13.0.0", - "prettier": "^1.12.1", + "nyc": "^14.0.0", + "prettier": "^1.0.0", "remark-cli": "^6.0.0", - "remark-preset-wooorm": "^4.0.0", + "remark-preset-wooorm": "^5.0.0", "tape": "^4.0.0", - "tinyify": "^2.4.3", - "xo": "^0.23.0" + "tinyify": "^2.0.0", + "xo": "^0.24.0" }, "scripts": { "format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", diff --git a/test/index.js b/test/index.js index 6e1dfaa..a0c503c 100644 --- a/test/index.js +++ b/test/index.js @@ -1,7 +1,6 @@ 'use strict' /* eslint-disable import/no-unassigned-import */ - require('./node') require('./type') require('./value') @@ -11,3 +10,4 @@ require('./non-defined') require('./parent') require('./text') require('./void') +/* eslint-enable import/no-unassigned-import */ From 77b94344852c97457a2def9cbf5f5d928f3bdbfd Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 22 May 2019 10:53:40 +0200 Subject: [PATCH 33/85] Remove superfluous `xo` rules --- package.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/package.json b/package.json index b7d0011..e935d63 100644 --- a/package.json +++ b/package.json @@ -53,9 +53,6 @@ "prettier": true, "esnext": false, "rules": { - "guard-for-in": "off", - "no-var": "off", - "prefer-arrow-callback": "off", "no-eq-null": "off", "eqeqeq": "off" }, From 10ec5f76d6ef9114f8e31b20df695348d623fc0f Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 22 May 2019 10:55:43 +0200 Subject: [PATCH 34/85] Refactor comment-style --- index.js | 36 +++++++++++++++--------------------- test/void.js | 11 ----------- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/index.js b/index.js index 3fba115..059a399 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,5 @@ 'use strict' -/* Dependencies. */ var assert = require('assert') var array = require('x-is-array') var object = require('x-is-object') @@ -10,11 +9,8 @@ var inspect try { // eslint-disable-next-line no-useless-concat inspect = require('ut' + 'il').inspect -} catch (error) { - /* Empty. */ -} +} catch (error) {} -/* Expose. */ exports = wrap(unist) module.exports = exports @@ -23,14 +19,14 @@ exports.text = wrap(text) exports.void = wrap(empty) exports.wrap = wrap -/* Identifier to check if a value is seen. */ +// Identifier to check if a value is seen. var ID = '__unist__' -/* List of specced properties. */ +// List of specced properties. var defined = ['type', 'value', 'children', 'position'] -/* Wrapper around `Node` which adds the current node - * (and parent, if available), to the message. */ +// Wrapper around `Node` which adds the current node (and parent, if available), +// to the message. function wrap(fn) { return wrapped @@ -53,7 +49,7 @@ function wrap(fn) { } } -/* Assert. */ +// Assert. function unist(node) { var type var children @@ -95,8 +91,8 @@ function unist(node) { } } -/* Assert `value` (which lives at `key`) can be stringified - * and re-parsed to the same (deep) value. */ +// Assert `value` (which lives at `key`) can be stringified and re-parsed to the +// same (deep) value. function vanilla(key, value) { try { assert.deepStrictEqual(value, JSON.parse(JSON.stringify(value))) @@ -105,9 +101,8 @@ function vanilla(key, value) { } } -/* Stringify a value to inspect it. Tries `JSON.stringify()`, - * and if that fails uses `String()` instead. If `stringify()` - * works. */ +// Stringify a value to inspect it. +// Tries `JSON.stringify()`, and if that fails uses `String()` instead. function view(value) { try { /* eslint-disable no-else-return */ @@ -124,7 +119,7 @@ function view(value) { } } -/* Assert `node` is a parent node. */ +// Assert `node` is a parent node. function parent(node) { unist(node) @@ -132,7 +127,7 @@ function parent(node) { assert.ok('children' in node, 'parent should have `children`') } -/* Assert `node` is a text node. */ +// Assert `node` is a text node. function text(node) { unist(node) @@ -144,8 +139,7 @@ function text(node) { assert.ok('value' in node, 'text should have `value`') } -/* Assert `node` is a Unist node, but neither parent nor - * text. */ +// Assert `node` is a Unist node, but neither parent nor text. function empty(node) { unist(node) @@ -157,7 +151,7 @@ function empty(node) { ) } -/* Assert `location` is a Unist Location. */ +// Assert `location` is a Unist Location. function location(location) { if (location != null) { assert.ok(object(location), '`position` should be an object') @@ -167,7 +161,7 @@ function location(location) { } } -/* Assert `location` is a Unist Location. */ +// Assert `location` is a Unist Location. function position(position, name) { if (position != null) { assert.ok(object(position), '`' + name + '` should be an object') diff --git a/test/void.js b/test/void.js index eef6ef3..0cf8e08 100644 --- a/test/void.js +++ b/test/void.js @@ -1,16 +1,5 @@ -/** - * @author Titus Wormer - * @copyright 2016 Titus Wormer - * @license MIT - * @module unist-util-assert - * @fileoverview Test suite for `unist-util-assert`. - */ - 'use strict' -/* eslint-env node */ - -/* Dependencies. */ var test = require('tape') var assert = require('..') From 1c4c12ad23c1f9f055c92cedb3ed8b59c94ccb31 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 22 May 2019 10:57:34 +0200 Subject: [PATCH 35/85] Refactor internal terminology --- index.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 059a399..a458a86 100644 --- a/index.js +++ b/index.js @@ -72,7 +72,7 @@ function unist(node) { assert.strictEqual(typeof value, 'string', '`value` should be a string') } - location(node.position) + position(node.position) for (key in node) { if (defined.indexOf(key) === -1) { @@ -139,7 +139,7 @@ function text(node) { assert.ok('value' in node, 'text should have `value`') } -// Assert `node` is a Unist node, but neither parent nor text. +// Assert `node` is a unist node, but neither parent nor text. function empty(node) { unist(node) @@ -151,32 +151,32 @@ function empty(node) { ) } -// Assert `location` is a Unist Location. -function location(location) { - if (location != null) { - assert.ok(object(location), '`position` should be an object') +// Assert `position` is a unist position. +function position(position) { + if (position != null) { + assert.ok(object(position), '`position` should be an object') - position(location.start, 'position.start') - position(location.end, 'position.end') + point(position.start, 'position.start') + point(position.end, 'position.end') } } -// Assert `location` is a Unist Location. -function position(position, name) { - if (position != null) { - assert.ok(object(position), '`' + name + '` should be an object') +// Assert `point` is a unist point. +function point(point, name) { + if (point != null) { + assert.ok(object(point), '`' + name + '` should be an object') - if (position.line != null) { - assert.ok('line' in position, '`' + name + '` should have numeric `line`') - assert.ok(position.line >= 1, '`' + name + '.line` should be gte `1`') + if (point.line != null) { + assert.ok('line' in point, '`' + name + '` should have numeric `line`') + assert.ok(point.line >= 1, '`' + name + '.line` should be gte `1`') } - if (position.column != null) { + if (point.column != null) { assert.ok( - 'column' in position, + 'column' in point, '`' + name + '` should have numeric `column`' ) - assert.ok(position.column >= 1, '`' + name + '.column` should be gte `1`') + assert.ok(point.column >= 1, '`' + name + '.column` should be gte `1`') } } } From ab1e7d4c824eb9034f358c8b20cf7dc541a4fc2c Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 22 May 2019 10:58:07 +0200 Subject: [PATCH 36/85] Add more badges --- readme.md | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index 4aa9d69..1d9a60c 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,12 @@ -# unist-util-assert [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] +# unist-util-assert + +[![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] Assert [Unist][] nodes. @@ -93,13 +101,31 @@ repository, organisation, or community you agree to abide by its terms. -[travis-badge]: https://img.shields.io/travis/syntax-tree/unist-util-assert.svg +[build-badge]: https://img.shields.io/travis/syntax-tree/unist-util-assert.svg + +[build]: https://travis-ci.org/syntax-tree/unist-util-assert + +[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-assert.svg + +[coverage]: https://codecov.io/github/syntax-tree/unist-util-assert + +[downloads-badge]: https://img.shields.io/npm/dm/unist-util-assert.svg + +[downloads]: https://www.npmjs.com/package/unist-util-assert + +[size-badge]: https://img.shields.io/bundlephobia/minzip/unist-util-assert.svg + +[size]: https://bundlephobia.com/result?p=unist-util-assert + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg -[travis]: https://travis-ci.org/syntax-tree/unist-util-assert +[collective]: https://opencollective.com/unified -[codecov-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-assert.svg +[chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg -[codecov]: https://codecov.io/github/syntax-tree/unist-util-assert +[chat]: https://spectrum.chat/unified/syntax-tree [npm]: https://docs.npmjs.com/cli/install From cf9d09d186aa5e266a879d063eff83a86e90d74d Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 22 May 2019 11:04:32 +0200 Subject: [PATCH 37/85] Refactor prose --- readme.md | 66 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/readme.md b/readme.md index 1d9a60c..4e8a74b 100644 --- a/readme.md +++ b/readme.md @@ -8,9 +8,9 @@ [![Backers][backers-badge]][collective] [![Chat][chat-badge]][chat] -Assert [Unist][] nodes. +[**unist**][unist] utility to assert trees. -## Installation +## Install [npm][]: @@ -20,7 +20,7 @@ npm install unist-util-assert ## Usage -```javascript +```js var assert = require('unist-util-assert') assert({type: 'root', children: []}) @@ -46,41 +46,43 @@ assert({type: 'paragraph', children: ['foo']}) ## API -### `assert(node)` +### `assert(tree)` -Assert that `node` is a valid [Unist][] node. If `node` has `children`, -all children will be asserted as well. +Assert that [`tree`][tree] is a valid [unist][] [node][]. +If `tree` is a [parent][], all [child][]ren will be asserted as well. -### `assert.parent(node)` +### `assert.parent(tree)` -Assert that `node` is a valid Unist [Parent][]. +Assert that `tree` is a valid [unist][] [parent][]. +All [child][]ren will be asserted as well. ### `assert.text(node)` -Assert that `node` is a valid Unist [Text][]. +Assert that `node` is a valid [unist][] [literal][]. ### `assert.void(node)` -Assert that `node` is a valid Unist node, but neither Text nor Parent. +Assert that `node` is a valid [unist][] [node][], but neither [parent][] nor +[literal][]. ## Extensions -This module can be used as a base to test subsets of Unist (for an -example, see [`mdast-util-assert`][mdast-util-assert]). All functions -which are exposed from such a module, and functions used internally to -test child nodes, should be wrapped in `assert.wrap`, which adds an -inspectable string of the respective node, and its parent when available, -to exposed error message. +This module can be used as a base to test subsets of [unist][] (for an example, +see [`mdast-util-assert`][mdast-util-assert]). +All functions that are exposed from such a module, and functions used internally +to test [child][]ren, should be wrapped in `assert.wrap`, which adds an +inspectable string of the respective node, and its parent when available, to +the exposed error message. ### `assert.wrap(fn)` -Wraps a function (which is passed a node, and an optional parent node), -so that any errors thrown inside it will contain information regarding -the node (and the parent, when given). +Wraps `fn` (which is passed a node, and an optional parent node), so that any +errors thrown inside it will contain information regarding the node (and the +parent, when given). ## Related -* [`mdast-util-assert`](https://github.com/syntax-tree/mdast-util-assert) +* [`mdast-util-assert`][mdast-util-assert] — Check [mdast](https://github.com/syntax-tree/mdast) nodes * [`hast-util-assert`](https://github.com/syntax-tree/hast-util-assert) — Check [hast](https://github.com/syntax-tree/hast) nodes @@ -89,11 +91,13 @@ the node (and the parent, when given). ## Contribute -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. ## License @@ -133,14 +137,22 @@ repository, organisation, or community you agree to abide by its terms. [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 [parent]: https://github.com/syntax-tree/unist#parent -[text]: https://github.com/syntax-tree/unist#text +[literal]: https://github.com/syntax-tree/unist#literal -[mdast-util-assert]: https://github.com/syntax-tree/mdast-util-assert +[node]: https://github.com/syntax-tree/unist#node + +[tree]: https://github.com/syntax-tree/unist#tree -[contributing]: https://github.com/syntax-tree/unist/blob/master/contributing.md +[child]: https://github.com/syntax-tree/unist#child -[coc]: https://github.com/syntax-tree/unist/blob/master/code-of-conduct.md +[mdast-util-assert]: https://github.com/syntax-tree/mdast-util-assert From b93dba560a4465aabc59bfcc403fbe69f44413ba Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 22 May 2019 11:04:58 +0200 Subject: [PATCH 38/85] 1.0.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e935d63..5686397 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unist-util-assert", - "version": "1.0.3", + "version": "1.0.4", "description": "Assert Unist nodes", "license": "MIT", "keywords": [ From 86d85344cc9b5258131f43ab2eb10c7c2a508637 Mon Sep 17 00:00:00 2001 From: Christian Murphy Date: Wed, 13 Nov 2019 08:55:49 -0700 Subject: [PATCH 39/85] Add types Closes GH-1. Reviewed-by: Junyoung Choi Reviewed-by: Titus Wormer --- index.js | 8 +++---- package.json | 14 +++++++----- types/index.d.ts | 39 +++++++++++++++++++++++++++++++++ types/tsconfig.json | 10 +++++++++ types/tslint.json | 7 ++++++ types/unist-util-assert-test.ts | 25 +++++++++++++++++++++ 6 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 types/index.d.ts create mode 100644 types/tsconfig.json create mode 100644 types/tslint.json create mode 100644 types/unist-util-assert-test.ts diff --git a/index.js b/index.js index a458a86..6b53947 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,7 @@ var inspect try { // eslint-disable-next-line no-useless-concat inspect = require('ut' + 'il').inspect -} catch (error) {} +} catch (_) {} exports = wrap(unist) module.exports = exports @@ -75,7 +75,7 @@ function unist(node) { position(node.position) for (key in node) { - if (defined.indexOf(key) === -1) { + if (!defined.includes(key)) { vanilla(key, node[key]) } } @@ -96,7 +96,7 @@ function unist(node) { function vanilla(key, value) { try { assert.deepStrictEqual(value, JSON.parse(JSON.stringify(value))) - } catch (error) { + } catch (_) { assert.fail('non-specced property `' + key + '` should be JSON') } } @@ -113,7 +113,7 @@ function view(value) { return JSON.stringify(value) } /* eslint-enable no-else-return */ - } catch (error) { + } catch (_) { /* istanbul ignore next - Cyclical. */ return String(value) } diff --git a/package.json b/package.json index 5686397..9b2f9a1 100644 --- a/package.json +++ b/package.json @@ -20,17 +20,20 @@ "x-is-object": "^0.1.0" }, "files": [ - "index.js" + "index.js", + "types/index.d.ts" ], + "types": "types/index.d.ts", "devDependencies": { "browserify": "^16.0.0", + "dtslint": "^2.0.0", "nyc": "^14.0.0", "prettier": "^1.0.0", - "remark-cli": "^6.0.0", - "remark-preset-wooorm": "^5.0.0", + "remark-cli": "^7.0.0", + "remark-preset-wooorm": "^6.0.0", "tape": "^4.0.0", "tinyify": "^2.0.0", - "xo": "^0.24.0" + "xo": "^0.25.0" }, "scripts": { "format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", @@ -39,7 +42,8 @@ "build": "npm run build-bundle && npm run build-mangle", "test-api": "node test", "test-coverage": "nyc --reporter lcov tape test", - "test": "npm run format && npm run build && npm run test-coverage" + "test-types": "dtslint types", + "test": "npm run format && npm run build && npm run test-coverage && npm run test-types" }, "prettier": { "tabWidth": 2, diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..590b0f0 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,39 @@ +// TypeScript Version: 3.7 + +import {Node, Parent, Literal} from 'unist' + +declare namespace unistUtilAssert { + /** + * A unist Node that is neither a Parent nor a Literal. + */ + interface Void extends Node { + children: never + value: never + } +} + +declare const unistUtilAssert: { + /** + * Assert that tree is a valid unist node. + * If tree is a parent, all children will be asserted as well. + */ + (tree: unknown): asserts tree is Node + + /** + * Assert that tree is a valid unist parent. + * All children will be asserted as well. + */ + parent(tree: unknown): asserts tree is Parent + + /** + * Assert that node is a valid unist literal. + */ + text(tree: unknown): asserts tree is Literal + + /** + * Assert that node is a valid unist node, but neither parent nor literal. + */ + void(tree: unknown): asserts tree is unistUtilAssert.Void +} + +export = unistUtilAssert diff --git a/types/tsconfig.json b/types/tsconfig.json new file mode 100644 index 0000000..6c5f15b --- /dev/null +++ b/types/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "lib": ["es2015"], + "strict": true, + "baseUrl": ".", + "paths": { + "unist-util-assert": ["index.d.ts"] + } + } +} diff --git a/types/tslint.json b/types/tslint.json new file mode 100644 index 0000000..70c4494 --- /dev/null +++ b/types/tslint.json @@ -0,0 +1,7 @@ +{ + "extends": "dtslint/dtslint.json", + "rules": { + "semicolon": false, + "whitespace": false + } +} diff --git a/types/unist-util-assert-test.ts b/types/unist-util-assert-test.ts new file mode 100644 index 0000000..4ca0e8a --- /dev/null +++ b/types/unist-util-assert-test.ts @@ -0,0 +1,25 @@ +import * as assert from 'unist-util-assert' + +function testAssert() { + const node = {} + assert(node) + node // $ExpectType Node +} + +function testParentAssert() { + const node = {} + assert.parent(node) + node // $ExpectType Parent +} + +function testTextAssert() { + const node = {} + assert.text(node) + node // $ExpectType Literal +} + +function testVoidAssert() { + const node = {} + assert.void(node) + node // $ExpectType Void +} From 7301c36536c56966e30cf525233695fe938572a8 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 14 Nov 2019 17:38:29 +0100 Subject: [PATCH 40/85] 2.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9b2f9a1..b69d4e6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unist-util-assert", - "version": "1.0.4", + "version": "2.0.0", "description": "Assert Unist nodes", "license": "MIT", "keywords": [ From aab41c08240e113c132bbd7ad4a696a0ae88598c Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sun, 16 Feb 2020 15:04:43 +0100 Subject: [PATCH 41/85] Add `funding` field to `package.json` --- package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/package.json b/package.json index b69d4e6..4ef4118 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,10 @@ ], "repository": "syntax-tree/unist-util-assert", "bugs": "https://github.com/syntax-tree/unist-util-assert/issues", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, "author": "Titus Wormer (https://wooorm.com)", "contributors": [ "Titus Wormer (https://wooorm.com)" From bc7bf7c1499951a8f19d42dbdd12458ef0be86b8 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sun, 16 Feb 2020 15:05:19 +0100 Subject: [PATCH 42/85] Update metadata --- package.json | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 4ef4118..54996d5 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,16 @@ { "name": "unist-util-assert", "version": "2.0.0", - "description": "Assert Unist nodes", + "description": "unist utility to assert nodes", "license": "MIT", "keywords": [ - "assert", "unist", + "unist-util", "util", - "utility" + "utility", + "assert", + "check", + "test" ], "repository": "syntax-tree/unist-util-assert", "bugs": "https://github.com/syntax-tree/unist-util-assert/issues", From 65115c0091c3894b70f76e4f8e198f61307084e9 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sun, 16 Feb 2020 15:06:51 +0100 Subject: [PATCH 43/85] Refactor prose --- readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 4e8a74b..0fea61d 100644 --- a/readme.md +++ b/readme.md @@ -18,7 +18,7 @@ npm install unist-util-assert ``` -## Usage +## Use ```js var assert = require('unist-util-assert') @@ -95,8 +95,8 @@ See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get started. See [`support.md`][support] for ways to get help. -This project has a [Code of Conduct][coc]. -By interacting with this repository, organisation, or community you agree to +This project has a [code of conduct][coc]. +By interacting with this repository, organization, or community you agree to abide by its terms. ## License @@ -127,7 +127,7 @@ abide by its terms. [collective]: https://opencollective.com/unified -[chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg +[chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg [chat]: https://spectrum.chat/unified/syntax-tree From 988ea0805ae291a195524e795944797e963096da Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sun, 16 Feb 2020 15:07:03 +0100 Subject: [PATCH 44/85] Update dev-dependencies --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 54996d5..adfbc22 100644 --- a/package.json +++ b/package.json @@ -33,14 +33,14 @@ "types": "types/index.d.ts", "devDependencies": { "browserify": "^16.0.0", - "dtslint": "^2.0.0", - "nyc": "^14.0.0", + "dtslint": "^3.0.0", + "nyc": "^15.0.0", "prettier": "^1.0.0", "remark-cli": "^7.0.0", "remark-preset-wooorm": "^6.0.0", "tape": "^4.0.0", "tinyify": "^2.0.0", - "xo": "^0.25.0" + "xo": "^0.26.0" }, "scripts": { "format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", From 17fc036cd405adf213e9c1feea5c802dae865b87 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sun, 16 Feb 2020 15:07:51 +0100 Subject: [PATCH 45/85] 2.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index adfbc22..b6fb6c5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unist-util-assert", - "version": "2.0.0", + "version": "2.0.1", "description": "unist utility to assert nodes", "license": "MIT", "keywords": [ From fd50771537fe8af6935a166e66f2569404d30fca Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 17 Jun 2020 17:06:07 +0200 Subject: [PATCH 46/85] Change `master` in links to `HEAD` --- readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 0fea61d..26ebe36 100644 --- a/readme.md +++ b/readme.md @@ -137,11 +137,11 @@ abide by its terms. [author]: https://wooorm.com -[contributing]: https://github.com/syntax-tree/.github/blob/master/contributing.md +[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md -[support]: https://github.com/syntax-tree/.github/blob/master/support.md +[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md -[coc]: https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md +[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md [unist]: https://github.com/syntax-tree/unist From a379fb4c33aab816648f351fb92332f367bf6348 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 17 Jun 2020 17:07:13 +0200 Subject: [PATCH 47/85] Update dev-dependencies --- .prettierignore | 2 ++ package.json | 15 +++++++++------ test/children.js | 10 +++++----- test/node.js | 10 +++++----- test/non-defined.js | 6 +++--- test/parent.js | 10 +++++----- test/position.js | 36 ++++++++++++++++++------------------ test/text.js | 10 +++++----- test/type.js | 12 ++++++------ test/value.js | 12 ++++++------ test/void.js | 10 +++++----- 11 files changed, 69 insertions(+), 64 deletions(-) diff --git a/.prettierignore b/.prettierignore index c2357ce..892c49c 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,5 @@ coverage/ unist-util-assert.js unist-util-assert.min.js +*.json +*.md diff --git a/package.json b/package.json index b6fb6c5..5636ee0 100644 --- a/package.json +++ b/package.json @@ -35,15 +35,15 @@ "browserify": "^16.0.0", "dtslint": "^3.0.0", "nyc": "^15.0.0", - "prettier": "^1.0.0", - "remark-cli": "^7.0.0", - "remark-preset-wooorm": "^6.0.0", - "tape": "^4.0.0", + "prettier": "^2.0.0", + "remark-cli": "^8.0.0", + "remark-preset-wooorm": "^7.0.0", + "tape": "^5.0.0", "tinyify": "^2.0.0", - "xo": "^0.26.0" + "xo": "^0.32.0" }, "scripts": { - "format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", + "format": "remark . -qfo && prettier . --write && xo --fix", "build-bundle": "browserify . -s unistUtilAssert > unist-util-assert.js", "build-mangle": "browserify . -s unistUtilAssert -p tinyify > unist-util-assert.min.js", "build": "npm run build-bundle && npm run build-mangle", @@ -64,10 +64,13 @@ "prettier": true, "esnext": false, "rules": { + "unicorn/prefer-optional-catch-binding": "off", + "unicorn/prefer-set-has": "off", "no-eq-null": "off", "eqeqeq": "off" }, "ignores": [ + "types/", "unist-util-assert.js" ] }, diff --git a/test/children.js b/test/children.js index eddfb6a..634f20d 100644 --- a/test/children.js +++ b/test/children.js @@ -3,9 +3,9 @@ var test = require('tape') var assert = require('..') -test('children', function(t) { +test('children', function (t) { t.throws( - function() { + function () { assert({type: 'foo', children: {alpha: 'bravo'}}) }, /`children` should be an array: `{ type: 'foo', children: { alpha: 'bravo' } }`$/, @@ -13,19 +13,19 @@ test('children', function(t) { ) t.throws( - function() { + function () { assert({type: 'foo', children: ['one']}) }, /node should be an object: `'one'` in `{ type: 'foo', children: \[ 'one' ] }`$/, 'should throw if given a non-node child in children' ) - t.doesNotThrow(function() { + t.doesNotThrow(function () { assert({type: 'parent', children: [{type: 'text', value: 'alpha'}]}) }, 'should not throw on vald children') t.throws( - function() { + function () { assert({ type: 'foo', children: [ diff --git a/test/node.js b/test/node.js index 7f1ff79..0fa62f7 100644 --- a/test/node.js +++ b/test/node.js @@ -3,9 +3,9 @@ var test = require('tape') var assert = require('..') -test('node', function(t) { +test('node', function (t) { t.throws( - function() { + function () { assert() }, /node should be an object: `undefined`$/, @@ -13,7 +13,7 @@ test('node', function(t) { ) t.throws( - function() { + function () { assert(null) }, /node should be an object: `null`$/, @@ -21,7 +21,7 @@ test('node', function(t) { ) t.throws( - function() { + function () { assert('foo') }, /node should be an object: `'foo'`$/, @@ -29,7 +29,7 @@ test('node', function(t) { ) t.throws( - function() { + function () { assert(6) }, /node should be an object: `6`$/, diff --git a/test/non-defined.js b/test/non-defined.js index ed72e2c..97fe941 100644 --- a/test/non-defined.js +++ b/test/non-defined.js @@ -3,8 +3,8 @@ var test = require('tape') var assert = require('..') -test('non-defined', function(t) { - t.doesNotThrow(function() { +test('non-defined', function (t) { + t.doesNotThrow(function () { assert({ type: 'element', properties: { @@ -20,7 +20,7 @@ test('non-defined', function(t) { }, 'should not throw if non-defined properties are found') t.throws( - function() { + function () { assert({ type: 'break', data: {foo: Function} diff --git a/test/parent.js b/test/parent.js index ba62c49..5660da6 100644 --- a/test/parent.js +++ b/test/parent.js @@ -3,9 +3,9 @@ var test = require('tape') var assert = require('..') -test('assert.parent()', function(t) { +test('assert.parent()', function (t) { t.throws( - function() { + function () { assert.parent({}) }, /node should have a type: `{}`$/, @@ -13,7 +13,7 @@ test('assert.parent()', function(t) { ) t.throws( - function() { + function () { assert.parent({type: 'text', value: 'foo'}) }, /parent should not have `value`: `{ type: 'text', value: 'foo' }`$/, @@ -21,14 +21,14 @@ test('assert.parent()', function(t) { ) t.throws( - function() { + function () { assert.parent({type: 'break'}) }, /parent should have `children`: `{ type: 'break' }`$/, 'should throw if the given node has `children`' ) - t.doesNotThrow(function() { + t.doesNotThrow(function () { assert.parent({type: 'strong', children: []}) }, 'should not throw on valid void nodes') diff --git a/test/position.js b/test/position.js index dde618a..2f4665c 100644 --- a/test/position.js +++ b/test/position.js @@ -3,73 +3,73 @@ var test = require('tape') var assert = require('..') -test('position', function(t) { +test('position', function (t) { t.throws( - function() { + function () { assert({type: 'foo', position: 1}) }, /`position` should be an object: `{ type: 'foo', position: 1 }`$/, 'should throw if given a non-object `position`' ) - t.doesNotThrow(function() { + t.doesNotThrow(function () { assert({type: 'foo', position: null}) }, 'should not throw if given a null `position`') - t.doesNotThrow(function() { + t.doesNotThrow(function () { assert({type: 'foo', position: {}}) }, 'should not throw if given an empty `position` object') t.throws( - function() { + function () { assert({type: 'foo', position: {start: 1}}) }, /`position.start` should be an object: `{ type: 'foo', position: { start: 1 } }`$/, 'should throw if given a non-object `position.start`' ) - t.doesNotThrow(function() { + t.doesNotThrow(function () { assert({type: 'foo', position: {start: null}}) }, 'should not throw if given a null `position.start`') - t.doesNotThrow(function() { + t.doesNotThrow(function () { assert({type: 'foo', position: {start: {}}}) }, 'should not throw if given an empty `position.start` object') t.throws( - function() { + function () { assert({type: 'foo', position: {end: 1}}) }, /`position.end` should be an object: `{ type: 'foo', position: { end: 1 } }`$/, 'should throw if given a non-object `position.end`' ) - t.doesNotThrow(function() { + t.doesNotThrow(function () { assert({type: 'foo', position: {end: null}}) }, 'should not throw if given a null `position.end`') - t.doesNotThrow(function() { + t.doesNotThrow(function () { assert({type: 'foo', position: {end: {}}}) }, 'should not throw if given an empty `position.end` object') - t.doesNotThrow(function() { + t.doesNotThrow(function () { assert({type: 'foo', position: {start: {line: null}}}) }, 'should not throw if given a `position.start.line` to `null`') - t.doesNotThrow(function() { + t.doesNotThrow(function () { assert({type: 'foo', position: {start: {column: null}}}) }, 'should not throw if given a `position.start.column` to `null`') - t.doesNotThrow(function() { + t.doesNotThrow(function () { assert({type: 'foo', position: {end: {line: null}}}) }, 'should not throw if given a `position.end.line` to `null`') - t.doesNotThrow(function() { + t.doesNotThrow(function () { assert({type: 'foo', position: {end: {column: null}}}) }, 'should not throw if given a `position.end.column` to `null`') t.throws( - function() { + function () { assert({type: 'foo', position: {start: {line: 0}}}) }, /`position.start.line` should be gte `1`: `{ type: 'foo', position: { start: { line: 0 } } }`$/, @@ -77,7 +77,7 @@ test('position', function(t) { ) t.throws( - function() { + function () { assert({type: 'foo', position: {start: {column: 0}}}) }, /`position.start.column` should be gte `1`: `{ type: 'foo', position: { start: { column: 0 } } }`$/, @@ -85,7 +85,7 @@ test('position', function(t) { ) t.throws( - function() { + function () { assert({type: 'foo', position: {end: {line: 0}}}) }, /`position.end.line` should be gte `1`: `{ type: 'foo', position: { end: { line: 0 } } }`$/, @@ -93,7 +93,7 @@ test('position', function(t) { ) t.throws( - function() { + function () { assert({type: 'foo', position: {end: {column: 0}}}) }, /`position.end.column` should be gte `1`: `{ type: 'foo', position: { end: { column: 0 } } }`$/, diff --git a/test/text.js b/test/text.js index 889e0f3..44e41ab 100644 --- a/test/text.js +++ b/test/text.js @@ -3,9 +3,9 @@ var test = require('tape') var assert = require('..') -test('assert.text()', function(t) { +test('assert.text()', function (t) { t.throws( - function() { + function () { assert.text({}) }, /node should have a type: `{}`$/, @@ -13,7 +13,7 @@ test('assert.text()', function(t) { ) t.throws( - function() { + function () { assert.text({type: 'strong', children: []}) }, /text should not have `children`: `{ type: 'strong', children: \[] }`$/, @@ -21,14 +21,14 @@ test('assert.text()', function(t) { ) t.throws( - function() { + function () { assert.text({type: 'break'}) }, /text should have `value`: `{ type: 'break' }`$/, 'should throw if the given node has no `value`' ) - t.doesNotThrow(function() { + t.doesNotThrow(function () { assert.text({type: 'text', value: 'foo'}) }, 'should not throw on valid text nodes') diff --git a/test/type.js b/test/type.js index d328eaa..0ca440e 100644 --- a/test/type.js +++ b/test/type.js @@ -3,9 +3,9 @@ var test = require('tape') var assert = require('..') -test('type', function(t) { +test('type', function (t) { t.throws( - function() { + function () { assert([1, 5]) }, /node should have a type: `\[ 1, 5 ]`$/, @@ -13,7 +13,7 @@ test('type', function(t) { ) t.throws( - function() { + function () { assert({value: 'foo'}) }, /node should have a type: `{ value: 'foo' }`$/, @@ -21,7 +21,7 @@ test('type', function(t) { ) t.throws( - function() { + function () { assert({type: 1}) }, /`type` should be a string: `{ type: 1 }`$/, @@ -29,14 +29,14 @@ test('type', function(t) { ) t.throws( - function() { + function () { assert({type: ''}) }, /`type` should not be empty: `{ type: '' }`$/, 'should throw if given an empty string type' ) - t.doesNotThrow(function() { + t.doesNotThrow(function () { assert({type: 'foo'}) }, 'should not throw if given a non-empty type string') diff --git a/test/value.js b/test/value.js index c7c3f45..34ef6cf 100644 --- a/test/value.js +++ b/test/value.js @@ -3,28 +3,28 @@ var test = require('tape') var assert = require('..') -test('value', function(t) { +test('value', function (t) { t.throws( - function() { + function () { assert({type: 'foo', value: 1}) }, /`value` should be a string: `{ type: 'foo', value: 1 }`$/, 'should throw if given a non-string `value`' ) - t.doesNotThrow(function() { + t.doesNotThrow(function () { assert({type: 'foo', value: ''}) }, 'should not throw if given an empty string `value`') - t.doesNotThrow(function() { + t.doesNotThrow(function () { assert({type: 'foo', value: 'foo'}) }, 'should not throw if given an string `value`') - t.doesNotThrow(function() { + t.doesNotThrow(function () { assert({type: 'foo', value: undefined}) }, 'should not throw if given an undefined `value`') - t.doesNotThrow(function() { + t.doesNotThrow(function () { assert({type: 'foo', value: null}) }, 'should not throw if given an null `value`') diff --git a/test/void.js b/test/void.js index 0cf8e08..4adf914 100644 --- a/test/void.js +++ b/test/void.js @@ -3,9 +3,9 @@ var test = require('tape') var assert = require('..') -test('assert.void()', function(t) { +test('assert.void()', function (t) { t.throws( - function() { + function () { assert.void({}) }, /node should have a type: `{}`$/, @@ -13,7 +13,7 @@ test('assert.void()', function(t) { ) t.throws( - function() { + function () { assert.void({type: 'text', value: 'foo'}) }, /void should not have `value`: `{ type: 'text', value: 'foo' }`$/, @@ -21,14 +21,14 @@ test('assert.void()', function(t) { ) t.throws( - function() { + function () { assert.void({type: 'strong', children: []}) }, /void should not have `children`: `{ type: 'strong', children: \[] }`$/, 'should throw if the given node has `children`' ) - t.doesNotThrow(function() { + t.doesNotThrow(function () { assert.void({type: 'break'}) }, 'should not throw on valid void nodes') From 0516af5527518f8f00cee7573e661c31fea2e1bd Mon Sep 17 00:00:00 2001 From: Titus Date: Fri, 21 Aug 2020 11:28:57 +0200 Subject: [PATCH 48/85] Add Discussions --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 26ebe36..7cbde84 100644 --- a/readme.md +++ b/readme.md @@ -127,9 +127,9 @@ abide by its terms. [collective]: https://opencollective.com/unified -[chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg -[chat]: https://spectrum.chat/unified/syntax-tree +[chat]: https://github.com/syntax-tree/unist/discussions [npm]: https://docs.npmjs.com/cli/install From eba5a027db52e1b2d30bf495b36be440da780ffe Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 2 Nov 2020 15:32:07 +0100 Subject: [PATCH 49/85] Update dev-dependencies --- index.js | 10 ++-------- package.json | 18 +++++++++--------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index 6b53947..43a47ac 100644 --- a/index.js +++ b/index.js @@ -105,14 +105,8 @@ function vanilla(key, value) { // Tries `JSON.stringify()`, and if that fails uses `String()` instead. function view(value) { try { - /* eslint-disable no-else-return */ - /* istanbul ignore else - Browser. */ - if (inspect) { - return inspect(value, {colors: false}) - } else { - return JSON.stringify(value) - } - /* eslint-enable no-else-return */ + /* istanbul ignore next - Browser. */ + return inspect ? inspect(value, {colors: false}) : JSON.stringify(value) } catch (_) { /* istanbul ignore next - Cyclical. */ return String(value) diff --git a/package.json b/package.json index 5636ee0..f1a03dd 100644 --- a/package.json +++ b/package.json @@ -32,20 +32,20 @@ ], "types": "types/index.d.ts", "devDependencies": { - "browserify": "^16.0.0", - "dtslint": "^3.0.0", + "browserify": "^17.0.0", + "dtslint": "^4.0.0", "nyc": "^15.0.0", "prettier": "^2.0.0", - "remark-cli": "^8.0.0", - "remark-preset-wooorm": "^7.0.0", + "remark-cli": "^9.0.0", + "remark-preset-wooorm": "^8.0.0", "tape": "^5.0.0", - "tinyify": "^2.0.0", - "xo": "^0.32.0" + "tinyify": "^3.0.0", + "xo": "^0.34.0" }, "scripts": { - "format": "remark . -qfo && prettier . --write && xo --fix", - "build-bundle": "browserify . -s unistUtilAssert > unist-util-assert.js", - "build-mangle": "browserify . -s unistUtilAssert -p tinyify > unist-util-assert.min.js", + "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", + "build-bundle": "browserify . -s unistUtilAssert -o unist-util-assert.js", + "build-mangle": "browserify . -s unistUtilAssert -o unist-util-assert.min.js -p tinyify", "build": "npm run build-bundle && npm run build-mangle", "test-api": "node test", "test-coverage": "nyc --reporter lcov tape test", From e073c4c8d30616e2747d0885b426c53155727ca4 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 3 Dec 2020 12:19:22 +0100 Subject: [PATCH 50/85] Update dev-dependencies --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f1a03dd..7389049 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "remark-preset-wooorm": "^8.0.0", "tape": "^5.0.0", "tinyify": "^3.0.0", - "xo": "^0.34.0" + "xo": "^0.35.0" }, "scripts": { "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", From 7a6365c55c544371024fc2ad352317c323ec81e4 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 3 Dec 2020 12:19:24 +0100 Subject: [PATCH 51/85] Use Actions --- .github/workflows/main.yml | 21 +++++++++++++++++++++ .travis.yml | 15 --------------- readme.md | 4 ++-- 3 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/main.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..ffb6759 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,21 @@ +name: main +on: + - pull_request + - push +jobs: + main: + name: ${{matrix.node}} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: dcodeIO/setup-node-nvm@master + with: + node-version: ${{matrix.node}} + - run: npm install + - run: npm test + - uses: codecov/codecov-action@v1 + strategy: + matrix: + node: + - lts/dubnium + - node diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9512fbb..0000000 --- a/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -language: node_js -node_js: - - lts/dubnium - - node -after_script: bash <(curl -s https://codecov.io/bash) -deploy: - provider: releases - skip_cleanup: true - api_key: - secure: qHdUT4ioWdJk8Vsk1QcWRU88miY/VEOHUSaRMYGs66/KwjKJZTXwwEpaU0O10AZvlX+xGwvg2omzrc0MY6YMu6Zol/PiGcI0yDD06LAOIW2J+X2877vw5YvQBZMW2iSL7bF8utOt5SpxtYEIV58tNHZwbFCS0zTDpqj62chKlFHOi+c95fqV33upRUx3vjVCbz0VdGIjsgyg++4Us2qZawfilhfsvNqG1UoJTdZqG5qvEJJ10IxnJqRTylrzzn+h2wP3RODmuWTYOhSQj8maE+jdlTb5bt0vd2Omo/Rd8dsAOWY87qsaL8x2hTcQO3dM9p07QjyhVu62YLfEqMP0TclnHb0L4t9mu5FVkp8aNs7ocL2tqh8B0RBTZSx1m0IVfOe6HSDNsGuMxZai2Zk9dZLxQyWO9Y66ohH3wv34MPtFvrdBBCB60Kcc4DjRNjSirFqU716zF0PzmkKLA55z2Txbqcqp3qBnMUojuDtuSkfquy5+/30q6ssfQV6czy/Sp/4zZMyb2X3Oq2smk/cb593rVQ/KtJIkjNByw+WZk90z6tXMQvxkhftNVjZxmBXZC70igV+zaWNAYwXQMGPkp+dcu5IkeX3GTfry50Z4BKfHmkJzgT3l4d6FpeO0yynzmHH6jSHxXsbnoo32CDWyhYTpdZPq/0LL1afWd13h9rk= - file: - - 'unist-util-assert.js' - - 'unist-util-assert.min.js' - on: - tags: true diff --git a/readme.md b/readme.md index 7cbde84..1562d03 100644 --- a/readme.md +++ b/readme.md @@ -105,9 +105,9 @@ abide by its terms. -[build-badge]: https://img.shields.io/travis/syntax-tree/unist-util-assert.svg +[build-badge]: https://github.com/syntax-tree/unist-util-assert/workflows/main/badge.svg -[build]: https://travis-ci.org/syntax-tree/unist-util-assert +[build]: https://github.com/syntax-tree/unist-util-assert/actions [coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-assert.svg From 1e23ad16f126ade3c674919ed52b28ea098bdf31 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sun, 18 Apr 2021 14:04:52 +0200 Subject: [PATCH 52/85] Add bb --- .github/workflows/bb.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/workflows/bb.yml diff --git a/.github/workflows/bb.yml b/.github/workflows/bb.yml new file mode 100644 index 0000000..291ab09 --- /dev/null +++ b/.github/workflows/bb.yml @@ -0,0 +1,13 @@ +name: bb +on: + issues: + types: [opened, reopened, edited, closed, labeled, unlabeled] + pull_request: + types: [opened, reopened, edited, closed, labeled, unlabeled] +jobs: + main: + runs-on: ubuntu-latest + steps: + - uses: unifiedjs/beep-boop-beta@main + with: + repo-token: ${{secrets.GITHUB_TOKEN}} From a436c3903eb4a620081846ee3a6b5fedd7a8e594 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sun, 18 Apr 2021 14:05:02 +0200 Subject: [PATCH 53/85] Update Node in Actions --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ffb6759..fe284ad 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,5 +17,5 @@ jobs: strategy: matrix: node: - - lts/dubnium + - lts/erbium - node From c37d0e5499a1cfac4f76a2f93c2833f5f815799b Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sun, 18 Apr 2021 14:38:23 +0200 Subject: [PATCH 54/85] Use ESM --- .gitignore | 3 -- index.js | 115 ++++++++++++++++++++++---------------------- inspect.browser.js | 3 ++ inspect.js | 5 ++ package.json | 50 +++++++++---------- readme.md | 18 ++++--- test/children.js | 6 +-- test/index.js | 20 ++++---- test/node.js | 6 +-- test/non-defined.js | 6 +-- test/parent.js | 6 +-- test/position.js | 6 +-- test/text.js | 6 +-- test/type.js | 6 +-- test/value.js | 6 +-- test/void.js | 6 +-- 16 files changed, 126 insertions(+), 142 deletions(-) create mode 100644 inspect.browser.js create mode 100644 inspect.js diff --git a/.gitignore b/.gitignore index d007bef..735f4af 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,5 @@ .DS_Store *.log -.nyc_output/ coverage/ node_modules/ -unist-util-assert.js -unist-util-assert.min.js yarn.lock diff --git a/index.js b/index.js index 43a47ac..9323d23 100644 --- a/index.js +++ b/index.js @@ -1,33 +1,20 @@ -'use strict' +import nodeAssert from 'assert' +import {inspect} from './inspect.js' -var assert = require('assert') -var array = require('x-is-array') -var object = require('x-is-object') - -var inspect - -try { - // eslint-disable-next-line no-useless-concat - inspect = require('ut' + 'il').inspect -} catch (_) {} - -exports = wrap(unist) -module.exports = exports - -exports.parent = wrap(parent) -exports.text = wrap(text) -exports.void = wrap(empty) -exports.wrap = wrap +export var assert = wrap(assertNode) +assert.parent = wrap(parent) +assert.text = wrap(text) +assert.void = wrap(empty) // Identifier to check if a value is seen. var ID = '__unist__' // List of specced properties. -var defined = ['type', 'value', 'children', 'position'] +var defined = new Set(['type', 'value', 'children', 'position']) // Wrapper around `Node` which adds the current node (and parent, if available), // to the message. -function wrap(fn) { +export function wrap(fn) { return wrapped function wrapped(node, parent) { @@ -50,7 +37,7 @@ function wrap(fn) { } // Assert. -function unist(node) { +function assertNode(node) { var type var children var value @@ -58,35 +45,35 @@ function unist(node) { var index var length - assert.ok(object(node), 'node should be an object') + nodeAssert.ok(node === Object(node), 'node should be an object') type = node.type children = node.children value = node.value - assert.ok('type' in node, 'node should have a type') - assert.strictEqual(typeof type, 'string', '`type` should be a string') - assert.notStrictEqual(type, '', '`type` should not be empty') + nodeAssert.ok('type' in node, 'node should have a type') + nodeAssert.strictEqual(typeof type, 'string', '`type` should be a string') + nodeAssert.notStrictEqual(type, '', '`type` should not be empty') - if (value != null) { - assert.strictEqual(typeof value, 'string', '`value` should be a string') + if (value !== null && value !== undefined) { + nodeAssert.strictEqual(typeof value, 'string', '`value` should be a string') } position(node.position) for (key in node) { - if (!defined.includes(key)) { + if (!defined.has(key)) { vanilla(key, node[key]) } } - if (children != null) { - assert.ok(array(children), '`children` should be an array') + if (children !== null && children !== undefined) { + nodeAssert.ok(Array.isArray(children), '`children` should be an array') index = -1 length = children.length while (++index < length) { - exports(children[index], node) + assert(children[index], node) } } } @@ -95,9 +82,9 @@ function unist(node) { // same (deep) value. function vanilla(key, value) { try { - assert.deepStrictEqual(value, JSON.parse(JSON.stringify(value))) - } catch (_) { - assert.fail('non-specced property `' + key + '` should be JSON') + nodeAssert.deepStrictEqual(value, JSON.parse(JSON.stringify(value))) + } catch { + nodeAssert.fail('non-specced property `' + key + '` should be JSON') } } @@ -105,40 +92,43 @@ function vanilla(key, value) { // Tries `JSON.stringify()`, and if that fails uses `String()` instead. function view(value) { try { - /* istanbul ignore next - Browser. */ - return inspect ? inspect(value, {colors: false}) : JSON.stringify(value) - } catch (_) { - /* istanbul ignore next - Cyclical. */ + return inspect(value) + /* c8 ignore next 3 */ + } catch { return String(value) } } // Assert `node` is a parent node. function parent(node) { - unist(node) + assertNode(node) - assert.strictEqual('value' in node, false, 'parent should not have `value`') - assert.ok('children' in node, 'parent should have `children`') + nodeAssert.strictEqual( + 'value' in node, + false, + 'parent should not have `value`' + ) + nodeAssert.ok('children' in node, 'parent should have `children`') } // Assert `node` is a text node. function text(node) { - unist(node) + assertNode(node) - assert.strictEqual( + nodeAssert.strictEqual( 'children' in node, false, 'text should not have `children`' ) - assert.ok('value' in node, 'text should have `value`') + nodeAssert.ok('value' in node, 'text should have `value`') } // Assert `node` is a unist node, but neither parent nor text. function empty(node) { - unist(node) + assertNode(node) - assert.strictEqual('value' in node, false, 'void should not have `value`') - assert.strictEqual( + nodeAssert.strictEqual('value' in node, false, 'void should not have `value`') + nodeAssert.strictEqual( 'children' in node, false, 'void should not have `children`' @@ -147,8 +137,11 @@ function empty(node) { // Assert `position` is a unist position. function position(position) { - if (position != null) { - assert.ok(object(position), '`position` should be an object') + if (position !== null && position !== undefined) { + nodeAssert.ok( + position === Object(position), + '`position` should be an object' + ) point(position.start, 'position.start') point(position.end, 'position.end') @@ -157,20 +150,26 @@ function position(position) { // Assert `point` is a unist point. function point(point, name) { - if (point != null) { - assert.ok(object(point), '`' + name + '` should be an object') + if (point !== null && point !== undefined) { + nodeAssert.ok(point === Object(point), '`' + name + '` should be an object') - if (point.line != null) { - assert.ok('line' in point, '`' + name + '` should have numeric `line`') - assert.ok(point.line >= 1, '`' + name + '.line` should be gte `1`') + if (point.line !== null && point.line !== undefined) { + nodeAssert.ok( + 'line' in point, + '`' + name + '` should have numeric `line`' + ) + nodeAssert.ok(point.line >= 1, '`' + name + '.line` should be gte `1`') } - if (point.column != null) { - assert.ok( + if (point.column !== null && point.column !== undefined) { + nodeAssert.ok( 'column' in point, '`' + name + '` should have numeric `column`' ) - assert.ok(point.column >= 1, '`' + name + '.column` should be gte `1`') + nodeAssert.ok( + point.column >= 1, + '`' + name + '.column` should be gte `1`' + ) } } } diff --git a/inspect.browser.js b/inspect.browser.js new file mode 100644 index 0000000..ba997b8 --- /dev/null +++ b/inspect.browser.js @@ -0,0 +1,3 @@ +export function inspect(value) { + return JSON.stringify(value) +} diff --git a/inspect.js b/inspect.js new file mode 100644 index 0000000..e1fa1c9 --- /dev/null +++ b/inspect.js @@ -0,0 +1,5 @@ +import {inspect as utilInspect} from 'util' + +export function inspect(value) { + return utilInspect(value, {colors: false}) +} diff --git a/package.json b/package.json index 7389049..4b3b9b6 100644 --- a/package.json +++ b/package.json @@ -22,35 +22,38 @@ "contributors": [ "Titus Wormer (https://wooorm.com)" ], - "dependencies": { - "x-is-array": "^0.1.0", - "x-is-object": "^0.1.0" + "sideEffects": false, + "type": "module", + "main": "index.js", + "browser": { + "./inspect.js": "./inspect.browser.js" }, + "react-native": { + "./inspect.js": "./inspect.browser.js" + }, + "types": "types/index.d.ts", "files": [ "index.js", + "inspect.js", + "inspect.browser.js", "types/index.d.ts" ], - "types": "types/index.d.ts", + "dependencies": {}, "devDependencies": { - "browserify": "^17.0.0", + "c8": "^7.0.0", "dtslint": "^4.0.0", - "nyc": "^15.0.0", "prettier": "^2.0.0", "remark-cli": "^9.0.0", "remark-preset-wooorm": "^8.0.0", "tape": "^5.0.0", - "tinyify": "^3.0.0", - "xo": "^0.35.0" + "xo": "^0.38.0" }, "scripts": { "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", - "build-bundle": "browserify . -s unistUtilAssert -o unist-util-assert.js", - "build-mangle": "browserify . -s unistUtilAssert -o unist-util-assert.min.js -p tinyify", - "build": "npm run build-bundle && npm run build-mangle", - "test-api": "node test", - "test-coverage": "nyc --reporter lcov tape test", + "test-api": "node test/index.js", + "test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test/index.js", "test-types": "dtslint types", - "test": "npm run format && npm run build && npm run test-coverage && npm run test-types" + "test": "npm run format && npm run test-coverage && npm run test-types" }, "prettier": { "tabWidth": 2, @@ -62,24 +65,15 @@ }, "xo": { "prettier": true, - "esnext": false, "rules": { - "unicorn/prefer-optional-catch-binding": "off", - "unicorn/prefer-set-has": "off", - "no-eq-null": "off", - "eqeqeq": "off" + "import/no-mutable-exports": "off", + "no-var": "off", + "prefer-arrow-callback": "off" }, - "ignores": [ - "types/", - "unist-util-assert.js" + "ignore": [ + "types/" ] }, - "nyc": { - "check-coverage": true, - "lines": 100, - "functions": 100, - "branches": 100 - }, "remarkConfig": { "plugins": [ "preset-wooorm" diff --git a/readme.md b/readme.md index 1562d03..e40f06f 100644 --- a/readme.md +++ b/readme.md @@ -12,16 +12,19 @@ ## Install +This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): +Node 12+ is needed to use it and it must be `import`ed instead of `require`d. + [npm][]: -```bash +```sh npm install unist-util-assert ``` ## Use ```js -var assert = require('unist-util-assert') +import {assert} from 'unist-util-assert' assert({type: 'root', children: []}) assert({type: 'break'}) @@ -46,6 +49,9 @@ assert({type: 'paragraph', children: ['foo']}) ## API +This package exports the following identifiers: `assert`, `wrap`. +There is no default export. + ### `assert(tree)` Assert that [`tree`][tree] is a valid [unist][] [node][]. @@ -70,11 +76,11 @@ Assert that `node` is a valid [unist][] [node][], but neither [parent][] nor This module can be used as a base to test subsets of [unist][] (for an example, see [`mdast-util-assert`][mdast-util-assert]). All functions that are exposed from such a module, and functions used internally -to test [child][]ren, should be wrapped in `assert.wrap`, which adds an -inspectable string of the respective node, and its parent when available, to -the exposed error message. +to test [child][]ren, should be wrapped in `wrap`, which adds an inspectable +string of the respective node, and its parent when available, to the exposed +error message. -### `assert.wrap(fn)` +### `wrap(fn)` Wraps `fn` (which is passed a node, and an optional parent node), so that any errors thrown inside it will contain information regarding the node (and the diff --git a/test/children.js b/test/children.js index 634f20d..2e0ab62 100644 --- a/test/children.js +++ b/test/children.js @@ -1,7 +1,5 @@ -'use strict' - -var test = require('tape') -var assert = require('..') +import test from 'tape' +import {assert} from '../index.js' test('children', function (t) { t.throws( diff --git a/test/index.js b/test/index.js index a0c503c..d1b5062 100644 --- a/test/index.js +++ b/test/index.js @@ -1,13 +1,11 @@ -'use strict' - /* eslint-disable import/no-unassigned-import */ -require('./node') -require('./type') -require('./value') -require('./children') -require('./position') -require('./non-defined') -require('./parent') -require('./text') -require('./void') +import './node.js' +import './type.js' +import './value.js' +import './children.js' +import './position.js' +import './non-defined.js' +import './parent.js' +import './text.js' +import './void.js' /* eslint-enable import/no-unassigned-import */ diff --git a/test/node.js b/test/node.js index 0fa62f7..a557703 100644 --- a/test/node.js +++ b/test/node.js @@ -1,7 +1,5 @@ -'use strict' - -var test = require('tape') -var assert = require('..') +import test from 'tape' +import {assert} from '../index.js' test('node', function (t) { t.throws( diff --git a/test/non-defined.js b/test/non-defined.js index 97fe941..5632088 100644 --- a/test/non-defined.js +++ b/test/non-defined.js @@ -1,7 +1,5 @@ -'use strict' - -var test = require('tape') -var assert = require('..') +import test from 'tape' +import {assert} from '../index.js' test('non-defined', function (t) { t.doesNotThrow(function () { diff --git a/test/parent.js b/test/parent.js index 5660da6..70085e9 100644 --- a/test/parent.js +++ b/test/parent.js @@ -1,7 +1,5 @@ -'use strict' - -var test = require('tape') -var assert = require('..') +import test from 'tape' +import {assert} from '../index.js' test('assert.parent()', function (t) { t.throws( diff --git a/test/position.js b/test/position.js index 2f4665c..55244c7 100644 --- a/test/position.js +++ b/test/position.js @@ -1,7 +1,5 @@ -'use strict' - -var test = require('tape') -var assert = require('..') +import test from 'tape' +import {assert} from '../index.js' test('position', function (t) { t.throws( diff --git a/test/text.js b/test/text.js index 44e41ab..0fb9d2b 100644 --- a/test/text.js +++ b/test/text.js @@ -1,7 +1,5 @@ -'use strict' - -var test = require('tape') -var assert = require('..') +import test from 'tape' +import {assert} from '../index.js' test('assert.text()', function (t) { t.throws( diff --git a/test/type.js b/test/type.js index 0ca440e..3e87b42 100644 --- a/test/type.js +++ b/test/type.js @@ -1,7 +1,5 @@ -'use strict' - -var test = require('tape') -var assert = require('..') +import test from 'tape' +import {assert} from '../index.js' test('type', function (t) { t.throws( diff --git a/test/value.js b/test/value.js index 34ef6cf..e180874 100644 --- a/test/value.js +++ b/test/value.js @@ -1,7 +1,5 @@ -'use strict' - -var test = require('tape') -var assert = require('..') +import test from 'tape' +import {assert} from '../index.js' test('value', function (t) { t.throws( diff --git a/test/void.js b/test/void.js index 4adf914..9ff1d25 100644 --- a/test/void.js +++ b/test/void.js @@ -1,7 +1,5 @@ -'use strict' - -var test = require('tape') -var assert = require('..') +import test from 'tape' +import {assert} from '../index.js' test('assert.void()', function (t) { t.throws( From 098866da020d8dd8aaf57237458a45faa92560fa Mon Sep 17 00:00:00 2001 From: Titus Date: Mon, 10 May 2021 11:52:49 +0200 Subject: [PATCH 55/85] Add JSDoc based types Closes GH-2. --- .gitignore | 1 + index.js | 229 ++++++++++++++++++++++++-------- index.test-d.ts | 18 +++ inspect.browser.js | 4 + inspect.js | 4 + package.json | 34 +++-- readme.md | 27 ++-- test/index.js | 2 +- test/{text.js => literal.js} | 16 +-- test/parent.js | 12 +- test/type.js | 4 +- test/void.js | 12 +- tsconfig.json | 15 +++ types/index.d.ts | 39 ------ types/tsconfig.json | 10 -- types/tslint.json | 7 - types/unist-util-assert-test.ts | 25 ---- 17 files changed, 277 insertions(+), 182 deletions(-) create mode 100644 index.test-d.ts rename test/{text.js => literal.js} (54%) create mode 100644 tsconfig.json delete mode 100644 types/index.d.ts delete mode 100644 types/tsconfig.json delete mode 100644 types/tslint.json delete mode 100644 types/unist-util-assert-test.ts diff --git a/.gitignore b/.gitignore index 735f4af..c977c85 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .DS_Store +*.d.ts *.log coverage/ node_modules/ diff --git a/index.js b/index.js index 9323d23..38ed0dd 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,63 @@ +/** + * @typedef {import('assert').AssertionError} AssertionError + * @typedef {import('unist').Node} Node + * @typedef {import('unist').Parent} Parent + * @typedef {import('unist').Literal} Literal + * @typedef {import('unist').Position} Position + * @typedef {import('unist').Point} Point + * @typedef {Node & {children: never, value: never}} Void + */ + import nodeAssert from 'assert' import {inspect} from './inspect.js' -export var assert = wrap(assertNode) -assert.parent = wrap(parent) -assert.text = wrap(text) -assert.void = wrap(empty) +var own = {}.hasOwnProperty + +/** + * Assert that `node` is a valid unist node. + * If `node` is a parent, all children will be asserted too. + * + * @param {unknown} [node] + * @param {Parent} [parent] + * @returns {asserts node is Node} + */ +export function assert(node, parent) { + return wrap(assertNode)(node, parent) +} + +/** + * Assert that `node` is a valid unist parent. + * All children will be asserted too. + * + * @param {unknown} [node] + * @param {Parent} [parent] + * @returns {asserts node is Parent} + */ +export function parent(node, parent) { + return wrap(assertParent)(node, parent) +} + +/** + * Assert that `node` is a valid unist literal. + * + * @param {unknown} [node] + * @param {Parent} [parent] + * @returns {asserts node is Literal} + */ +export function literal(node, parent) { + return wrap(assertLiteral)(node, parent) +} + +/** + * Assert that `node` is a valid unist node, but neither parent nor literal. + * + * @param {unknown} [node] + * @param {Parent} [parent] + * @returns {asserts node is Void} + */ +export function _void(node, parent) { + return wrap(assertVoid)(node, parent) +} // Identifier to check if a value is seen. var ID = '__unist__' @@ -12,23 +65,30 @@ var ID = '__unist__' // List of specced properties. var defined = new Set(['type', 'value', 'children', 'position']) -// Wrapper around `Node` which adds the current node (and parent, if available), -// to the message. +/** + * Wrapper that adds the current node (and parent, if available) to error + * messages. + * + * @param {(node?: unknown, parent?: Parent|null) => asserts node is Node} fn + * @returns {(node?: unknown, parent?: Parent|null) => asserts node is Node} + */ export function wrap(fn) { return wrapped + /** + * @param {unknown} node + * @param {Parent} [parent] + * @throws {AssertionError} + * @returns {asserts node is T} + */ function wrapped(node, parent) { try { fn(node, parent) } catch (error) { - if (!error[ID]) { + if (!own.call(error, ID)) { error[ID] = true - error.message += ': `' + view(node) + '`' - - if (parent) { - error.message += ' in `' + view(parent) + '`' - } + if (parent) error.message += ' in `' + view(parent) + '`' } throw error @@ -36,29 +96,47 @@ export function wrap(fn) { } } -// Assert. +/** + * Assert. + * + * @param {unknown} node + * @returns {asserts node is Node} + */ function assertNode(node) { - var type - var children - var value + var index = -1 + /** @type {Parent} */ + var parent + /** @type {unknown} */ + var child + /** @type {string} */ var key - var index - var length - - nodeAssert.ok(node === Object(node), 'node should be an object') - type = node.type - children = node.children - value = node.value + nodeAssert.ok( + node && typeof node === 'object' && !Array.isArray(node), + 'node should be an object' + ) - nodeAssert.ok('type' in node, 'node should have a type') - nodeAssert.strictEqual(typeof type, 'string', '`type` should be a string') - nodeAssert.notStrictEqual(type, '', '`type` should not be empty') + nodeAssert.ok(own.call(node, 'type'), 'node should have a type') + nodeAssert.strictEqual( + // @ts-expect-error Looks like an indexed object. + typeof node.type, + 'string', + '`type` should be a string' + ) + // @ts-expect-error Looks like an indexed object. + nodeAssert.notStrictEqual(node.type, '', '`type` should not be empty') - if (value !== null && value !== undefined) { - nodeAssert.strictEqual(typeof value, 'string', '`value` should be a string') + // @ts-expect-error Looks like an indexed object. + if (node.value !== null && node.value !== undefined) { + nodeAssert.strictEqual( + // @ts-expect-error Looks like an indexed object. + typeof node.value, + 'string', + '`value` should be a string' + ) } + // @ts-expect-error Looks like an indexed object. position(node.position) for (key in node) { @@ -67,19 +145,30 @@ function assertNode(node) { } } - if (children !== null && children !== undefined) { - nodeAssert.ok(Array.isArray(children), '`children` should be an array') + // @ts-expect-error Looks like an indexed object. + if (node.children !== null && node.children !== undefined) { + // @ts-expect-error Looks like parent. + parent = node + nodeAssert.ok( + Array.isArray(parent.children), + '`children` should be an array' + ) index = -1 - length = children.length - while (++index < length) { - assert(children[index], node) + while (++index < parent.children.length) { + child = parent.children[index] + assert(child, parent) } } } -// Assert `value` (which lives at `key`) can be stringified and re-parsed to the -// same (deep) value. +/** + * Assert `value` (which lives at `key`) can be stringified and re-parsed to the + * same (deep) value. + * + * @param {string} key + * @param {unknown} value + */ function vanilla(key, value) { try { nodeAssert.deepStrictEqual(value, JSON.parse(JSON.stringify(value))) @@ -88,8 +177,13 @@ function vanilla(key, value) { } } -// Stringify a value to inspect it. -// Tries `JSON.stringify()`, and if that fails uses `String()` instead. +/** + * Stringify a value to inspect it. + * Tries `JSON.stringify()`, and if that fails uses `String()` instead. + * + * @param {unknown} value + * @returns {string} + */ function view(value) { try { return inspect(value) @@ -99,8 +193,13 @@ function view(value) { } } -// Assert `node` is a parent node. -function parent(node) { +/** + * Assert `node` is a parent node. + * + * @param {Node} node + * @returns {asserts node is Parent} + */ +function assertParent(node) { assertNode(node) nodeAssert.strictEqual( @@ -111,20 +210,30 @@ function parent(node) { nodeAssert.ok('children' in node, 'parent should have `children`') } -// Assert `node` is a text node. -function text(node) { +/** + * Assert `node` is a literal node. + * + * @param {Node} node + * @returns {asserts node is Literal} + */ +function assertLiteral(node) { assertNode(node) nodeAssert.strictEqual( 'children' in node, false, - 'text should not have `children`' + 'literal should not have `children`' ) - nodeAssert.ok('value' in node, 'text should have `value`') + nodeAssert.ok('value' in node, 'literal should have `value`') } -// Assert `node` is a unist node, but neither parent nor text. -function empty(node) { +/** + * Assert `node` is a unist node, but neither parent nor literal. + * + * @param {Node} node + * @returns {asserts node is Void} + */ +function assertVoid(node) { assertNode(node) nodeAssert.strictEqual('value' in node, false, 'void should not have `value`') @@ -135,7 +244,12 @@ function empty(node) { ) } -// Assert `position` is a unist position. +/** + * Assert `position` is a unist position. + * + * @param {Position} position + * @returns {asserts position is Position} + */ function position(position) { if (position !== null && position !== undefined) { nodeAssert.ok( @@ -148,27 +262,36 @@ function position(position) { } } -// Assert `point` is a unist point. -function point(point, name) { +/** + * Assert `point` is a unist point. + * + * @param {Point} point + * @param {string} label + * @returns {asserts point is Point} + */ +function point(point, label) { if (point !== null && point !== undefined) { - nodeAssert.ok(point === Object(point), '`' + name + '` should be an object') + nodeAssert.ok( + point === Object(point), + '`' + label + '` should be an object' + ) if (point.line !== null && point.line !== undefined) { nodeAssert.ok( 'line' in point, - '`' + name + '` should have numeric `line`' + '`' + label + '` should have numeric `line`' ) - nodeAssert.ok(point.line >= 1, '`' + name + '.line` should be gte `1`') + nodeAssert.ok(point.line >= 1, '`' + label + '.line` should be gte `1`') } if (point.column !== null && point.column !== undefined) { nodeAssert.ok( 'column' in point, - '`' + name + '` should have numeric `column`' + '`' + label + '` should have numeric `column`' ) nodeAssert.ok( point.column >= 1, - '`' + name + '.column` should be gte `1`' + '`' + label + '.column` should be gte `1`' ) } } diff --git a/index.test-d.ts b/index.test-d.ts new file mode 100644 index 0000000..a763e3b --- /dev/null +++ b/index.test-d.ts @@ -0,0 +1,18 @@ +import {expectType, expectNotType} from 'tsd' +import {Node, Parent} from 'unist' +import {assert, parent} from './index.js' + +var emptyNode = {type: 'a'} +var literalNode = {type: 'b', value: 'c'} +var parentNode = {type: 'd', children: [emptyNode, literalNode]} + +expectNotType(emptyNode) +expectNotType(literalNode) +expectNotType(parentNode) + +assert(emptyNode) +expectType(emptyNode) + +expectNotType(parentNode) +parent(parentNode) +expectType(parentNode) diff --git a/inspect.browser.js b/inspect.browser.js index ba997b8..ae54a93 100644 --- a/inspect.browser.js +++ b/inspect.browser.js @@ -1,3 +1,7 @@ +/** + * @param {unknown} value + * @returns {string} + */ export function inspect(value) { return JSON.stringify(value) } diff --git a/inspect.js b/inspect.js index e1fa1c9..99f3c98 100644 --- a/inspect.js +++ b/inspect.js @@ -1,5 +1,9 @@ import {inspect as utilInspect} from 'util' +/** + * @param {unknown} value + * @returns {string} + */ export function inspect(value) { return utilInspect(value, {colors: false}) } diff --git a/package.json b/package.json index 4b3b9b6..3eb6858 100644 --- a/package.json +++ b/package.json @@ -31,29 +31,38 @@ "react-native": { "./inspect.js": "./inspect.browser.js" }, - "types": "types/index.d.ts", + "types": "index.d.ts", "files": [ + "index.d.ts", "index.js", + "inspect.d.ts", "inspect.js", - "inspect.browser.js", - "types/index.d.ts" + "inspect.browser.d.ts", + "inspect.browser.js" ], - "dependencies": {}, + "dependencies": { + "@types/unist": "^2.0.0" + }, "devDependencies": { + "@types/tape": "^4.0.0", "c8": "^7.0.0", - "dtslint": "^4.0.0", "prettier": "^2.0.0", "remark-cli": "^9.0.0", "remark-preset-wooorm": "^8.0.0", + "rimraf": "^3.0.0", "tape": "^5.0.0", + "tsd": "^0.14.0", + "type-coverage": "^2.0.0", + "typescript": "^4.0.0", "xo": "^0.38.0" }, "scripts": { + "prepack": "npm run build && npm run format", + "build": "rimraf \"{test/**,}*.d.ts\" && tsc && tsd && type-coverage", "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", "test-api": "node test/index.js", "test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test/index.js", - "test-types": "dtslint types", - "test": "npm run format && npm run test-coverage && npm run test-types" + "test": "npm run build && npm run format && npm run test-coverage" }, "prettier": { "tabWidth": 2, @@ -69,14 +78,17 @@ "import/no-mutable-exports": "off", "no-var": "off", "prefer-arrow-callback": "off" - }, - "ignore": [ - "types/" - ] + } }, "remarkConfig": { "plugins": [ "preset-wooorm" ] + }, + "typeCoverage": { + "atLeast": 100, + "detail": true, + "strict": true, + "ignoreCatch": true } } diff --git a/readme.md b/readme.md index e40f06f..839bf47 100644 --- a/readme.md +++ b/readme.md @@ -24,7 +24,7 @@ npm install unist-util-assert ## Use ```js -import {assert} from 'unist-util-assert' +import {assert, parent, _void} from 'unist-util-assert' assert({type: 'root', children: []}) assert({type: 'break'}) @@ -34,13 +34,13 @@ assert({type: 'element', properties: {}, children: []}) assert({children: []}) // AssertionError: node should have a type: `{ children: [] }` -assert.parent({type: 'break'}) +parent({type: 'break'}) // AssertionError: parent should have `children`: `{ type: 'break' }` assert({type: 'element', properties: function() {}}) // AssertionError: non-specced property `properties` should be JSON: `{ type: 'element', properties: [Function] }` -assert.void({type: 'text', value: 'Alpha'}) +_void({type: 'text', value: 'Alpha'}) // AssertionError: void should not have `value`: `{ type: 'text', value: 'Alpha' }` assert({type: 'paragraph', children: ['foo']}) @@ -49,24 +49,25 @@ assert({type: 'paragraph', children: ['foo']}) ## API -This package exports the following identifiers: `assert`, `wrap`. +This package exports the following identifiers: `assert`, `parent`, `literal`, +`_void`, `wrap`. There is no default export. -### `assert(tree)` +### `assert(node[, parent])` -Assert that [`tree`][tree] is a valid [unist][] [node][]. -If `tree` is a [parent][], all [child][]ren will be asserted as well. +Assert that `node` is a valid [unist][] [node][]. +If `node` is a [parent][], all [child][]ren will be asserted too. -### `assert.parent(tree)` +### `parent(node[, parent])` -Assert that `tree` is a valid [unist][] [parent][]. -All [child][]ren will be asserted as well. +Assert that `node` is a valid [unist][] [parent][]. +All [child][]ren will be asserted too. -### `assert.text(node)` +### `literal(node[, parent])` Assert that `node` is a valid [unist][] [literal][]. -### `assert.void(node)` +### `_void(node[, parent])` Assert that `node` is a valid [unist][] [node][], but neither [parent][] nor [literal][]. @@ -157,8 +158,6 @@ abide by its terms. [node]: https://github.com/syntax-tree/unist#node -[tree]: https://github.com/syntax-tree/unist#tree - [child]: https://github.com/syntax-tree/unist#child [mdast-util-assert]: https://github.com/syntax-tree/mdast-util-assert diff --git a/test/index.js b/test/index.js index d1b5062..63a1f69 100644 --- a/test/index.js +++ b/test/index.js @@ -6,6 +6,6 @@ import './children.js' import './position.js' import './non-defined.js' import './parent.js' -import './text.js' +import './literal.js' import './void.js' /* eslint-enable import/no-unassigned-import */ diff --git a/test/text.js b/test/literal.js similarity index 54% rename from test/text.js rename to test/literal.js index 0fb9d2b..1ea51fb 100644 --- a/test/text.js +++ b/test/literal.js @@ -1,10 +1,10 @@ import test from 'tape' -import {assert} from '../index.js' +import {literal} from '../index.js' -test('assert.text()', function (t) { +test('literal()', function (t) { t.throws( function () { - assert.text({}) + literal({}) }, /node should have a type: `{}`$/, 'should throw the same errors as `assert()`' @@ -12,22 +12,22 @@ test('assert.text()', function (t) { t.throws( function () { - assert.text({type: 'strong', children: []}) + literal({type: 'strong', children: []}) }, - /text should not have `children`: `{ type: 'strong', children: \[] }`$/, + /literal should not have `children`: `{ type: 'strong', children: \[] }`$/, 'should throw if the given node has `children`' ) t.throws( function () { - assert.text({type: 'break'}) + literal({type: 'break'}) }, - /text should have `value`: `{ type: 'break' }`$/, + /literal should have `value`: `{ type: 'break' }`$/, 'should throw if the given node has no `value`' ) t.doesNotThrow(function () { - assert.text({type: 'text', value: 'foo'}) + literal({type: 'text', value: 'foo'}) }, 'should not throw on valid text nodes') t.end() diff --git a/test/parent.js b/test/parent.js index 70085e9..0879528 100644 --- a/test/parent.js +++ b/test/parent.js @@ -1,10 +1,10 @@ import test from 'tape' -import {assert} from '../index.js' +import {parent} from '../index.js' -test('assert.parent()', function (t) { +test('parent()', function (t) { t.throws( function () { - assert.parent({}) + parent({}) }, /node should have a type: `{}`$/, 'should throw the same errors as `assert()`' @@ -12,7 +12,7 @@ test('assert.parent()', function (t) { t.throws( function () { - assert.parent({type: 'text', value: 'foo'}) + parent({type: 'text', value: 'foo'}) }, /parent should not have `value`: `{ type: 'text', value: 'foo' }`$/, 'should throw if the given node has a `value`' @@ -20,14 +20,14 @@ test('assert.parent()', function (t) { t.throws( function () { - assert.parent({type: 'break'}) + parent({type: 'break'}) }, /parent should have `children`: `{ type: 'break' }`$/, 'should throw if the given node has `children`' ) t.doesNotThrow(function () { - assert.parent({type: 'strong', children: []}) + parent({type: 'strong', children: []}) }, 'should not throw on valid void nodes') t.end() diff --git a/test/type.js b/test/type.js index 3e87b42..5112d5d 100644 --- a/test/type.js +++ b/test/type.js @@ -4,9 +4,9 @@ import {assert} from '../index.js' test('type', function (t) { t.throws( function () { - assert([1, 5]) + assert({}) }, - /node should have a type: `\[ 1, 5 ]`$/, + /node should have a type: `{}`$/, 'should throw if not given a `type` (#1)' ) diff --git a/test/void.js b/test/void.js index 9ff1d25..2cb03d4 100644 --- a/test/void.js +++ b/test/void.js @@ -1,10 +1,10 @@ import test from 'tape' -import {assert} from '../index.js' +import {_void} from '../index.js' -test('assert.void()', function (t) { +test('_void()', function (t) { t.throws( function () { - assert.void({}) + _void({}) }, /node should have a type: `{}`$/, 'should throw the same errors as `assert()`' @@ -12,7 +12,7 @@ test('assert.void()', function (t) { t.throws( function () { - assert.void({type: 'text', value: 'foo'}) + _void({type: 'text', value: 'foo'}) }, /void should not have `value`: `{ type: 'text', value: 'foo' }`$/, 'should throw if the given node has a `value`' @@ -20,14 +20,14 @@ test('assert.void()', function (t) { t.throws( function () { - assert.void({type: 'strong', children: []}) + _void({type: 'strong', children: []}) }, /void should not have `children`: `{ type: 'strong', children: \[] }`$/, 'should throw if the given node has `children`' ) t.doesNotThrow(function () { - assert.void({type: 'break'}) + _void({type: 'break'}) }, 'should not throw on valid void nodes') t.end() diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..1cb61bf --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,15 @@ +{ + "include": ["*.js", "test/**/*.js"], + "compilerOptions": { + "target": "ES2020", + "lib": ["ES2020"], + "module": "ES2020", + "moduleResolution": "node", + "allowJs": true, + "checkJs": true, + "declaration": true, + "emitDeclarationOnly": true, + "allowSyntheticDefaultImports": true, + "skipLibCheck": true + } +} diff --git a/types/index.d.ts b/types/index.d.ts deleted file mode 100644 index 590b0f0..0000000 --- a/types/index.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -// TypeScript Version: 3.7 - -import {Node, Parent, Literal} from 'unist' - -declare namespace unistUtilAssert { - /** - * A unist Node that is neither a Parent nor a Literal. - */ - interface Void extends Node { - children: never - value: never - } -} - -declare const unistUtilAssert: { - /** - * Assert that tree is a valid unist node. - * If tree is a parent, all children will be asserted as well. - */ - (tree: unknown): asserts tree is Node - - /** - * Assert that tree is a valid unist parent. - * All children will be asserted as well. - */ - parent(tree: unknown): asserts tree is Parent - - /** - * Assert that node is a valid unist literal. - */ - text(tree: unknown): asserts tree is Literal - - /** - * Assert that node is a valid unist node, but neither parent nor literal. - */ - void(tree: unknown): asserts tree is unistUtilAssert.Void -} - -export = unistUtilAssert diff --git a/types/tsconfig.json b/types/tsconfig.json deleted file mode 100644 index 6c5f15b..0000000 --- a/types/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "compilerOptions": { - "lib": ["es2015"], - "strict": true, - "baseUrl": ".", - "paths": { - "unist-util-assert": ["index.d.ts"] - } - } -} diff --git a/types/tslint.json b/types/tslint.json deleted file mode 100644 index 70c4494..0000000 --- a/types/tslint.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "dtslint/dtslint.json", - "rules": { - "semicolon": false, - "whitespace": false - } -} diff --git a/types/unist-util-assert-test.ts b/types/unist-util-assert-test.ts deleted file mode 100644 index 4ca0e8a..0000000 --- a/types/unist-util-assert-test.ts +++ /dev/null @@ -1,25 +0,0 @@ -import * as assert from 'unist-util-assert' - -function testAssert() { - const node = {} - assert(node) - node // $ExpectType Node -} - -function testParentAssert() { - const node = {} - assert.parent(node) - node // $ExpectType Parent -} - -function testTextAssert() { - const node = {} - assert.text(node) - node // $ExpectType Literal -} - -function testVoidAssert() { - const node = {} - assert.void(node) - node // $ExpectType Void -} From c0de63b51449f557778617ebd0c31ff155f7b586 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 10 May 2021 11:58:27 +0200 Subject: [PATCH 56/85] Update dev-dependencies --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 3eb6858..2a6b10c 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "tsd": "^0.14.0", "type-coverage": "^2.0.0", "typescript": "^4.0.0", - "xo": "^0.38.0" + "xo": "^0.40.0" }, "scripts": { "prepack": "npm run build && npm run format", @@ -75,9 +75,9 @@ "xo": { "prettier": true, "rules": { - "import/no-mutable-exports": "off", "no-var": "off", - "prefer-arrow-callback": "off" + "prefer-arrow-callback": "off", + "unicorn/prefer-node-protocol": "off" } }, "remarkConfig": { From 742fd1e6902f717a1af1a3a4439dbf281a906116 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 10 May 2021 11:58:55 +0200 Subject: [PATCH 57/85] 3.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2a6b10c..1267b38 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unist-util-assert", - "version": "2.0.1", + "version": "3.0.0", "description": "unist utility to assert nodes", "license": "MIT", "keywords": [ From 37fce497e9f0d0c5bc38fcb23fa9916cdad3ee40 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 10 May 2021 13:25:17 +0200 Subject: [PATCH 58/85] Fix typescript --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 38ed0dd..765976e 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ * @typedef {import('unist').Literal} Literal * @typedef {import('unist').Position} Position * @typedef {import('unist').Point} Point - * @typedef {Node & {children: never, value: never}} Void + * @typedef {Node & {children: never, value: never}} _Void */ import nodeAssert from 'assert' @@ -53,7 +53,7 @@ export function literal(node, parent) { * * @param {unknown} [node] * @param {Parent} [parent] - * @returns {asserts node is Void} + * @returns {asserts node is _Void} */ export function _void(node, parent) { return wrap(assertVoid)(node, parent) @@ -231,7 +231,7 @@ function assertLiteral(node) { * Assert `node` is a unist node, but neither parent nor literal. * * @param {Node} node - * @returns {asserts node is Void} + * @returns {asserts node is _Void} */ function assertVoid(node) { assertNode(node) From 0c759cea4c6027cbb1db875544ad9d3ec8aec9ed Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 10 May 2021 13:25:29 +0200 Subject: [PATCH 59/85] 3.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1267b38..7072d53 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unist-util-assert", - "version": "3.0.0", + "version": "3.0.1", "description": "unist utility to assert nodes", "license": "MIT", "keywords": [ From 146bcac953e850356cd7e3ee9d9c3f7567a9cc06 Mon Sep 17 00:00:00 2001 From: Titus Date: Tue, 1 Jun 2021 10:39:42 +0200 Subject: [PATCH 60/85] Use `pull_request_target` in bb --- .github/workflows/bb.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bb.yml b/.github/workflows/bb.yml index 291ab09..0198fc3 100644 --- a/.github/workflows/bb.yml +++ b/.github/workflows/bb.yml @@ -2,7 +2,7 @@ name: bb on: issues: types: [opened, reopened, edited, closed, labeled, unlabeled] - pull_request: + pull_request_target: types: [opened, reopened, edited, closed, labeled, unlabeled] jobs: main: From 1343abc0576687c88ae70589d4ac3f57d7691850 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 21 Jul 2021 14:30:59 +0200 Subject: [PATCH 61/85] Update `tsd` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7072d53..a8a0580 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "remark-preset-wooorm": "^8.0.0", "rimraf": "^3.0.0", "tape": "^5.0.0", - "tsd": "^0.14.0", + "tsd": "^0.17.0", "type-coverage": "^2.0.0", "typescript": "^4.0.0", "xo": "^0.40.0" From 63e73cfbbbffbfe0791a66d73cb54cc7e8c7296b Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 21 Jul 2021 14:33:44 +0200 Subject: [PATCH 62/85] Refactor code-style --- index.js | 25 +++++++++++-------------- index.test-d.ts | 6 +++--- inspect.js | 2 +- package.json | 7 +------ test/children.js | 10 +++++----- test/literal.js | 10 +++++----- test/node.js | 10 +++++----- test/non-defined.js | 6 +++--- test/parent.js | 10 +++++----- test/position.js | 36 ++++++++++++++++++------------------ test/type.js | 12 ++++++------ test/value.js | 12 ++++++------ test/void.js | 10 +++++----- 13 files changed, 74 insertions(+), 82 deletions(-) diff --git a/index.js b/index.js index 765976e..1aeef84 100644 --- a/index.js +++ b/index.js @@ -8,10 +8,10 @@ * @typedef {Node & {children: never, value: never}} _Void */ -import nodeAssert from 'assert' +import nodeAssert from 'node:assert' import {inspect} from './inspect.js' -var own = {}.hasOwnProperty +const own = {}.hasOwnProperty /** * Assert that `node` is a valid unist node. @@ -60,10 +60,10 @@ export function _void(node, parent) { } // Identifier to check if a value is seen. -var ID = '__unist__' +const ID = '__unist__' // List of specced properties. -var defined = new Set(['type', 'value', 'children', 'position']) +const defined = new Set(['type', 'value', 'children', 'position']) /** * Wrapper that adds the current node (and parent, if available) to error @@ -103,13 +103,7 @@ export function wrap(fn) { * @returns {asserts node is Node} */ function assertNode(node) { - var index = -1 - /** @type {Parent} */ - var parent - /** @type {unknown} */ - var child - /** @type {string} */ - var key + let index = -1 nodeAssert.ok( node && typeof node === 'object' && !Array.isArray(node), @@ -139,6 +133,9 @@ function assertNode(node) { // @ts-expect-error Looks like an indexed object. position(node.position) + /** @type {string} */ + let key + for (key in node) { if (!defined.has(key)) { vanilla(key, node[key]) @@ -147,8 +144,9 @@ function assertNode(node) { // @ts-expect-error Looks like an indexed object. if (node.children !== null && node.children !== undefined) { + /** @type {Parent} */ // @ts-expect-error Looks like parent. - parent = node + const parent = node nodeAssert.ok( Array.isArray(parent.children), '`children` should be an array' @@ -156,8 +154,7 @@ function assertNode(node) { index = -1 while (++index < parent.children.length) { - child = parent.children[index] - assert(child, parent) + assert(parent.children[index], parent) } } } diff --git a/index.test-d.ts b/index.test-d.ts index a763e3b..96465a2 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -2,9 +2,9 @@ import {expectType, expectNotType} from 'tsd' import {Node, Parent} from 'unist' import {assert, parent} from './index.js' -var emptyNode = {type: 'a'} -var literalNode = {type: 'b', value: 'c'} -var parentNode = {type: 'd', children: [emptyNode, literalNode]} +const emptyNode = {type: 'a'} +const literalNode = {type: 'b', value: 'c'} +const parentNode = {type: 'd', children: [emptyNode, literalNode]} expectNotType(emptyNode) expectNotType(literalNode) diff --git a/inspect.js b/inspect.js index 99f3c98..389b9aa 100644 --- a/inspect.js +++ b/inspect.js @@ -1,4 +1,4 @@ -import {inspect as utilInspect} from 'util' +import {inspect as utilInspect} from 'node:util' /** * @param {unknown} value diff --git a/package.json b/package.json index a8a0580..59ff0d6 100644 --- a/package.json +++ b/package.json @@ -73,12 +73,7 @@ "trailingComma": "none" }, "xo": { - "prettier": true, - "rules": { - "no-var": "off", - "prefer-arrow-callback": "off", - "unicorn/prefer-node-protocol": "off" - } + "prettier": true }, "remarkConfig": { "plugins": [ diff --git a/test/children.js b/test/children.js index 2e0ab62..c197d8a 100644 --- a/test/children.js +++ b/test/children.js @@ -1,9 +1,9 @@ import test from 'tape' import {assert} from '../index.js' -test('children', function (t) { +test('children', (t) => { t.throws( - function () { + () => { assert({type: 'foo', children: {alpha: 'bravo'}}) }, /`children` should be an array: `{ type: 'foo', children: { alpha: 'bravo' } }`$/, @@ -11,19 +11,19 @@ test('children', function (t) { ) t.throws( - function () { + () => { assert({type: 'foo', children: ['one']}) }, /node should be an object: `'one'` in `{ type: 'foo', children: \[ 'one' ] }`$/, 'should throw if given a non-node child in children' ) - t.doesNotThrow(function () { + t.doesNotThrow(() => { assert({type: 'parent', children: [{type: 'text', value: 'alpha'}]}) }, 'should not throw on vald children') t.throws( - function () { + () => { assert({ type: 'foo', children: [ diff --git a/test/literal.js b/test/literal.js index 1ea51fb..7ee315e 100644 --- a/test/literal.js +++ b/test/literal.js @@ -1,9 +1,9 @@ import test from 'tape' import {literal} from '../index.js' -test('literal()', function (t) { +test('literal()', (t) => { t.throws( - function () { + () => { literal({}) }, /node should have a type: `{}`$/, @@ -11,7 +11,7 @@ test('literal()', function (t) { ) t.throws( - function () { + () => { literal({type: 'strong', children: []}) }, /literal should not have `children`: `{ type: 'strong', children: \[] }`$/, @@ -19,14 +19,14 @@ test('literal()', function (t) { ) t.throws( - function () { + () => { literal({type: 'break'}) }, /literal should have `value`: `{ type: 'break' }`$/, 'should throw if the given node has no `value`' ) - t.doesNotThrow(function () { + t.doesNotThrow(() => { literal({type: 'text', value: 'foo'}) }, 'should not throw on valid text nodes') diff --git a/test/node.js b/test/node.js index a557703..a20a7a6 100644 --- a/test/node.js +++ b/test/node.js @@ -1,9 +1,9 @@ import test from 'tape' import {assert} from '../index.js' -test('node', function (t) { +test('node', (t) => { t.throws( - function () { + () => { assert() }, /node should be an object: `undefined`$/, @@ -11,7 +11,7 @@ test('node', function (t) { ) t.throws( - function () { + () => { assert(null) }, /node should be an object: `null`$/, @@ -19,7 +19,7 @@ test('node', function (t) { ) t.throws( - function () { + () => { assert('foo') }, /node should be an object: `'foo'`$/, @@ -27,7 +27,7 @@ test('node', function (t) { ) t.throws( - function () { + () => { assert(6) }, /node should be an object: `6`$/, diff --git a/test/non-defined.js b/test/non-defined.js index 5632088..bae8870 100644 --- a/test/non-defined.js +++ b/test/non-defined.js @@ -1,8 +1,8 @@ import test from 'tape' import {assert} from '../index.js' -test('non-defined', function (t) { - t.doesNotThrow(function () { +test('non-defined', (t) => { + t.doesNotThrow(() => { assert({ type: 'element', properties: { @@ -18,7 +18,7 @@ test('non-defined', function (t) { }, 'should not throw if non-defined properties are found') t.throws( - function () { + () => { assert({ type: 'break', data: {foo: Function} diff --git a/test/parent.js b/test/parent.js index 0879528..0f76cba 100644 --- a/test/parent.js +++ b/test/parent.js @@ -1,9 +1,9 @@ import test from 'tape' import {parent} from '../index.js' -test('parent()', function (t) { +test('parent()', (t) => { t.throws( - function () { + () => { parent({}) }, /node should have a type: `{}`$/, @@ -11,7 +11,7 @@ test('parent()', function (t) { ) t.throws( - function () { + () => { parent({type: 'text', value: 'foo'}) }, /parent should not have `value`: `{ type: 'text', value: 'foo' }`$/, @@ -19,14 +19,14 @@ test('parent()', function (t) { ) t.throws( - function () { + () => { parent({type: 'break'}) }, /parent should have `children`: `{ type: 'break' }`$/, 'should throw if the given node has `children`' ) - t.doesNotThrow(function () { + t.doesNotThrow(() => { parent({type: 'strong', children: []}) }, 'should not throw on valid void nodes') diff --git a/test/position.js b/test/position.js index 55244c7..fa4139d 100644 --- a/test/position.js +++ b/test/position.js @@ -1,73 +1,73 @@ import test from 'tape' import {assert} from '../index.js' -test('position', function (t) { +test('position', (t) => { t.throws( - function () { + () => { assert({type: 'foo', position: 1}) }, /`position` should be an object: `{ type: 'foo', position: 1 }`$/, 'should throw if given a non-object `position`' ) - t.doesNotThrow(function () { + t.doesNotThrow(() => { assert({type: 'foo', position: null}) }, 'should not throw if given a null `position`') - t.doesNotThrow(function () { + t.doesNotThrow(() => { assert({type: 'foo', position: {}}) }, 'should not throw if given an empty `position` object') t.throws( - function () { + () => { assert({type: 'foo', position: {start: 1}}) }, /`position.start` should be an object: `{ type: 'foo', position: { start: 1 } }`$/, 'should throw if given a non-object `position.start`' ) - t.doesNotThrow(function () { + t.doesNotThrow(() => { assert({type: 'foo', position: {start: null}}) }, 'should not throw if given a null `position.start`') - t.doesNotThrow(function () { + t.doesNotThrow(() => { assert({type: 'foo', position: {start: {}}}) }, 'should not throw if given an empty `position.start` object') t.throws( - function () { + () => { assert({type: 'foo', position: {end: 1}}) }, /`position.end` should be an object: `{ type: 'foo', position: { end: 1 } }`$/, 'should throw if given a non-object `position.end`' ) - t.doesNotThrow(function () { + t.doesNotThrow(() => { assert({type: 'foo', position: {end: null}}) }, 'should not throw if given a null `position.end`') - t.doesNotThrow(function () { + t.doesNotThrow(() => { assert({type: 'foo', position: {end: {}}}) }, 'should not throw if given an empty `position.end` object') - t.doesNotThrow(function () { + t.doesNotThrow(() => { assert({type: 'foo', position: {start: {line: null}}}) }, 'should not throw if given a `position.start.line` to `null`') - t.doesNotThrow(function () { + t.doesNotThrow(() => { assert({type: 'foo', position: {start: {column: null}}}) }, 'should not throw if given a `position.start.column` to `null`') - t.doesNotThrow(function () { + t.doesNotThrow(() => { assert({type: 'foo', position: {end: {line: null}}}) }, 'should not throw if given a `position.end.line` to `null`') - t.doesNotThrow(function () { + t.doesNotThrow(() => { assert({type: 'foo', position: {end: {column: null}}}) }, 'should not throw if given a `position.end.column` to `null`') t.throws( - function () { + () => { assert({type: 'foo', position: {start: {line: 0}}}) }, /`position.start.line` should be gte `1`: `{ type: 'foo', position: { start: { line: 0 } } }`$/, @@ -75,7 +75,7 @@ test('position', function (t) { ) t.throws( - function () { + () => { assert({type: 'foo', position: {start: {column: 0}}}) }, /`position.start.column` should be gte `1`: `{ type: 'foo', position: { start: { column: 0 } } }`$/, @@ -83,7 +83,7 @@ test('position', function (t) { ) t.throws( - function () { + () => { assert({type: 'foo', position: {end: {line: 0}}}) }, /`position.end.line` should be gte `1`: `{ type: 'foo', position: { end: { line: 0 } } }`$/, @@ -91,7 +91,7 @@ test('position', function (t) { ) t.throws( - function () { + () => { assert({type: 'foo', position: {end: {column: 0}}}) }, /`position.end.column` should be gte `1`: `{ type: 'foo', position: { end: { column: 0 } } }`$/, diff --git a/test/type.js b/test/type.js index 5112d5d..1086770 100644 --- a/test/type.js +++ b/test/type.js @@ -1,9 +1,9 @@ import test from 'tape' import {assert} from '../index.js' -test('type', function (t) { +test('type', (t) => { t.throws( - function () { + () => { assert({}) }, /node should have a type: `{}`$/, @@ -11,7 +11,7 @@ test('type', function (t) { ) t.throws( - function () { + () => { assert({value: 'foo'}) }, /node should have a type: `{ value: 'foo' }`$/, @@ -19,7 +19,7 @@ test('type', function (t) { ) t.throws( - function () { + () => { assert({type: 1}) }, /`type` should be a string: `{ type: 1 }`$/, @@ -27,14 +27,14 @@ test('type', function (t) { ) t.throws( - function () { + () => { assert({type: ''}) }, /`type` should not be empty: `{ type: '' }`$/, 'should throw if given an empty string type' ) - t.doesNotThrow(function () { + t.doesNotThrow(() => { assert({type: 'foo'}) }, 'should not throw if given a non-empty type string') diff --git a/test/value.js b/test/value.js index e180874..2cc1ed9 100644 --- a/test/value.js +++ b/test/value.js @@ -1,28 +1,28 @@ import test from 'tape' import {assert} from '../index.js' -test('value', function (t) { +test('value', (t) => { t.throws( - function () { + () => { assert({type: 'foo', value: 1}) }, /`value` should be a string: `{ type: 'foo', value: 1 }`$/, 'should throw if given a non-string `value`' ) - t.doesNotThrow(function () { + t.doesNotThrow(() => { assert({type: 'foo', value: ''}) }, 'should not throw if given an empty string `value`') - t.doesNotThrow(function () { + t.doesNotThrow(() => { assert({type: 'foo', value: 'foo'}) }, 'should not throw if given an string `value`') - t.doesNotThrow(function () { + t.doesNotThrow(() => { assert({type: 'foo', value: undefined}) }, 'should not throw if given an undefined `value`') - t.doesNotThrow(function () { + t.doesNotThrow(() => { assert({type: 'foo', value: null}) }, 'should not throw if given an null `value`') diff --git a/test/void.js b/test/void.js index 2cb03d4..cc1ea54 100644 --- a/test/void.js +++ b/test/void.js @@ -1,9 +1,9 @@ import test from 'tape' import {_void} from '../index.js' -test('_void()', function (t) { +test('_void()', (t) => { t.throws( - function () { + () => { _void({}) }, /node should have a type: `{}`$/, @@ -11,7 +11,7 @@ test('_void()', function (t) { ) t.throws( - function () { + () => { _void({type: 'text', value: 'foo'}) }, /void should not have `value`: `{ type: 'text', value: 'foo' }`$/, @@ -19,14 +19,14 @@ test('_void()', function (t) { ) t.throws( - function () { + () => { _void({type: 'strong', children: []}) }, /void should not have `children`: `{ type: 'strong', children: \[] }`$/, 'should throw if the given node has `children`' ) - t.doesNotThrow(function () { + t.doesNotThrow(() => { _void({type: 'break'}) }, 'should not throw on valid void nodes') From d9d0d642ee9f8d17642eb1ec7c0a891d7f5224a9 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 21 Jul 2021 14:38:46 +0200 Subject: [PATCH 63/85] Add `strict` to `tsconfig` --- index.js | 13 ++++++++----- package.json | 6 +++++- tsconfig.json | 3 ++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 1aeef84..cac22fa 100644 --- a/index.js +++ b/index.js @@ -69,17 +69,17 @@ const defined = new Set(['type', 'value', 'children', 'position']) * Wrapper that adds the current node (and parent, if available) to error * messages. * - * @param {(node?: unknown, parent?: Parent|null) => asserts node is Node} fn - * @returns {(node?: unknown, parent?: Parent|null) => asserts node is Node} + * @param {(node?: any, parent?: Parent|null) => asserts node is Node} fn + * @returns {(node?: any, parent?: Parent|null) => asserts node is Node} */ export function wrap(fn) { return wrapped /** * @param {unknown} node - * @param {Parent} [parent] + * @param {Parent|null|undefined} [parent] * @throws {AssertionError} - * @returns {asserts node is T} + * @returns {void} */ function wrapped(node, parent) { try { @@ -138,7 +138,10 @@ function assertNode(node) { for (key in node) { if (!defined.has(key)) { - vanilla(key, node[key]) + /** @type {unknown} */ + // @ts-expect-error: hush. + const value = node[key] + vanilla(key, value) } } diff --git a/package.json b/package.json index 59ff0d6..849d6b9 100644 --- a/package.json +++ b/package.json @@ -84,6 +84,10 @@ "atLeast": 100, "detail": true, "strict": true, - "ignoreCatch": true + "ignoreCatch": true, + "#": "Couple of needed any’s", + "ignoreFiles": [ + "index.d.ts" + ] } } diff --git a/tsconfig.json b/tsconfig.json index 1cb61bf..ab9f0b7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,7 @@ "declaration": true, "emitDeclarationOnly": true, "allowSyntheticDefaultImports": true, - "skipLibCheck": true + "skipLibCheck": true, + "strict": true } } From b5a566c068ef3acf34993dbe3f64d945e3bfd3f7 Mon Sep 17 00:00:00 2001 From: Christian Murphy Date: Thu, 3 Mar 2022 11:02:05 -0700 Subject: [PATCH 64/85] Add `ignore-scripts` to `.npmrc` --- .npmrc | 1 + 1 file changed, 1 insertion(+) diff --git a/.npmrc b/.npmrc index 43c97e7..9951b11 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +1,2 @@ package-lock=false +ignore-scripts=true From dffaa98924f7a1806ff84ba237056d6627857479 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sun, 5 Jun 2022 11:45:17 +0200 Subject: [PATCH 65/85] Update dev-dependencies --- index.js | 14 ++++++++++---- package.json | 8 ++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index cac22fa..65b4393 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,11 @@ * @typedef {import('unist').Position} Position * @typedef {import('unist').Point} Point * @typedef {Node & {children: never, value: never}} _Void + * + * @typedef SeenErrorFields + * @property {true} [__unist__] + * + * @typedef {Error & SeenErrorFields} SeenError */ import nodeAssert from 'node:assert' @@ -85,10 +90,11 @@ export function wrap(fn) { try { fn(node, parent) } catch (error) { - if (!own.call(error, ID)) { - error[ID] = true - error.message += ': `' + view(node) + '`' - if (parent) error.message += ' in `' + view(parent) + '`' + const exception = /** @type {SeenError} */ (error) + if (!own.call(exception, ID)) { + exception[ID] = true + exception.message += ': `' + view(node) + '`' + if (parent) exception.message += ' in `' + view(parent) + '`' } throw error diff --git a/package.json b/package.json index 849d6b9..12d488b 100644 --- a/package.json +++ b/package.json @@ -47,14 +47,14 @@ "@types/tape": "^4.0.0", "c8": "^7.0.0", "prettier": "^2.0.0", - "remark-cli": "^9.0.0", - "remark-preset-wooorm": "^8.0.0", + "remark-cli": "^10.0.0", + "remark-preset-wooorm": "^9.0.0", "rimraf": "^3.0.0", "tape": "^5.0.0", - "tsd": "^0.17.0", + "tsd": "^0.20.0", "type-coverage": "^2.0.0", "typescript": "^4.0.0", - "xo": "^0.40.0" + "xo": "^0.49.0" }, "scripts": { "prepack": "npm run build && npm run format", From 93a6640fff53e555980f260a09a35a86baf0865c Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sun, 5 Jun 2022 11:53:08 +0200 Subject: [PATCH 66/85] Add improved docs --- readme.md | 139 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 105 insertions(+), 34 deletions(-) diff --git a/readme.md b/readme.md index 839bf47..349d461 100644 --- a/readme.md +++ b/readme.md @@ -8,19 +8,63 @@ [![Backers][backers-badge]][collective] [![Chat][chat-badge]][chat] -[**unist**][unist] utility to assert trees. +[unist][] utility to assert trees. -## Install +## Contents + +* [What is this?](#what-is-this) +* [When should I use this?](#when-should-i-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`assert(node[, parent])`](#assertnode-parent) + * [`parent(node[, parent])`](#parentnode-parent) + * [`literal(node[, parent])`](#literalnode-parent) + * [`_void(node[, parent])`](#_voidnode-parent) + * [`wrap(fn)`](#wrapfn) +* [Extensions](#extensions) +* [Types](#types) +* [Compatibility](#compatibility) +* [Related](#related) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package is a tiny utility that helps you deal with nodes. + +## When should I use this? -This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): -Node 12+ is needed to use it and it must be `import`ed instead of `require`d. +This utility is typically useful when you expect certain nodes in your APIs +and want to make sure they’re valid and as expected. -[npm][]: +Different utilities, [`mdast-util-assert`][mdast-util-assert], +[`hast-util-assert`][hast-util-assert], and [`nlcst-test`][nlcst-test], +do the same but for mdast, hast, and nlcst nodes, respectively. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [npm][]: ```sh npm install unist-util-assert ``` +In Deno with [`esm.sh`][esmsh]: + +```js +import {assert} from 'https://esm.sh/unist-util-assert@3' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + ## Use ```js @@ -49,37 +93,33 @@ assert({type: 'paragraph', children: ['foo']}) ## API -This package exports the following identifiers: `assert`, `parent`, `literal`, -`_void`, `wrap`. +This package exports the identifiers `assert`, `parent`, `literal`, `_void`, +and `wrap`. There is no default export. ### `assert(node[, parent])` -Assert that `node` is a valid [unist][] [node][]. -If `node` is a [parent][], all [child][]ren will be asserted too. +Assert that `node` is a valid unist [`Node`][node]. +If `tree` is a [parent][], all children will be asserted as well. + +###### Throws + +When `node`, or one of its children, is not a valid node. ### `parent(node[, parent])` -Assert that `node` is a valid [unist][] [parent][]. -All [child][]ren will be asserted too. +Assert that `node` is a valid unist [`Parent`][parent]. +All children will be asserted as well. ### `literal(node[, parent])` -Assert that `node` is a valid [unist][] [literal][]. +Assert that `node` is a valid unist [`Literal`][literal]. ### `_void(node[, parent])` -Assert that `node` is a valid [unist][] [node][], but neither [parent][] nor -[literal][]. - -## Extensions - -This module can be used as a base to test subsets of [unist][] (for an example, -see [`mdast-util-assert`][mdast-util-assert]). -All functions that are exposed from such a module, and functions used internally -to test [child][]ren, should be wrapped in `wrap`, which adds an inspectable -string of the respective node, and its parent when available, to the exposed -error message. +Assert that `node` is a valid unist [`Node`][node], but neither +[`Parent`][parent] nor +[`Literal`][literal]. ### `wrap(fn)` @@ -87,19 +127,40 @@ Wraps `fn` (which is passed a node, and an optional parent node), so that any errors thrown inside it will contain information regarding the node (and the parent, when given). +## Extensions + +This module can be used as a base to test subsets of unist (for an example, see +[`mdast-util-assert`][mdast-util-assert]). +All functions that are exposed from such a module, and functions used internally +to test children, should be wrapped in `wrap`, which adds an inspectable string +of the respective node, and its parent when available, to the exposed error +message. + +## Types + +This package is fully typed with [TypeScript][]. +It does not export additional types. + +## Compatibility + +Projects maintained by the unified collective are compatible with all maintained +versions of Node.js. +As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+. +Our projects sometimes work with older versions, but this is not guaranteed. + ## Related * [`mdast-util-assert`][mdast-util-assert] - — Check [mdast](https://github.com/syntax-tree/mdast) nodes + — assert mdast nodes * [`hast-util-assert`](https://github.com/syntax-tree/hast-util-assert) - — Check [hast](https://github.com/syntax-tree/hast) nodes + — assert hast nodes * [`nlcst-test`](https://github.com/syntax-tree/nlcst-test) - — Check [nlcst](https://github.com/syntax-tree/nlcst) nodes + — assert nlcst nodes ## Contribute -See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get -started. +See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for +ways to get started. See [`support.md`][support] for ways to get help. This project has a [code of conduct][coc]. @@ -140,24 +201,34 @@ abide by its terms. [npm]: https://docs.npmjs.com/cli/install +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[esmsh]: https://esm.sh + +[typescript]: https://www.typescriptlang.org + [license]: license [author]: https://wooorm.com -[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md +[health]: https://github.com/syntax-tree/.github -[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md +[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md -[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md +[support]: https://github.com/syntax-tree/.github/blob/main/support.md + +[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md [unist]: https://github.com/syntax-tree/unist +[node]: https://github.com/syntax-tree/unist#node + [parent]: https://github.com/syntax-tree/unist#parent [literal]: https://github.com/syntax-tree/unist#literal -[node]: https://github.com/syntax-tree/unist#node +[mdast-util-assert]: https://github.com/syntax-tree/mdast-util-assert -[child]: https://github.com/syntax-tree/unist#child +[hast-util-assert]: https://github.com/syntax-tree/hast-util-assert -[mdast-util-assert]: https://github.com/syntax-tree/mdast-util-assert +[nlcst-test]: https://github.com/syntax-tree/nlcst-test From d7a0967b3cc29df35f48a6ea36759f7736a96bd5 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 6 Jan 2023 17:43:45 +0100 Subject: [PATCH 67/85] Update dev-dependencies --- index.test-d.ts | 2 +- package.json | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/index.test-d.ts b/index.test-d.ts index 96465a2..e9f0264 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,5 +1,5 @@ import {expectType, expectNotType} from 'tsd' -import {Node, Parent} from 'unist' +import {type Node, type Parent} from 'unist' import {assert, parent} from './index.js' const emptyNode = {type: 'a'} diff --git a/package.json b/package.json index 12d488b..4fb2074 100644 --- a/package.json +++ b/package.json @@ -47,14 +47,14 @@ "@types/tape": "^4.0.0", "c8": "^7.0.0", "prettier": "^2.0.0", - "remark-cli": "^10.0.0", + "remark-cli": "^11.0.0", "remark-preset-wooorm": "^9.0.0", "rimraf": "^3.0.0", "tape": "^5.0.0", - "tsd": "^0.20.0", + "tsd": "^0.25.0", "type-coverage": "^2.0.0", "typescript": "^4.0.0", - "xo": "^0.49.0" + "xo": "^0.53.0" }, "scripts": { "prepack": "npm run build && npm run format", From 8406e39d34cf7ddf2a9dc07592d9691eb2c1d155 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 6 Jan 2023 17:43:56 +0100 Subject: [PATCH 68/85] Update Actions --- .github/workflows/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fe284ad..89dc06c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,15 +7,15 @@ jobs: name: ${{matrix.node}} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: dcodeIO/setup-node-nvm@master + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 with: node-version: ${{matrix.node}} - run: npm install - run: npm test - - uses: codecov/codecov-action@v1 + - uses: codecov/codecov-action@v3 strategy: matrix: node: - - lts/erbium + - lts/fermium - node From b6142059aee6a01e269508ac2abcb5ab5ffe137e Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 6 Jan 2023 17:44:32 +0100 Subject: [PATCH 69/85] Update `tsconfig.json` --- package.json | 7 +++---- tsconfig.json | 17 +++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 4fb2074..533e4c0 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,6 @@ "prettier": "^2.0.0", "remark-cli": "^11.0.0", "remark-preset-wooorm": "^9.0.0", - "rimraf": "^3.0.0", "tape": "^5.0.0", "tsd": "^0.25.0", "type-coverage": "^2.0.0", @@ -58,10 +57,10 @@ }, "scripts": { "prepack": "npm run build && npm run format", - "build": "rimraf \"{test/**,}*.d.ts\" && tsc && tsd && type-coverage", + "build": "tsc --build --clean && tsc --build && tsd && type-coverage", "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", - "test-api": "node test/index.js", - "test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test/index.js", + "test-api": "node --conditions development test.js", + "test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api", "test": "npm run build && npm run format && npm run test-coverage" }, "prettier": { diff --git a/tsconfig.json b/tsconfig.json index ab9f0b7..1bc9e99 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,16 +1,17 @@ { - "include": ["*.js", "test/**/*.js"], + "include": ["**/**.js"], + "exclude": ["coverage/", "node_modules/"], "compilerOptions": { - "target": "ES2020", - "lib": ["ES2020"], - "module": "ES2020", - "moduleResolution": "node", - "allowJs": true, "checkJs": true, "declaration": true, "emitDeclarationOnly": true, - "allowSyntheticDefaultImports": true, + "exactOptionalPropertyTypes": true, + "forceConsistentCasingInFileNames": true, + "lib": ["es2020"], + "module": "node16", + "newLine": "lf", "skipLibCheck": true, - "strict": true + "strict": true, + "target": "es2020" } } From b0889eadc286907c07a97c15f980b9b007db985e Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 6 Jan 2023 18:14:14 +0100 Subject: [PATCH 70/85] Refactor code-style * Add support for `null` in input of API * Add more docs to JSDoc * Add a type check --- index.js | 134 ++++++++++++++++++++++++++++++++++++++------------- package.json | 2 +- readme.md | 14 +++--- 3 files changed, 110 insertions(+), 40 deletions(-) diff --git a/index.js b/index.js index 65b4393..97b793a 100644 --- a/index.js +++ b/index.js @@ -19,46 +19,68 @@ import {inspect} from './inspect.js' const own = {}.hasOwnProperty /** - * Assert that `node` is a valid unist node. + * Assert that `tree` is a valid unist node. + * * If `node` is a parent, all children will be asserted too. * - * @param {unknown} [node] - * @param {Parent} [parent] - * @returns {asserts node is Node} + * @param {unknown} [tree] + * Thing to assert. + * @param {Parent | null | undefined} [parent] + * Optional, valid parent. + * @returns {asserts tree is Node} + * Whether `tree` (and its descendants) are valid nodes. + * @throws {AssertionError} + * When `tree` (or its descendants) is not a node. */ -export function assert(node, parent) { - return wrap(assertNode)(node, parent) +export function assert(tree, parent) { + return wrap(assertNode)(tree, parent) } /** - * Assert that `node` is a valid unist parent. + * Assert that `tree` is a valid unist parent. + * * All children will be asserted too. * - * @param {unknown} [node] - * @param {Parent} [parent] - * @returns {asserts node is Parent} + * @param {unknown} [tree] + * Thing to assert. + * @param {Parent | null | undefined} [parent] + * Optional, valid parent. + * @returns {asserts tree is Parent} + * Whether `tree` is a parent and its descendants are valid nodes. + * @throws {AssertionError} + * When `tree` is not a parent or its descendants are not nodes. */ -export function parent(node, parent) { - return wrap(assertParent)(node, parent) +export function parent(tree, parent) { + return wrap(assertParent)(tree, parent) } /** * Assert that `node` is a valid unist literal. * * @param {unknown} [node] - * @param {Parent} [parent] + * Thing to assert. + * @param {Parent | null | undefined} [parent] + * Optional, valid parent. * @returns {asserts node is Literal} + * Whether `node` is a literal. + * @throws {AssertionError} + * When `node` is not a literal. */ export function literal(node, parent) { return wrap(assertLiteral)(node, parent) } /** - * Assert that `node` is a valid unist node, but neither parent nor literal. + * Assert that `node` is a valid void node. * * @param {unknown} [node] - * @param {Parent} [parent] + * Thing to assert. + * @param {Parent | null | undefined} [parent] + * Optional, valid parent. * @returns {asserts node is _Void} + * Whether `node` is a node but neither parent nor literal. + * @throws {AssertionError} + * When `node` is not a node, a parent, or a literal. */ export function _void(node, parent) { return wrap(assertVoid)(node, parent) @@ -74,17 +96,25 @@ const defined = new Set(['type', 'value', 'children', 'position']) * Wrapper that adds the current node (and parent, if available) to error * messages. * - * @param {(node?: any, parent?: Parent|null) => asserts node is Node} fn - * @returns {(node?: any, parent?: Parent|null) => asserts node is Node} + * @template {Node} T + * Node type. + * @param {(node?: any, parent?: Parent | null | undefined) => asserts node is T} fn + * Custom assertion. + * @returns {(node?: any, parent?: Parent | null | undefined) => asserts node is T} + * Assertion. */ export function wrap(fn) { return wrapped /** * @param {unknown} node - * @param {Parent|null|undefined} [parent] + * Thing to check. + * @param {Parent | null | undefined} [parent] + * Optional, valid parent. * @throws {AssertionError} + * Whether `node` is a node but neither parent nor literal. * @returns {void} + * Nothing. */ function wrapped(node, parent) { try { @@ -103,10 +133,16 @@ export function wrap(fn) { } /** - * Assert. + * Assert that `node` is a valid unist parent. + * + * All children will be asserted too. * * @param {unknown} node + * Thing to assert. * @returns {asserts node is Node} + * Whether `node` (and its descendants) are valid nodes. + * @throws {AssertionError} + * When `node` (or its descendants) is not a node. */ function assertNode(node) { let index = -1 @@ -173,7 +209,9 @@ function assertNode(node) { * same (deep) value. * * @param {string} key + * Name of field. * @param {unknown} value + * Value of field. */ function vanilla(key, value) { try { @@ -185,10 +223,13 @@ function vanilla(key, value) { /** * Stringify a value to inspect it. + * * Tries `JSON.stringify()`, and if that fails uses `String()` instead. * * @param {unknown} value + * Anything (should be JSON). * @returns {string} + * User-visible preresentation. */ function view(value) { try { @@ -200,10 +241,16 @@ function view(value) { } /** - * Assert `node` is a parent node. + * Assert that `node` is a valid unist parent. + * + * All children will be asserted too. * * @param {Node} node + * Thing to assert. * @returns {asserts node is Parent} + * Whether `node` is a parent and its descendants are valid nodes. + * @throws {AssertionError} + * When `node` is not a parent or its descendants are not nodes. */ function assertParent(node) { assertNode(node) @@ -217,10 +264,14 @@ function assertParent(node) { } /** - * Assert `node` is a literal node. + * Assert that `node` is a valid unist literal. * - * @param {Node} node + * @param {unknown} [node] + * Thing to assert. * @returns {asserts node is Literal} + * Whether `node` is a literal. + * @throws {AssertionError} + * When `node` is not a literal. */ function assertLiteral(node) { assertNode(node) @@ -234,10 +285,14 @@ function assertLiteral(node) { } /** - * Assert `node` is a unist node, but neither parent nor literal. + * Assert that `node` is a valid void node. * - * @param {Node} node + * @param {unknown} [node] + * Thing to assert. * @returns {asserts node is _Void} + * Whether `node` is a node but neither parent nor literal. + * @throws {AssertionError} + * When `node` is not a node, a parent, or a literal. */ function assertVoid(node) { assertNode(node) @@ -251,19 +306,25 @@ function assertVoid(node) { } /** - * Assert `position` is a unist position. + * Assert that `position` is a unist position. * - * @param {Position} position + * @param {unknown} position + * Thing to assert. * @returns {asserts position is Position} + * Whether `position` is a unist position. + * @throws {AssertionError} + * When `position` is not a position. */ function position(position) { if (position !== null && position !== undefined) { nodeAssert.ok( - position === Object(position), + typeof position === 'object' && position === Object(position), '`position` should be an object' ) + // @ts-expect-error: indexable. point(position.start, 'position.start') + // @ts-expect-error: indexable. point(position.end, 'position.end') } } @@ -271,28 +332,35 @@ function position(position) { /** * Assert `point` is a unist point. * - * @param {Point} point + * @param {unknown} point + * Thing to assert. * @param {string} label + * Whether `point` is a unist point. * @returns {asserts point is Point} + * When `point` is not a point. */ function point(point, label) { if (point !== null && point !== undefined) { nodeAssert.ok( - point === Object(point), + typeof point === 'object' && point === Object(point), '`' + label + '` should be an object' ) - if (point.line !== null && point.line !== undefined) { + if ('line' in point && point.line !== null && point.line !== undefined) { nodeAssert.ok( - 'line' in point, + typeof point.line === 'number', '`' + label + '` should have numeric `line`' ) nodeAssert.ok(point.line >= 1, '`' + label + '.line` should be gte `1`') } - if (point.column !== null && point.column !== undefined) { + if ( + 'column' in point && + point.column !== null && + point.column !== undefined + ) { nodeAssert.ok( - 'column' in point, + typeof point.column === 'number', '`' + label + '` should have numeric `column`' ) nodeAssert.ok( diff --git a/package.json b/package.json index 533e4c0..c629571 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "prepack": "npm run build && npm run format", "build": "tsc --build --clean && tsc --build && tsd && type-coverage", "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", - "test-api": "node --conditions development test.js", + "test-api": "node --conditions development test/index.js", "test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api", "test": "npm run build && npm run format && npm run test-coverage" }, diff --git a/readme.md b/readme.md index 349d461..a4d157a 100644 --- a/readme.md +++ b/readme.md @@ -17,8 +17,8 @@ * [Install](#install) * [Use](#use) * [API](#api) - * [`assert(node[, parent])`](#assertnode-parent) - * [`parent(node[, parent])`](#parentnode-parent) + * [`assert(tree[, parent])`](#asserttree-parent) + * [`parent(tree[, parent])`](#parenttree-parent) * [`literal(node[, parent])`](#literalnode-parent) * [`_void(node[, parent])`](#_voidnode-parent) * [`wrap(fn)`](#wrapfn) @@ -97,18 +97,20 @@ This package exports the identifiers `assert`, `parent`, `literal`, `_void`, and `wrap`. There is no default export. -### `assert(node[, parent])` +### `assert(tree[, parent])` + +Assert that `tree` is a valid unist [`Node`][node]. -Assert that `node` is a valid unist [`Node`][node]. If `tree` is a [parent][], all children will be asserted as well. ###### Throws When `node`, or one of its children, is not a valid node. -### `parent(node[, parent])` +### `parent(tree[, parent])` + +Assert that `tree` is a valid unist [`Parent`][parent]. -Assert that `node` is a valid unist [`Parent`][parent]. All children will be asserted as well. ### `literal(node[, parent])` From 39273c7c8ca8007dab3625857bd78e094a0a5eb3 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 6 Jan 2023 18:23:21 +0100 Subject: [PATCH 71/85] Use Node test runner --- .github/workflows/main.yml | 2 +- package.json | 3 +-- test/children.js | 15 +++++++------- test/literal.js | 15 +++++++------- test/node.js | 15 +++++++------- test/non-defined.js | 11 +++++----- test/parent.js | 15 +++++++------- test/position.js | 41 +++++++++++++++++++------------------- test/type.js | 17 ++++++++-------- test/value.js | 17 ++++++++-------- test/void.js | 15 +++++++------- 11 files changed, 78 insertions(+), 88 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 89dc06c..ee318ca 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,5 +17,5 @@ jobs: strategy: matrix: node: - - lts/fermium + - lts/hydrogen - node diff --git a/package.json b/package.json index c629571..040af2a 100644 --- a/package.json +++ b/package.json @@ -44,12 +44,11 @@ "@types/unist": "^2.0.0" }, "devDependencies": { - "@types/tape": "^4.0.0", + "@types/node": "^18.0.0", "c8": "^7.0.0", "prettier": "^2.0.0", "remark-cli": "^11.0.0", "remark-preset-wooorm": "^9.0.0", - "tape": "^5.0.0", "tsd": "^0.25.0", "type-coverage": "^2.0.0", "typescript": "^4.0.0", diff --git a/test/children.js b/test/children.js index c197d8a..6a8e27c 100644 --- a/test/children.js +++ b/test/children.js @@ -1,8 +1,9 @@ -import test from 'tape' +import nodeAssert from 'node:assert/strict' +import test from 'node:test' import {assert} from '../index.js' -test('children', (t) => { - t.throws( +test('children', () => { + nodeAssert.throws( () => { assert({type: 'foo', children: {alpha: 'bravo'}}) }, @@ -10,7 +11,7 @@ test('children', (t) => { 'should throw if given a non-node child in children' ) - t.throws( + nodeAssert.throws( () => { assert({type: 'foo', children: ['one']}) }, @@ -18,11 +19,11 @@ test('children', (t) => { 'should throw if given a non-node child in children' ) - t.doesNotThrow(() => { + nodeAssert.doesNotThrow(() => { assert({type: 'parent', children: [{type: 'text', value: 'alpha'}]}) }, 'should not throw on vald children') - t.throws( + nodeAssert.throws( () => { assert({ type: 'foo', @@ -37,6 +38,4 @@ test('children', (t) => { /node should be an object: `'one'` in `{ type: 'bar', children: \[ 'one' ] }`$/, 'should throw on invalid descendants' ) - - t.end() }) diff --git a/test/literal.js b/test/literal.js index 7ee315e..b0c11fd 100644 --- a/test/literal.js +++ b/test/literal.js @@ -1,8 +1,9 @@ -import test from 'tape' +import assert from 'node:assert/strict' +import test from 'node:test' import {literal} from '../index.js' -test('literal()', (t) => { - t.throws( +test('literal()', () => { + assert.throws( () => { literal({}) }, @@ -10,7 +11,7 @@ test('literal()', (t) => { 'should throw the same errors as `assert()`' ) - t.throws( + assert.throws( () => { literal({type: 'strong', children: []}) }, @@ -18,7 +19,7 @@ test('literal()', (t) => { 'should throw if the given node has `children`' ) - t.throws( + assert.throws( () => { literal({type: 'break'}) }, @@ -26,9 +27,7 @@ test('literal()', (t) => { 'should throw if the given node has no `value`' ) - t.doesNotThrow(() => { + assert.doesNotThrow(() => { literal({type: 'text', value: 'foo'}) }, 'should not throw on valid text nodes') - - t.end() }) diff --git a/test/node.js b/test/node.js index a20a7a6..f9da6d6 100644 --- a/test/node.js +++ b/test/node.js @@ -1,8 +1,9 @@ -import test from 'tape' +import nodeAssert from 'node:assert/strict' +import test from 'node:test' import {assert} from '../index.js' -test('node', (t) => { - t.throws( +test('node', () => { + nodeAssert.throws( () => { assert() }, @@ -10,7 +11,7 @@ test('node', (t) => { 'should throw if not given a node (#1)' ) - t.throws( + nodeAssert.throws( () => { assert(null) }, @@ -18,7 +19,7 @@ test('node', (t) => { 'should throw if not given a node (#2)' ) - t.throws( + nodeAssert.throws( () => { assert('foo') }, @@ -26,13 +27,11 @@ test('node', (t) => { 'should throw if given a non-node (#1)' ) - t.throws( + nodeAssert.throws( () => { assert(6) }, /node should be an object: `6`$/, 'should throw if not given a non-node (#2)' ) - - t.end() }) diff --git a/test/non-defined.js b/test/non-defined.js index bae8870..abe7431 100644 --- a/test/non-defined.js +++ b/test/non-defined.js @@ -1,8 +1,9 @@ -import test from 'tape' +import nodeAssert from 'node:assert/strict' +import test from 'node:test' import {assert} from '../index.js' -test('non-defined', (t) => { - t.doesNotThrow(() => { +test('non-defined', () => { + nodeAssert.doesNotThrow(() => { assert({ type: 'element', properties: { @@ -17,7 +18,7 @@ test('non-defined', (t) => { }) }, 'should not throw if non-defined properties are found') - t.throws( + nodeAssert.throws( () => { assert({ type: 'break', @@ -27,6 +28,4 @@ test('non-defined', (t) => { /non-specced property `data` should be JSON: `{ type: 'break', data: { foo: \[Function: Function] } }`$/, 'should throw if non-defined properties are not serialisable' ) - - t.end() }) diff --git a/test/parent.js b/test/parent.js index 0f76cba..c247a19 100644 --- a/test/parent.js +++ b/test/parent.js @@ -1,8 +1,9 @@ -import test from 'tape' +import assert from 'node:assert/strict' +import test from 'node:test' import {parent} from '../index.js' -test('parent()', (t) => { - t.throws( +test('parent()', () => { + assert.throws( () => { parent({}) }, @@ -10,7 +11,7 @@ test('parent()', (t) => { 'should throw the same errors as `assert()`' ) - t.throws( + assert.throws( () => { parent({type: 'text', value: 'foo'}) }, @@ -18,7 +19,7 @@ test('parent()', (t) => { 'should throw if the given node has a `value`' ) - t.throws( + assert.throws( () => { parent({type: 'break'}) }, @@ -26,9 +27,7 @@ test('parent()', (t) => { 'should throw if the given node has `children`' ) - t.doesNotThrow(() => { + assert.doesNotThrow(() => { parent({type: 'strong', children: []}) }, 'should not throw on valid void nodes') - - t.end() }) diff --git a/test/position.js b/test/position.js index fa4139d..7c09655 100644 --- a/test/position.js +++ b/test/position.js @@ -1,8 +1,9 @@ -import test from 'tape' +import nodeAssert from 'node:assert/strict' +import test from 'node:test' import {assert} from '../index.js' -test('position', (t) => { - t.throws( +test('position', () => { + nodeAssert.throws( () => { assert({type: 'foo', position: 1}) }, @@ -10,15 +11,15 @@ test('position', (t) => { 'should throw if given a non-object `position`' ) - t.doesNotThrow(() => { + nodeAssert.doesNotThrow(() => { assert({type: 'foo', position: null}) }, 'should not throw if given a null `position`') - t.doesNotThrow(() => { + nodeAssert.doesNotThrow(() => { assert({type: 'foo', position: {}}) }, 'should not throw if given an empty `position` object') - t.throws( + nodeAssert.throws( () => { assert({type: 'foo', position: {start: 1}}) }, @@ -26,15 +27,15 @@ test('position', (t) => { 'should throw if given a non-object `position.start`' ) - t.doesNotThrow(() => { + nodeAssert.doesNotThrow(() => { assert({type: 'foo', position: {start: null}}) }, 'should not throw if given a null `position.start`') - t.doesNotThrow(() => { + nodeAssert.doesNotThrow(() => { assert({type: 'foo', position: {start: {}}}) }, 'should not throw if given an empty `position.start` object') - t.throws( + nodeAssert.throws( () => { assert({type: 'foo', position: {end: 1}}) }, @@ -42,31 +43,31 @@ test('position', (t) => { 'should throw if given a non-object `position.end`' ) - t.doesNotThrow(() => { + nodeAssert.doesNotThrow(() => { assert({type: 'foo', position: {end: null}}) }, 'should not throw if given a null `position.end`') - t.doesNotThrow(() => { + nodeAssert.doesNotThrow(() => { assert({type: 'foo', position: {end: {}}}) }, 'should not throw if given an empty `position.end` object') - t.doesNotThrow(() => { + nodeAssert.doesNotThrow(() => { assert({type: 'foo', position: {start: {line: null}}}) }, 'should not throw if given a `position.start.line` to `null`') - t.doesNotThrow(() => { + nodeAssert.doesNotThrow(() => { assert({type: 'foo', position: {start: {column: null}}}) }, 'should not throw if given a `position.start.column` to `null`') - t.doesNotThrow(() => { + nodeAssert.doesNotThrow(() => { assert({type: 'foo', position: {end: {line: null}}}) }, 'should not throw if given a `position.end.line` to `null`') - t.doesNotThrow(() => { + nodeAssert.doesNotThrow(() => { assert({type: 'foo', position: {end: {column: null}}}) }, 'should not throw if given a `position.end.column` to `null`') - t.throws( + nodeAssert.throws( () => { assert({type: 'foo', position: {start: {line: 0}}}) }, @@ -74,7 +75,7 @@ test('position', (t) => { 'should throw if `position.start.line` is less than 1' ) - t.throws( + nodeAssert.throws( () => { assert({type: 'foo', position: {start: {column: 0}}}) }, @@ -82,7 +83,7 @@ test('position', (t) => { 'should throw if `position.start.column` is less than 1' ) - t.throws( + nodeAssert.throws( () => { assert({type: 'foo', position: {end: {line: 0}}}) }, @@ -90,13 +91,11 @@ test('position', (t) => { 'should throw if `position.end.line` is less than 1' ) - t.throws( + nodeAssert.throws( () => { assert({type: 'foo', position: {end: {column: 0}}}) }, /`position.end.column` should be gte `1`: `{ type: 'foo', position: { end: { column: 0 } } }`$/, 'should throw if `position.end.column` is less than 1' ) - - t.end() }) diff --git a/test/type.js b/test/type.js index 1086770..52e2afd 100644 --- a/test/type.js +++ b/test/type.js @@ -1,8 +1,9 @@ -import test from 'tape' +import nodeAssert from 'node:assert/strict' +import test from 'node:test' import {assert} from '../index.js' -test('type', (t) => { - t.throws( +test('type', () => { + nodeAssert.throws( () => { assert({}) }, @@ -10,7 +11,7 @@ test('type', (t) => { 'should throw if not given a `type` (#1)' ) - t.throws( + nodeAssert.throws( () => { assert({value: 'foo'}) }, @@ -18,7 +19,7 @@ test('type', (t) => { 'should throw if not given a type (#2)' ) - t.throws( + nodeAssert.throws( () => { assert({type: 1}) }, @@ -26,7 +27,7 @@ test('type', (t) => { 'should throw if not given a non-string type' ) - t.throws( + nodeAssert.throws( () => { assert({type: ''}) }, @@ -34,9 +35,7 @@ test('type', (t) => { 'should throw if given an empty string type' ) - t.doesNotThrow(() => { + nodeAssert.doesNotThrow(() => { assert({type: 'foo'}) }, 'should not throw if given a non-empty type string') - - t.end() }) diff --git a/test/value.js b/test/value.js index 2cc1ed9..f2f50e5 100644 --- a/test/value.js +++ b/test/value.js @@ -1,8 +1,9 @@ -import test from 'tape' +import nodeAssert from 'node:assert/strict' +import test from 'node:test' import {assert} from '../index.js' -test('value', (t) => { - t.throws( +test('value', () => { + nodeAssert.throws( () => { assert({type: 'foo', value: 1}) }, @@ -10,21 +11,19 @@ test('value', (t) => { 'should throw if given a non-string `value`' ) - t.doesNotThrow(() => { + nodeAssert.doesNotThrow(() => { assert({type: 'foo', value: ''}) }, 'should not throw if given an empty string `value`') - t.doesNotThrow(() => { + nodeAssert.doesNotThrow(() => { assert({type: 'foo', value: 'foo'}) }, 'should not throw if given an string `value`') - t.doesNotThrow(() => { + nodeAssert.doesNotThrow(() => { assert({type: 'foo', value: undefined}) }, 'should not throw if given an undefined `value`') - t.doesNotThrow(() => { + nodeAssert.doesNotThrow(() => { assert({type: 'foo', value: null}) }, 'should not throw if given an null `value`') - - t.end() }) diff --git a/test/void.js b/test/void.js index cc1ea54..7384f2c 100644 --- a/test/void.js +++ b/test/void.js @@ -1,8 +1,9 @@ -import test from 'tape' +import assert from 'node:assert/strict' +import test from 'node:test' import {_void} from '../index.js' -test('_void()', (t) => { - t.throws( +test('_void()', () => { + assert.throws( () => { _void({}) }, @@ -10,7 +11,7 @@ test('_void()', (t) => { 'should throw the same errors as `assert()`' ) - t.throws( + assert.throws( () => { _void({type: 'text', value: 'foo'}) }, @@ -18,7 +19,7 @@ test('_void()', (t) => { 'should throw if the given node has a `value`' ) - t.throws( + assert.throws( () => { _void({type: 'strong', children: []}) }, @@ -26,9 +27,7 @@ test('_void()', (t) => { 'should throw if the given node has `children`' ) - t.doesNotThrow(() => { + assert.doesNotThrow(() => { _void({type: 'break'}) }, 'should not throw on valid void nodes') - - t.end() }) From e0f582e967e052fd1c4b98c4bb745407ab37ff52 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 6 Jan 2023 18:27:17 +0100 Subject: [PATCH 72/85] Refactor to move implementation to `lib/` --- index.js | 371 +----------------- index.test-d.ts | 2 +- lib/index.js | 372 +++++++++++++++++++ inspect.browser.js => lib/inspect.browser.js | 0 inspect.js => lib/inspect.js | 0 package.json | 13 +- readme.md | 2 +- 7 files changed, 381 insertions(+), 379 deletions(-) create mode 100644 lib/index.js rename inspect.browser.js => lib/inspect.browser.js (100%) rename inspect.js => lib/inspect.js (100%) diff --git a/index.js b/index.js index 97b793a..a286e7d 100644 --- a/index.js +++ b/index.js @@ -1,372 +1,5 @@ /** - * @typedef {import('assert').AssertionError} AssertionError - * @typedef {import('unist').Node} Node - * @typedef {import('unist').Parent} Parent - * @typedef {import('unist').Literal} Literal - * @typedef {import('unist').Position} Position - * @typedef {import('unist').Point} Point - * @typedef {Node & {children: never, value: never}} _Void - * - * @typedef SeenErrorFields - * @property {true} [__unist__] - * - * @typedef {Error & SeenErrorFields} SeenError + * @typedef {import('./lib/index.js').AssertionError} AssertionError */ -import nodeAssert from 'node:assert' -import {inspect} from './inspect.js' - -const own = {}.hasOwnProperty - -/** - * Assert that `tree` is a valid unist node. - * - * If `node` is a parent, all children will be asserted too. - * - * @param {unknown} [tree] - * Thing to assert. - * @param {Parent | null | undefined} [parent] - * Optional, valid parent. - * @returns {asserts tree is Node} - * Whether `tree` (and its descendants) are valid nodes. - * @throws {AssertionError} - * When `tree` (or its descendants) is not a node. - */ -export function assert(tree, parent) { - return wrap(assertNode)(tree, parent) -} - -/** - * Assert that `tree` is a valid unist parent. - * - * All children will be asserted too. - * - * @param {unknown} [tree] - * Thing to assert. - * @param {Parent | null | undefined} [parent] - * Optional, valid parent. - * @returns {asserts tree is Parent} - * Whether `tree` is a parent and its descendants are valid nodes. - * @throws {AssertionError} - * When `tree` is not a parent or its descendants are not nodes. - */ -export function parent(tree, parent) { - return wrap(assertParent)(tree, parent) -} - -/** - * Assert that `node` is a valid unist literal. - * - * @param {unknown} [node] - * Thing to assert. - * @param {Parent | null | undefined} [parent] - * Optional, valid parent. - * @returns {asserts node is Literal} - * Whether `node` is a literal. - * @throws {AssertionError} - * When `node` is not a literal. - */ -export function literal(node, parent) { - return wrap(assertLiteral)(node, parent) -} - -/** - * Assert that `node` is a valid void node. - * - * @param {unknown} [node] - * Thing to assert. - * @param {Parent | null | undefined} [parent] - * Optional, valid parent. - * @returns {asserts node is _Void} - * Whether `node` is a node but neither parent nor literal. - * @throws {AssertionError} - * When `node` is not a node, a parent, or a literal. - */ -export function _void(node, parent) { - return wrap(assertVoid)(node, parent) -} - -// Identifier to check if a value is seen. -const ID = '__unist__' - -// List of specced properties. -const defined = new Set(['type', 'value', 'children', 'position']) - -/** - * Wrapper that adds the current node (and parent, if available) to error - * messages. - * - * @template {Node} T - * Node type. - * @param {(node?: any, parent?: Parent | null | undefined) => asserts node is T} fn - * Custom assertion. - * @returns {(node?: any, parent?: Parent | null | undefined) => asserts node is T} - * Assertion. - */ -export function wrap(fn) { - return wrapped - - /** - * @param {unknown} node - * Thing to check. - * @param {Parent | null | undefined} [parent] - * Optional, valid parent. - * @throws {AssertionError} - * Whether `node` is a node but neither parent nor literal. - * @returns {void} - * Nothing. - */ - function wrapped(node, parent) { - try { - fn(node, parent) - } catch (error) { - const exception = /** @type {SeenError} */ (error) - if (!own.call(exception, ID)) { - exception[ID] = true - exception.message += ': `' + view(node) + '`' - if (parent) exception.message += ' in `' + view(parent) + '`' - } - - throw error - } - } -} - -/** - * Assert that `node` is a valid unist parent. - * - * All children will be asserted too. - * - * @param {unknown} node - * Thing to assert. - * @returns {asserts node is Node} - * Whether `node` (and its descendants) are valid nodes. - * @throws {AssertionError} - * When `node` (or its descendants) is not a node. - */ -function assertNode(node) { - let index = -1 - - nodeAssert.ok( - node && typeof node === 'object' && !Array.isArray(node), - 'node should be an object' - ) - - nodeAssert.ok(own.call(node, 'type'), 'node should have a type') - nodeAssert.strictEqual( - // @ts-expect-error Looks like an indexed object. - typeof node.type, - 'string', - '`type` should be a string' - ) - // @ts-expect-error Looks like an indexed object. - nodeAssert.notStrictEqual(node.type, '', '`type` should not be empty') - - // @ts-expect-error Looks like an indexed object. - if (node.value !== null && node.value !== undefined) { - nodeAssert.strictEqual( - // @ts-expect-error Looks like an indexed object. - typeof node.value, - 'string', - '`value` should be a string' - ) - } - - // @ts-expect-error Looks like an indexed object. - position(node.position) - - /** @type {string} */ - let key - - for (key in node) { - if (!defined.has(key)) { - /** @type {unknown} */ - // @ts-expect-error: hush. - const value = node[key] - vanilla(key, value) - } - } - - // @ts-expect-error Looks like an indexed object. - if (node.children !== null && node.children !== undefined) { - /** @type {Parent} */ - // @ts-expect-error Looks like parent. - const parent = node - nodeAssert.ok( - Array.isArray(parent.children), - '`children` should be an array' - ) - index = -1 - - while (++index < parent.children.length) { - assert(parent.children[index], parent) - } - } -} - -/** - * Assert `value` (which lives at `key`) can be stringified and re-parsed to the - * same (deep) value. - * - * @param {string} key - * Name of field. - * @param {unknown} value - * Value of field. - */ -function vanilla(key, value) { - try { - nodeAssert.deepStrictEqual(value, JSON.parse(JSON.stringify(value))) - } catch { - nodeAssert.fail('non-specced property `' + key + '` should be JSON') - } -} - -/** - * Stringify a value to inspect it. - * - * Tries `JSON.stringify()`, and if that fails uses `String()` instead. - * - * @param {unknown} value - * Anything (should be JSON). - * @returns {string} - * User-visible preresentation. - */ -function view(value) { - try { - return inspect(value) - /* c8 ignore next 3 */ - } catch { - return String(value) - } -} - -/** - * Assert that `node` is a valid unist parent. - * - * All children will be asserted too. - * - * @param {Node} node - * Thing to assert. - * @returns {asserts node is Parent} - * Whether `node` is a parent and its descendants are valid nodes. - * @throws {AssertionError} - * When `node` is not a parent or its descendants are not nodes. - */ -function assertParent(node) { - assertNode(node) - - nodeAssert.strictEqual( - 'value' in node, - false, - 'parent should not have `value`' - ) - nodeAssert.ok('children' in node, 'parent should have `children`') -} - -/** - * Assert that `node` is a valid unist literal. - * - * @param {unknown} [node] - * Thing to assert. - * @returns {asserts node is Literal} - * Whether `node` is a literal. - * @throws {AssertionError} - * When `node` is not a literal. - */ -function assertLiteral(node) { - assertNode(node) - - nodeAssert.strictEqual( - 'children' in node, - false, - 'literal should not have `children`' - ) - nodeAssert.ok('value' in node, 'literal should have `value`') -} - -/** - * Assert that `node` is a valid void node. - * - * @param {unknown} [node] - * Thing to assert. - * @returns {asserts node is _Void} - * Whether `node` is a node but neither parent nor literal. - * @throws {AssertionError} - * When `node` is not a node, a parent, or a literal. - */ -function assertVoid(node) { - assertNode(node) - - nodeAssert.strictEqual('value' in node, false, 'void should not have `value`') - nodeAssert.strictEqual( - 'children' in node, - false, - 'void should not have `children`' - ) -} - -/** - * Assert that `position` is a unist position. - * - * @param {unknown} position - * Thing to assert. - * @returns {asserts position is Position} - * Whether `position` is a unist position. - * @throws {AssertionError} - * When `position` is not a position. - */ -function position(position) { - if (position !== null && position !== undefined) { - nodeAssert.ok( - typeof position === 'object' && position === Object(position), - '`position` should be an object' - ) - - // @ts-expect-error: indexable. - point(position.start, 'position.start') - // @ts-expect-error: indexable. - point(position.end, 'position.end') - } -} - -/** - * Assert `point` is a unist point. - * - * @param {unknown} point - * Thing to assert. - * @param {string} label - * Whether `point` is a unist point. - * @returns {asserts point is Point} - * When `point` is not a point. - */ -function point(point, label) { - if (point !== null && point !== undefined) { - nodeAssert.ok( - typeof point === 'object' && point === Object(point), - '`' + label + '` should be an object' - ) - - if ('line' in point && point.line !== null && point.line !== undefined) { - nodeAssert.ok( - typeof point.line === 'number', - '`' + label + '` should have numeric `line`' - ) - nodeAssert.ok(point.line >= 1, '`' + label + '.line` should be gte `1`') - } - - if ( - 'column' in point && - point.column !== null && - point.column !== undefined - ) { - nodeAssert.ok( - typeof point.column === 'number', - '`' + label + '` should have numeric `column`' - ) - nodeAssert.ok( - point.column >= 1, - '`' + label + '.column` should be gte `1`' - ) - } - } -} +export {_void, assert, literal, parent, wrap} from './lib/index.js' diff --git a/index.test-d.ts b/index.test-d.ts index e9f0264..e1b4525 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,5 +1,5 @@ import {expectType, expectNotType} from 'tsd' -import {type Node, type Parent} from 'unist' +import type {Node, Parent} from 'unist' import {assert, parent} from './index.js' const emptyNode = {type: 'a'} diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..97b793a --- /dev/null +++ b/lib/index.js @@ -0,0 +1,372 @@ +/** + * @typedef {import('assert').AssertionError} AssertionError + * @typedef {import('unist').Node} Node + * @typedef {import('unist').Parent} Parent + * @typedef {import('unist').Literal} Literal + * @typedef {import('unist').Position} Position + * @typedef {import('unist').Point} Point + * @typedef {Node & {children: never, value: never}} _Void + * + * @typedef SeenErrorFields + * @property {true} [__unist__] + * + * @typedef {Error & SeenErrorFields} SeenError + */ + +import nodeAssert from 'node:assert' +import {inspect} from './inspect.js' + +const own = {}.hasOwnProperty + +/** + * Assert that `tree` is a valid unist node. + * + * If `node` is a parent, all children will be asserted too. + * + * @param {unknown} [tree] + * Thing to assert. + * @param {Parent | null | undefined} [parent] + * Optional, valid parent. + * @returns {asserts tree is Node} + * Whether `tree` (and its descendants) are valid nodes. + * @throws {AssertionError} + * When `tree` (or its descendants) is not a node. + */ +export function assert(tree, parent) { + return wrap(assertNode)(tree, parent) +} + +/** + * Assert that `tree` is a valid unist parent. + * + * All children will be asserted too. + * + * @param {unknown} [tree] + * Thing to assert. + * @param {Parent | null | undefined} [parent] + * Optional, valid parent. + * @returns {asserts tree is Parent} + * Whether `tree` is a parent and its descendants are valid nodes. + * @throws {AssertionError} + * When `tree` is not a parent or its descendants are not nodes. + */ +export function parent(tree, parent) { + return wrap(assertParent)(tree, parent) +} + +/** + * Assert that `node` is a valid unist literal. + * + * @param {unknown} [node] + * Thing to assert. + * @param {Parent | null | undefined} [parent] + * Optional, valid parent. + * @returns {asserts node is Literal} + * Whether `node` is a literal. + * @throws {AssertionError} + * When `node` is not a literal. + */ +export function literal(node, parent) { + return wrap(assertLiteral)(node, parent) +} + +/** + * Assert that `node` is a valid void node. + * + * @param {unknown} [node] + * Thing to assert. + * @param {Parent | null | undefined} [parent] + * Optional, valid parent. + * @returns {asserts node is _Void} + * Whether `node` is a node but neither parent nor literal. + * @throws {AssertionError} + * When `node` is not a node, a parent, or a literal. + */ +export function _void(node, parent) { + return wrap(assertVoid)(node, parent) +} + +// Identifier to check if a value is seen. +const ID = '__unist__' + +// List of specced properties. +const defined = new Set(['type', 'value', 'children', 'position']) + +/** + * Wrapper that adds the current node (and parent, if available) to error + * messages. + * + * @template {Node} T + * Node type. + * @param {(node?: any, parent?: Parent | null | undefined) => asserts node is T} fn + * Custom assertion. + * @returns {(node?: any, parent?: Parent | null | undefined) => asserts node is T} + * Assertion. + */ +export function wrap(fn) { + return wrapped + + /** + * @param {unknown} node + * Thing to check. + * @param {Parent | null | undefined} [parent] + * Optional, valid parent. + * @throws {AssertionError} + * Whether `node` is a node but neither parent nor literal. + * @returns {void} + * Nothing. + */ + function wrapped(node, parent) { + try { + fn(node, parent) + } catch (error) { + const exception = /** @type {SeenError} */ (error) + if (!own.call(exception, ID)) { + exception[ID] = true + exception.message += ': `' + view(node) + '`' + if (parent) exception.message += ' in `' + view(parent) + '`' + } + + throw error + } + } +} + +/** + * Assert that `node` is a valid unist parent. + * + * All children will be asserted too. + * + * @param {unknown} node + * Thing to assert. + * @returns {asserts node is Node} + * Whether `node` (and its descendants) are valid nodes. + * @throws {AssertionError} + * When `node` (or its descendants) is not a node. + */ +function assertNode(node) { + let index = -1 + + nodeAssert.ok( + node && typeof node === 'object' && !Array.isArray(node), + 'node should be an object' + ) + + nodeAssert.ok(own.call(node, 'type'), 'node should have a type') + nodeAssert.strictEqual( + // @ts-expect-error Looks like an indexed object. + typeof node.type, + 'string', + '`type` should be a string' + ) + // @ts-expect-error Looks like an indexed object. + nodeAssert.notStrictEqual(node.type, '', '`type` should not be empty') + + // @ts-expect-error Looks like an indexed object. + if (node.value !== null && node.value !== undefined) { + nodeAssert.strictEqual( + // @ts-expect-error Looks like an indexed object. + typeof node.value, + 'string', + '`value` should be a string' + ) + } + + // @ts-expect-error Looks like an indexed object. + position(node.position) + + /** @type {string} */ + let key + + for (key in node) { + if (!defined.has(key)) { + /** @type {unknown} */ + // @ts-expect-error: hush. + const value = node[key] + vanilla(key, value) + } + } + + // @ts-expect-error Looks like an indexed object. + if (node.children !== null && node.children !== undefined) { + /** @type {Parent} */ + // @ts-expect-error Looks like parent. + const parent = node + nodeAssert.ok( + Array.isArray(parent.children), + '`children` should be an array' + ) + index = -1 + + while (++index < parent.children.length) { + assert(parent.children[index], parent) + } + } +} + +/** + * Assert `value` (which lives at `key`) can be stringified and re-parsed to the + * same (deep) value. + * + * @param {string} key + * Name of field. + * @param {unknown} value + * Value of field. + */ +function vanilla(key, value) { + try { + nodeAssert.deepStrictEqual(value, JSON.parse(JSON.stringify(value))) + } catch { + nodeAssert.fail('non-specced property `' + key + '` should be JSON') + } +} + +/** + * Stringify a value to inspect it. + * + * Tries `JSON.stringify()`, and if that fails uses `String()` instead. + * + * @param {unknown} value + * Anything (should be JSON). + * @returns {string} + * User-visible preresentation. + */ +function view(value) { + try { + return inspect(value) + /* c8 ignore next 3 */ + } catch { + return String(value) + } +} + +/** + * Assert that `node` is a valid unist parent. + * + * All children will be asserted too. + * + * @param {Node} node + * Thing to assert. + * @returns {asserts node is Parent} + * Whether `node` is a parent and its descendants are valid nodes. + * @throws {AssertionError} + * When `node` is not a parent or its descendants are not nodes. + */ +function assertParent(node) { + assertNode(node) + + nodeAssert.strictEqual( + 'value' in node, + false, + 'parent should not have `value`' + ) + nodeAssert.ok('children' in node, 'parent should have `children`') +} + +/** + * Assert that `node` is a valid unist literal. + * + * @param {unknown} [node] + * Thing to assert. + * @returns {asserts node is Literal} + * Whether `node` is a literal. + * @throws {AssertionError} + * When `node` is not a literal. + */ +function assertLiteral(node) { + assertNode(node) + + nodeAssert.strictEqual( + 'children' in node, + false, + 'literal should not have `children`' + ) + nodeAssert.ok('value' in node, 'literal should have `value`') +} + +/** + * Assert that `node` is a valid void node. + * + * @param {unknown} [node] + * Thing to assert. + * @returns {asserts node is _Void} + * Whether `node` is a node but neither parent nor literal. + * @throws {AssertionError} + * When `node` is not a node, a parent, or a literal. + */ +function assertVoid(node) { + assertNode(node) + + nodeAssert.strictEqual('value' in node, false, 'void should not have `value`') + nodeAssert.strictEqual( + 'children' in node, + false, + 'void should not have `children`' + ) +} + +/** + * Assert that `position` is a unist position. + * + * @param {unknown} position + * Thing to assert. + * @returns {asserts position is Position} + * Whether `position` is a unist position. + * @throws {AssertionError} + * When `position` is not a position. + */ +function position(position) { + if (position !== null && position !== undefined) { + nodeAssert.ok( + typeof position === 'object' && position === Object(position), + '`position` should be an object' + ) + + // @ts-expect-error: indexable. + point(position.start, 'position.start') + // @ts-expect-error: indexable. + point(position.end, 'position.end') + } +} + +/** + * Assert `point` is a unist point. + * + * @param {unknown} point + * Thing to assert. + * @param {string} label + * Whether `point` is a unist point. + * @returns {asserts point is Point} + * When `point` is not a point. + */ +function point(point, label) { + if (point !== null && point !== undefined) { + nodeAssert.ok( + typeof point === 'object' && point === Object(point), + '`' + label + '` should be an object' + ) + + if ('line' in point && point.line !== null && point.line !== undefined) { + nodeAssert.ok( + typeof point.line === 'number', + '`' + label + '` should have numeric `line`' + ) + nodeAssert.ok(point.line >= 1, '`' + label + '.line` should be gte `1`') + } + + if ( + 'column' in point && + point.column !== null && + point.column !== undefined + ) { + nodeAssert.ok( + typeof point.column === 'number', + '`' + label + '` should have numeric `column`' + ) + nodeAssert.ok( + point.column >= 1, + '`' + label + '.column` should be gte `1`' + ) + } + } +} diff --git a/inspect.browser.js b/lib/inspect.browser.js similarity index 100% rename from inspect.browser.js rename to lib/inspect.browser.js diff --git a/inspect.js b/lib/inspect.js similarity index 100% rename from inspect.js rename to lib/inspect.js diff --git a/package.json b/package.json index 040af2a..e5c8271 100644 --- a/package.json +++ b/package.json @@ -26,19 +26,16 @@ "type": "module", "main": "index.js", "browser": { - "./inspect.js": "./inspect.browser.js" + "./lib/inspect.js": "./lib/inspect.browser.js" }, "react-native": { - "./inspect.js": "./inspect.browser.js" + "./lib/inspect.js": "./lib/inspect.browser.js" }, "types": "index.d.ts", "files": [ + "lib/", "index.d.ts", - "index.js", - "inspect.d.ts", - "inspect.js", - "inspect.browser.d.ts", - "inspect.browser.js" + "index.js" ], "dependencies": { "@types/unist": "^2.0.0" @@ -85,7 +82,7 @@ "ignoreCatch": true, "#": "Couple of needed any’s", "ignoreFiles": [ - "index.d.ts" + "lib/index.d.ts" ] } } diff --git a/readme.md b/readme.md index a4d157a..ec2e9d8 100644 --- a/readme.md +++ b/readme.md @@ -141,7 +141,7 @@ message. ## Types This package is fully typed with [TypeScript][]. -It does not export additional types. +It exports the additional type `AssertionError`. ## Compatibility From fbb5ebbe6c06027082fd8991c2b71950d7537314 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 6 Jan 2023 18:28:49 +0100 Subject: [PATCH 73/85] Add tests for exposed identifiers --- test/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/index.js b/test/index.js index 63a1f69..4f863a5 100644 --- a/test/index.js +++ b/test/index.js @@ -9,3 +9,15 @@ import './parent.js' import './literal.js' import './void.js' /* eslint-enable import/no-unassigned-import */ + +import assert from 'node:assert/strict' +import test from 'node:test' +import * as mod from '../index.js' + +test('assert', () => { + assert.deepEqual( + Object.keys(mod).sort(), + ['_void', 'assert', 'literal', 'parent', 'wrap'], + 'should expose the public api' + ) +}) From 61a3eedc6f35d536bd5fdbb6af76a539f84e6854 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 6 Jan 2023 18:40:34 +0100 Subject: [PATCH 74/85] Add improved docs --- lib/index.js | 28 +++++++----- readme.md | 121 +++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 119 insertions(+), 30 deletions(-) diff --git a/lib/index.js b/lib/index.js index 97b793a..dbdcd71 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,5 +1,7 @@ /** * @typedef {import('assert').AssertionError} AssertionError + * Assertion error from `node:assert`. + * * @typedef {import('unist').Node} Node * @typedef {import('unist').Parent} Parent * @typedef {import('unist').Literal} Literal @@ -21,14 +23,14 @@ const own = {}.hasOwnProperty /** * Assert that `tree` is a valid unist node. * - * If `node` is a parent, all children will be asserted too. + * If `tree` is a parent, all children will be asserted too. * * @param {unknown} [tree] * Thing to assert. * @param {Parent | null | undefined} [parent] * Optional, valid parent. * @returns {asserts tree is Node} - * Whether `tree` (and its descendants) are valid nodes. + * Nothing. * @throws {AssertionError} * When `tree` (or its descendants) is not a node. */ @@ -46,7 +48,7 @@ export function assert(tree, parent) { * @param {Parent | null | undefined} [parent] * Optional, valid parent. * @returns {asserts tree is Parent} - * Whether `tree` is a parent and its descendants are valid nodes. + * Nothing. * @throws {AssertionError} * When `tree` is not a parent or its descendants are not nodes. */ @@ -62,7 +64,7 @@ export function parent(tree, parent) { * @param {Parent | null | undefined} [parent] * Optional, valid parent. * @returns {asserts node is Literal} - * Whether `node` is a literal. + * Nothing. * @throws {AssertionError} * When `node` is not a literal. */ @@ -78,7 +80,7 @@ export function literal(node, parent) { * @param {Parent | null | undefined} [parent] * Optional, valid parent. * @returns {asserts node is _Void} - * Whether `node` is a node but neither parent nor literal. + * Nothing. * @throws {AssertionError} * When `node` is not a node, a parent, or a literal. */ @@ -140,7 +142,7 @@ export function wrap(fn) { * @param {unknown} node * Thing to assert. * @returns {asserts node is Node} - * Whether `node` (and its descendants) are valid nodes. + * Nothing. * @throws {AssertionError} * When `node` (or its descendants) is not a node. */ @@ -248,7 +250,7 @@ function view(value) { * @param {Node} node * Thing to assert. * @returns {asserts node is Parent} - * Whether `node` is a parent and its descendants are valid nodes. + * Nothing. * @throws {AssertionError} * When `node` is not a parent or its descendants are not nodes. */ @@ -269,7 +271,7 @@ function assertParent(node) { * @param {unknown} [node] * Thing to assert. * @returns {asserts node is Literal} - * Whether `node` is a literal. + * Nothing. * @throws {AssertionError} * When `node` is not a literal. */ @@ -290,7 +292,7 @@ function assertLiteral(node) { * @param {unknown} [node] * Thing to assert. * @returns {asserts node is _Void} - * Whether `node` is a node but neither parent nor literal. + * Nothing. * @throws {AssertionError} * When `node` is not a node, a parent, or a literal. */ @@ -311,7 +313,7 @@ function assertVoid(node) { * @param {unknown} position * Thing to assert. * @returns {asserts position is Position} - * Whether `position` is a unist position. + * Nothing. * @throws {AssertionError} * When `position` is not a position. */ @@ -335,9 +337,11 @@ function position(position) { * @param {unknown} point * Thing to assert. * @param {string} label - * Whether `point` is a unist point. + * `start` or `end` * @returns {asserts point is Point} - * When `point` is not a point. + * Nothing. + * @throws {AssertionError} + * When `point` is not a position. */ function point(point, label) { if (point !== null && point !== undefined) { diff --git a/readme.md b/readme.md index ec2e9d8..384f48b 100644 --- a/readme.md +++ b/readme.md @@ -22,6 +22,7 @@ * [`literal(node[, parent])`](#literalnode-parent) * [`_void(node[, parent])`](#_voidnode-parent) * [`wrap(fn)`](#wrapfn) + * [`AssertionError`](#assertionerror) * [Extensions](#extensions) * [Types](#types) * [Compatibility](#compatibility) @@ -45,7 +46,7 @@ do the same but for mdast, hast, and nlcst nodes, respectively. ## Install This package is [ESM only][esm]. -In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [npm][]: +In Node.js (version 14.14+ and 16.0+), install with [npm][]: ```sh npm install unist-util-assert @@ -93,41 +94,113 @@ assert({type: 'paragraph', children: ['foo']}) ## API -This package exports the identifiers `assert`, `parent`, `literal`, `_void`, -and `wrap`. +This package exports the identifiers [`_void`][void], [`assert`][assert], +[`literal`][literal], [`parent`][parent], and [`wrap`][wrap]. There is no default export. ### `assert(tree[, parent])` Assert that `tree` is a valid unist [`Node`][node]. -If `tree` is a [parent][], all children will be asserted as well. +If `tree` is a parent, all children will be asserted too. + +###### Parameters + +* `tree` (`unknown`) + — thing to assert +* `parent` ([`Parent`][parent-node], optional) + — optional, valid parent + +###### Returns + +Nothing. ###### Throws -When `node`, or one of its children, is not a valid node. +When `tree` (or its descendants) is not a node. ### `parent(tree[, parent])` -Assert that `tree` is a valid unist [`Parent`][parent]. +Assert that `tree` is a valid unist [`Parent`][parent-node]. + +All children will be asserted too. + +###### Parameters + +* `tree` (`unknown`) + — thing to assert +* `parent` ([`Parent`][parent-node], optional) + — optional, valid parent + +###### Returns + +Nothing. + +###### Throws -All children will be asserted as well. +When `tree` is not a parent or its descendants are not nodes. ### `literal(node[, parent])` -Assert that `node` is a valid unist [`Literal`][literal]. +Assert that `node` is a valid unist [`Literal`][literal-node]. + +###### Parameters + +* `tree` (`unknown`) + — thing to assert +* `parent` ([`Parent`][parent-node], optional) + — optional, valid parent + +###### Returns + +Nothing. + +###### Throws + +When `node` is not a literal. ### `_void(node[, parent])` -Assert that `node` is a valid unist [`Node`][node], but neither -[`Parent`][parent] nor -[`Literal`][literal]. +Assert that `node` is a valid void node. + +###### Parameters + +* `tree` (`unknown`) + — thing to assert +* `parent` ([`Parent`][parent-node], optional) + — optional, valid parent + +###### Returns + +Nothing. + +###### Throws + +When `node` is not a node, a parent, or a literal. ### `wrap(fn)` -Wraps `fn` (which is passed a node, and an optional parent node), so that any -errors thrown inside it will contain information regarding the node (and the -parent, when given). +Wrapper that adds the current node (and parent, if available) to error +messages. + +###### Parameters + +* `fn` (`(node?: any, parent?: Parent | null | undefined) => asserts node is Node)`) + — custom assertion + +###### Returns + +Wrapped `fn`. + +### `AssertionError` + +Assertion error from `node:assert` (TypeScript type). + +###### Type + +```ts +type AssertionError = import('node:assert').AssertionError +``` ## Extensions @@ -141,13 +214,13 @@ message. ## Types This package is fully typed with [TypeScript][]. -It exports the additional type `AssertionError`. +It exports the additional type [`AssertionError`][assertionerror]. ## Compatibility Projects maintained by the unified collective are compatible with all maintained versions of Node.js. -As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+. +As of now, that is Node.js 14.14+ and 16.0+. Our projects sometimes work with older versions, but this is not guaranteed. ## Related @@ -225,12 +298,24 @@ abide by its terms. [node]: https://github.com/syntax-tree/unist#node -[parent]: https://github.com/syntax-tree/unist#parent +[parent-node]: https://github.com/syntax-tree/unist#parent -[literal]: https://github.com/syntax-tree/unist#literal +[literal-node]: https://github.com/syntax-tree/unist#literal [mdast-util-assert]: https://github.com/syntax-tree/mdast-util-assert [hast-util-assert]: https://github.com/syntax-tree/hast-util-assert [nlcst-test]: https://github.com/syntax-tree/nlcst-test + +[assert]: #asserttree-parent + +[parent]: #parenttree-parent + +[literal]: #literalnode-parent + +[void]: #_voidnode-parent + +[wrap]: #wrapfn + +[assertionerror]: #assertionerror From 4e06127cc7180d6fbe789ec0f9005aec6b9acf76 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 6 Jan 2023 18:42:12 +0100 Subject: [PATCH 75/85] 3.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e5c8271..9ecb287 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unist-util-assert", - "version": "3.0.1", + "version": "3.0.2", "description": "unist utility to assert nodes", "license": "MIT", "keywords": [ From 4c74f03f685e964ba57c2ac1973b4b646557f6ae Mon Sep 17 00:00:00 2001 From: Titus Date: Mon, 16 Jan 2023 16:28:15 +0100 Subject: [PATCH 76/85] Use Node 16 in Actions Signed-off-by: Titus --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ee318ca..fb63387 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,5 +17,5 @@ jobs: strategy: matrix: node: - - lts/hydrogen + - lts/gallium - node From 57378999cb8a20570c0157c9d65b2cb56c7e0e2b Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 29 Jun 2023 13:36:32 +0200 Subject: [PATCH 77/85] Update dev-dependencies --- package.json | 10 +++++----- test/core.js | 11 +++++++++++ test/index.js | 13 +------------ 3 files changed, 17 insertions(+), 17 deletions(-) create mode 100644 test/core.js diff --git a/package.json b/package.json index 9ecb287..7b9d7b4 100644 --- a/package.json +++ b/package.json @@ -41,15 +41,15 @@ "@types/unist": "^2.0.0" }, "devDependencies": { - "@types/node": "^18.0.0", - "c8": "^7.0.0", + "@types/node": "^20.0.0", + "c8": "^8.0.0", "prettier": "^2.0.0", "remark-cli": "^11.0.0", "remark-preset-wooorm": "^9.0.0", - "tsd": "^0.25.0", + "tsd": "^0.28.0", "type-coverage": "^2.0.0", - "typescript": "^4.0.0", - "xo": "^0.53.0" + "typescript": "^5.0.0", + "xo": "^0.54.0" }, "scripts": { "prepack": "npm run build && npm run format", diff --git a/test/core.js b/test/core.js new file mode 100644 index 0000000..b7682d5 --- /dev/null +++ b/test/core.js @@ -0,0 +1,11 @@ +import assert from 'node:assert/strict' +import test from 'node:test' +import * as mod from '../index.js' + +test('assert', () => { + assert.deepEqual( + Object.keys(mod).sort(), + ['_void', 'assert', 'literal', 'parent', 'wrap'], + 'should expose the public api' + ) +}) diff --git a/test/index.js b/test/index.js index 4f863a5..d2e8419 100644 --- a/test/index.js +++ b/test/index.js @@ -1,4 +1,5 @@ /* eslint-disable import/no-unassigned-import */ +import './core.js' import './node.js' import './type.js' import './value.js' @@ -9,15 +10,3 @@ import './parent.js' import './literal.js' import './void.js' /* eslint-enable import/no-unassigned-import */ - -import assert from 'node:assert/strict' -import test from 'node:test' -import * as mod from '../index.js' - -test('assert', () => { - assert.deepEqual( - Object.keys(mod).sort(), - ['_void', 'assert', 'literal', 'parent', 'wrap'], - 'should expose the public api' - ) -}) From e429ed80c73ccdb1e5261b982fe876995ce99e69 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 29 Jun 2023 13:37:26 +0200 Subject: [PATCH 78/85] Refactor `package.json`, `tsconfig.json` --- package.json | 24 ++++++++++++------------ tsconfig.json | 10 ++++------ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 7b9d7b4..7f6631d 100644 --- a/package.json +++ b/package.json @@ -56,33 +56,33 @@ "build": "tsc --build --clean && tsc --build && tsd && type-coverage", "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", "test-api": "node --conditions development test/index.js", - "test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api", + "test-coverage": "c8 --100 --reporter lcov npm run test-api", "test": "npm run build && npm run format && npm run test-coverage" }, "prettier": { - "tabWidth": 2, - "useTabs": false, - "singleQuote": true, "bracketSpacing": false, "semi": false, - "trailingComma": "none" - }, - "xo": { - "prettier": true + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false }, "remarkConfig": { "plugins": [ - "preset-wooorm" + "remark-preset-wooorm" ] }, "typeCoverage": { "atLeast": 100, "detail": true, - "strict": true, "ignoreCatch": true, - "#": "Couple of needed any’s", + "#": "Couple of needed any’s", "ignoreFiles": [ "lib/index.d.ts" - ] + ], + "strict": true + }, + "xo": { + "prettier": true } } diff --git a/tsconfig.json b/tsconfig.json index 1bc9e99..870d82c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,17 +1,15 @@ { - "include": ["**/**.js"], - "exclude": ["coverage/", "node_modules/"], "compilerOptions": { "checkJs": true, + "customConditions": ["development"], "declaration": true, "emitDeclarationOnly": true, "exactOptionalPropertyTypes": true, - "forceConsistentCasingInFileNames": true, "lib": ["es2020"], "module": "node16", - "newLine": "lf", - "skipLibCheck": true, "strict": true, "target": "es2020" - } + }, + "exclude": ["coverage/", "node_modules/"], + "include": ["**/*.js"] } From d9ff3b86e7edc26bce778a4035fa27d1ce605149 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 29 Jun 2023 14:04:11 +0200 Subject: [PATCH 79/85] Refactor code-style --- index.test-d.ts | 2 +- lib/index.js | 55 +++++++--- package.json | 10 ++ readme.md | 2 +- test/children.js | 46 +++++---- test/core.js | 17 +-- test/index.js | 12 +-- test/literal.js | 46 +++++---- test/node.js | 42 +++----- test/non-defined.js | 54 +++++----- test/parent.js | 46 +++++---- test/position.js | 247 +++++++++++++++++++++++++++----------------- test/type.js | 56 +++++----- test/value.js | 53 ++++++---- test/void.js | 46 +++++---- 15 files changed, 422 insertions(+), 312 deletions(-) diff --git a/index.test-d.ts b/index.test-d.ts index e1b4525..4802246 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,4 +1,4 @@ -import {expectType, expectNotType} from 'tsd' +import {expectNotType, expectType} from 'tsd' import type {Node, Parent} from 'unist' import {assert, parent} from './index.js' diff --git a/lib/index.js b/lib/index.js index dbdcd71..ba2ce1a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,12 +1,22 @@ /** - * @typedef {import('assert').AssertionError} AssertionError - * Assertion error from `node:assert`. + * @typedef {import('node:assert').AssertionError} AssertionError * + * @typedef {import('unist').Literal} Literal * @typedef {import('unist').Node} Node * @typedef {import('unist').Parent} Parent - * @typedef {import('unist').Literal} Literal - * @typedef {import('unist').Position} Position * @typedef {import('unist').Point} Point + * @typedef {import('unist').Position} Position + */ + +/** + * @template T + * @callback CustomAssertion + * @param {any} [node] + * @param {Parent | null | undefined} [parent] + * @returns {asserts node is T} + */ + +/** * @typedef {Node & {children: never, value: never}} _Void * * @typedef SeenErrorFields @@ -100,9 +110,9 @@ const defined = new Set(['type', 'value', 'children', 'position']) * * @template {Node} T * Node type. - * @param {(node?: any, parent?: Parent | null | undefined) => asserts node is T} fn + * @param {CustomAssertion} fn * Custom assertion. - * @returns {(node?: any, parent?: Parent | null | undefined) => asserts node is T} + * @returns {CustomAssertion} * Assertion. */ export function wrap(fn) { @@ -115,7 +125,7 @@ export function wrap(fn) { * Optional, valid parent. * @throws {AssertionError} * Whether `node` is a node but neither parent nor literal. - * @returns {void} + * @returns {undefined} * Nothing. */ function wrapped(node, parent) { @@ -153,28 +163,24 @@ function assertNode(node) { node && typeof node === 'object' && !Array.isArray(node), 'node should be an object' ) + indexable(node) nodeAssert.ok(own.call(node, 'type'), 'node should have a type') nodeAssert.strictEqual( - // @ts-expect-error Looks like an indexed object. typeof node.type, 'string', '`type` should be a string' ) - // @ts-expect-error Looks like an indexed object. nodeAssert.notStrictEqual(node.type, '', '`type` should not be empty') - // @ts-expect-error Looks like an indexed object. if (node.value !== null && node.value !== undefined) { nodeAssert.strictEqual( - // @ts-expect-error Looks like an indexed object. typeof node.value, 'string', '`value` should be a string' ) } - // @ts-expect-error Looks like an indexed object. position(node.position) /** @type {string} */ @@ -182,14 +188,11 @@ function assertNode(node) { for (key in node) { if (!defined.has(key)) { - /** @type {unknown} */ - // @ts-expect-error: hush. const value = node[key] vanilla(key, value) } } - // @ts-expect-error Looks like an indexed object. if (node.children !== null && node.children !== undefined) { /** @type {Parent} */ // @ts-expect-error Looks like parent. @@ -324,9 +327,8 @@ function position(position) { '`position` should be an object' ) - // @ts-expect-error: indexable. + indexable(position) point(position.start, 'position.start') - // @ts-expect-error: indexable. point(position.end, 'position.end') } } @@ -374,3 +376,22 @@ function point(point, label) { } } } + +/** + * TypeScript helper to check if something is indexable (any object is + * indexable in JavaScript). + * + * @param {unknown} value + * Thing to check. + * @returns {asserts value is Record} + * Nothing. + * @throws {Error} + * When `value` is not an object. + */ +function indexable(value) { + // Always called when something is an object, this is just for TS. + /* c8 ignore next 3 */ + if (!value || typeof value !== 'object') { + throw new Error('Expected object') + } +} diff --git a/package.json b/package.json index 7f6631d..e269b38 100644 --- a/package.json +++ b/package.json @@ -83,6 +83,16 @@ "strict": true }, "xo": { + "overrides": [ + { + "files": [ + "test/**/*.js" + ], + "rules": { + "import/no-unassigned-import": "off" + } + } + ], "prettier": true } } diff --git a/readme.md b/readme.md index 384f48b..c98754d 100644 --- a/readme.md +++ b/readme.md @@ -69,7 +69,7 @@ In browsers with [`esm.sh`][esmsh]: ## Use ```js -import {assert, parent, _void} from 'unist-util-assert' +import {_void, assert, parent} from 'unist-util-assert' assert({type: 'root', children: []}) assert({type: 'break'}) diff --git a/test/children.js b/test/children.js index 6a8e27c..29ea1ce 100644 --- a/test/children.js +++ b/test/children.js @@ -2,29 +2,33 @@ import nodeAssert from 'node:assert/strict' import test from 'node:test' import {assert} from '../index.js' -test('children', () => { - nodeAssert.throws( - () => { - assert({type: 'foo', children: {alpha: 'bravo'}}) - }, - /`children` should be an array: `{ type: 'foo', children: { alpha: 'bravo' } }`$/, - 'should throw if given a non-node child in children' +test('children', async function (t) { + await t.test( + 'should throw if given a non-node child in children', + async function () { + nodeAssert.throws(function () { + assert({type: 'foo', children: {alpha: 'bravo'}}) + }, /`children` should be an array: `{ type: 'foo', children: { alpha: 'bravo' } }`$/) + } ) - nodeAssert.throws( - () => { - assert({type: 'foo', children: ['one']}) - }, - /node should be an object: `'one'` in `{ type: 'foo', children: \[ 'one' ] }`$/, - 'should throw if given a non-node child in children' + await t.test( + 'should throw if given a non-node child in children', + async function () { + nodeAssert.throws(function () { + assert({type: 'foo', children: ['one']}) + }, /node should be an object: `'one'` in `{ type: 'foo', children: \[ 'one' ] }`$/) + } ) - nodeAssert.doesNotThrow(() => { - assert({type: 'parent', children: [{type: 'text', value: 'alpha'}]}) - }, 'should not throw on vald children') + await t.test('should not throw on vald children', async function () { + nodeAssert.doesNotThrow(function () { + assert({type: 'parent', children: [{type: 'text', value: 'alpha'}]}) + }) + }) - nodeAssert.throws( - () => { + await t.test('should throw on invalid descendants', async function () { + nodeAssert.throws(function () { assert({ type: 'foo', children: [ @@ -34,8 +38,6 @@ test('children', () => { } ] }) - }, - /node should be an object: `'one'` in `{ type: 'bar', children: \[ 'one' ] }`$/, - 'should throw on invalid descendants' - ) + }, /node should be an object: `'one'` in `{ type: 'bar', children: \[ 'one' ] }`$/) + }) }) diff --git a/test/core.js b/test/core.js index b7682d5..98d8e3a 100644 --- a/test/core.js +++ b/test/core.js @@ -1,11 +1,14 @@ import assert from 'node:assert/strict' import test from 'node:test' -import * as mod from '../index.js' -test('assert', () => { - assert.deepEqual( - Object.keys(mod).sort(), - ['_void', 'assert', 'literal', 'parent', 'wrap'], - 'should expose the public api' - ) +test('assert', async function (t) { + await t.test('should expose the public api', async function () { + assert.deepEqual(Object.keys(await import('../index.js')).sort(), [ + '_void', + 'assert', + 'literal', + 'parent', + 'wrap' + ]) + }) }) diff --git a/test/index.js b/test/index.js index d2e8419..c9ea1b8 100644 --- a/test/index.js +++ b/test/index.js @@ -1,12 +1,10 @@ -/* eslint-disable import/no-unassigned-import */ +import './children.js' import './core.js' +import './literal.js' import './node.js' -import './type.js' -import './value.js' -import './children.js' -import './position.js' import './non-defined.js' import './parent.js' -import './literal.js' +import './position.js' +import './type.js' +import './value.js' import './void.js' -/* eslint-enable import/no-unassigned-import */ diff --git a/test/literal.js b/test/literal.js index b0c11fd..14f32e4 100644 --- a/test/literal.js +++ b/test/literal.js @@ -2,32 +2,34 @@ import assert from 'node:assert/strict' import test from 'node:test' import {literal} from '../index.js' -test('literal()', () => { - assert.throws( - () => { +test('literal()', async function (t) { + await t.test('should throw the same errors as `assert()`', async function () { + assert.throws(function () { literal({}) - }, - /node should have a type: `{}`$/, - 'should throw the same errors as `assert()`' - ) + }, /node should have a type: `{}`$/) + }) - assert.throws( - () => { - literal({type: 'strong', children: []}) - }, - /literal should not have `children`: `{ type: 'strong', children: \[] }`$/, - 'should throw if the given node has `children`' + await t.test( + 'should throw if the given node has `children`', + async function () { + assert.throws(function () { + literal({type: 'strong', children: []}) + }, /literal should not have `children`: `{ type: 'strong', children: \[] }`$/) + } ) - assert.throws( - () => { - literal({type: 'break'}) - }, - /literal should have `value`: `{ type: 'break' }`$/, - 'should throw if the given node has no `value`' + await t.test( + 'should throw if the given node has no `value`', + async function () { + assert.throws(function () { + literal({type: 'break'}) + }, /literal should have `value`: `{ type: 'break' }`$/) + } ) - assert.doesNotThrow(() => { - literal({type: 'text', value: 'foo'}) - }, 'should not throw on valid text nodes') + await t.test('should not throw on valid text nodes', async function () { + assert.doesNotThrow(function () { + literal({type: 'text', value: 'foo'}) + }) + }) }) diff --git a/test/node.js b/test/node.js index f9da6d6..c1bba41 100644 --- a/test/node.js +++ b/test/node.js @@ -2,36 +2,28 @@ import nodeAssert from 'node:assert/strict' import test from 'node:test' import {assert} from '../index.js' -test('node', () => { - nodeAssert.throws( - () => { +test('node', async function (t) { + await t.test('should throw if not given a node (#1)', async function () { + nodeAssert.throws(function () { assert() - }, - /node should be an object: `undefined`$/, - 'should throw if not given a node (#1)' - ) + }, /node should be an object: `undefined`$/) + }) - nodeAssert.throws( - () => { + await t.test('should throw if not given a node (#2)', async function () { + nodeAssert.throws(function () { assert(null) - }, - /node should be an object: `null`$/, - 'should throw if not given a node (#2)' - ) + }, /node should be an object: `null`$/) + }) - nodeAssert.throws( - () => { + await t.test('should throw if given a non-node (#1)', async function () { + nodeAssert.throws(function () { assert('foo') - }, - /node should be an object: `'foo'`$/, - 'should throw if given a non-node (#1)' - ) + }, /node should be an object: `'foo'`$/) + }) - nodeAssert.throws( - () => { + await t.test('should throw if not given a non-node (#2)', async function () { + nodeAssert.throws(function () { assert(6) - }, - /node should be an object: `6`$/, - 'should throw if not given a non-node (#2)' - ) + }, /node should be an object: `6`$/) + }) }) diff --git a/test/non-defined.js b/test/non-defined.js index abe7431..d5c11e3 100644 --- a/test/non-defined.js +++ b/test/non-defined.js @@ -2,30 +2,36 @@ import nodeAssert from 'node:assert/strict' import test from 'node:test' import {assert} from '../index.js' -test('non-defined', () => { - nodeAssert.doesNotThrow(() => { - assert({ - type: 'element', - properties: { - className: ['alpha'], - id: 'bravo' - }, - children: [], - position: {}, - data: { - charlie: 'delta' - } - }) - }, 'should not throw if non-defined properties are found') - - nodeAssert.throws( - () => { - assert({ - type: 'break', - data: {foo: Function} +test('non-defined', async function (t) { + await t.test( + 'should not throw if non-defined properties are found', + async function () { + nodeAssert.doesNotThrow(function () { + assert({ + type: 'element', + properties: { + className: ['alpha'], + id: 'bravo' + }, + children: [], + position: {}, + data: { + charlie: 'delta' + } + }) }) - }, - /non-specced property `data` should be JSON: `{ type: 'break', data: { foo: \[Function: Function] } }`$/, - 'should throw if non-defined properties are not serialisable' + } + ) + + await t.test( + 'should throw if non-defined properties are not serialisable', + async function () { + nodeAssert.throws(function () { + assert({ + type: 'break', + data: {foo: Function} + }) + }, /non-specced property `data` should be JSON: `{ type: 'break', data: { foo: \[Function: Function] } }`$/) + } ) }) diff --git a/test/parent.js b/test/parent.js index c247a19..416b0f9 100644 --- a/test/parent.js +++ b/test/parent.js @@ -2,32 +2,34 @@ import assert from 'node:assert/strict' import test from 'node:test' import {parent} from '../index.js' -test('parent()', () => { - assert.throws( - () => { +test('parent()', async function (t) { + await t.test('should throw the same errors as `assert()`', async function () { + assert.throws(function () { parent({}) - }, - /node should have a type: `{}`$/, - 'should throw the same errors as `assert()`' - ) + }, /node should have a type: `{}`$/) + }) - assert.throws( - () => { - parent({type: 'text', value: 'foo'}) - }, - /parent should not have `value`: `{ type: 'text', value: 'foo' }`$/, - 'should throw if the given node has a `value`' + await t.test( + 'should throw if the given node has a `value`', + async function () { + assert.throws(function () { + parent({type: 'text', value: 'foo'}) + }, /parent should not have `value`: `{ type: 'text', value: 'foo' }`$/) + } ) - assert.throws( - () => { - parent({type: 'break'}) - }, - /parent should have `children`: `{ type: 'break' }`$/, - 'should throw if the given node has `children`' + await t.test( + 'should throw if the given node has `children`', + async function () { + assert.throws(function () { + parent({type: 'break'}) + }, /parent should have `children`: `{ type: 'break' }`$/) + } ) - assert.doesNotThrow(() => { - parent({type: 'strong', children: []}) - }, 'should not throw on valid void nodes') + await t.test('should not throw on valid void nodes', async function () { + assert.doesNotThrow(function () { + parent({type: 'strong', children: []}) + }) + }) }) diff --git a/test/position.js b/test/position.js index 7c09655..73945da 100644 --- a/test/position.js +++ b/test/position.js @@ -2,100 +2,157 @@ import nodeAssert from 'node:assert/strict' import test from 'node:test' import {assert} from '../index.js' -test('position', () => { - nodeAssert.throws( - () => { - assert({type: 'foo', position: 1}) - }, - /`position` should be an object: `{ type: 'foo', position: 1 }`$/, - 'should throw if given a non-object `position`' - ) - - nodeAssert.doesNotThrow(() => { - assert({type: 'foo', position: null}) - }, 'should not throw if given a null `position`') - - nodeAssert.doesNotThrow(() => { - assert({type: 'foo', position: {}}) - }, 'should not throw if given an empty `position` object') - - nodeAssert.throws( - () => { - assert({type: 'foo', position: {start: 1}}) - }, - /`position.start` should be an object: `{ type: 'foo', position: { start: 1 } }`$/, - 'should throw if given a non-object `position.start`' - ) - - nodeAssert.doesNotThrow(() => { - assert({type: 'foo', position: {start: null}}) - }, 'should not throw if given a null `position.start`') - - nodeAssert.doesNotThrow(() => { - assert({type: 'foo', position: {start: {}}}) - }, 'should not throw if given an empty `position.start` object') - - nodeAssert.throws( - () => { - assert({type: 'foo', position: {end: 1}}) - }, - /`position.end` should be an object: `{ type: 'foo', position: { end: 1 } }`$/, - 'should throw if given a non-object `position.end`' - ) - - nodeAssert.doesNotThrow(() => { - assert({type: 'foo', position: {end: null}}) - }, 'should not throw if given a null `position.end`') - - nodeAssert.doesNotThrow(() => { - assert({type: 'foo', position: {end: {}}}) - }, 'should not throw if given an empty `position.end` object') - - nodeAssert.doesNotThrow(() => { - assert({type: 'foo', position: {start: {line: null}}}) - }, 'should not throw if given a `position.start.line` to `null`') - - nodeAssert.doesNotThrow(() => { - assert({type: 'foo', position: {start: {column: null}}}) - }, 'should not throw if given a `position.start.column` to `null`') - - nodeAssert.doesNotThrow(() => { - assert({type: 'foo', position: {end: {line: null}}}) - }, 'should not throw if given a `position.end.line` to `null`') - - nodeAssert.doesNotThrow(() => { - assert({type: 'foo', position: {end: {column: null}}}) - }, 'should not throw if given a `position.end.column` to `null`') - - nodeAssert.throws( - () => { - assert({type: 'foo', position: {start: {line: 0}}}) - }, - /`position.start.line` should be gte `1`: `{ type: 'foo', position: { start: { line: 0 } } }`$/, - 'should throw if `position.start.line` is less than 1' - ) - - nodeAssert.throws( - () => { - assert({type: 'foo', position: {start: {column: 0}}}) - }, - /`position.start.column` should be gte `1`: `{ type: 'foo', position: { start: { column: 0 } } }`$/, - 'should throw if `position.start.column` is less than 1' - ) - - nodeAssert.throws( - () => { - assert({type: 'foo', position: {end: {line: 0}}}) - }, - /`position.end.line` should be gte `1`: `{ type: 'foo', position: { end: { line: 0 } } }`$/, - 'should throw if `position.end.line` is less than 1' - ) - - nodeAssert.throws( - () => { - assert({type: 'foo', position: {end: {column: 0}}}) - }, - /`position.end.column` should be gte `1`: `{ type: 'foo', position: { end: { column: 0 } } }`$/, - 'should throw if `position.end.column` is less than 1' +test('position', async function (t) { + await t.test( + 'should throw if given a non-object `position`', + async function () { + nodeAssert.throws(function () { + assert({type: 'foo', position: 1}) + }, /`position` should be an object: `{ type: 'foo', position: 1 }`$/) + } + ) + + await t.test( + 'should not throw if given a null `position`', + async function () { + nodeAssert.doesNotThrow(function () { + assert({type: 'foo', position: null}) + }) + } + ) + + await t.test( + 'should not throw if given an empty `position` object', + async function () { + nodeAssert.doesNotThrow(function () { + assert({type: 'foo', position: {}}) + }) + } + ) + + await t.test( + 'should throw if given a non-object `position.start`', + async function () { + nodeAssert.throws(function () { + assert({type: 'foo', position: {start: 1}}) + }, /`position.start` should be an object: `{ type: 'foo', position: { start: 1 } }`$/) + } + ) + + await t.test( + 'should not throw if given a null `position.start`', + async function () { + nodeAssert.doesNotThrow(function () { + assert({type: 'foo', position: {start: null}}) + }) + } + ) + + await t.test( + 'should not throw if given an empty `position.start` object', + async function () { + nodeAssert.doesNotThrow(function () { + assert({type: 'foo', position: {start: {}}}) + }) + } + ) + + await t.test( + 'should throw if given a non-object `position.end`', + async function () { + nodeAssert.throws(function () { + assert({type: 'foo', position: {end: 1}}) + }, /`position.end` should be an object: `{ type: 'foo', position: { end: 1 } }`$/) + } + ) + + await t.test( + 'should not throw if given a null `position.end`', + async function () { + nodeAssert.doesNotThrow(function () { + assert({type: 'foo', position: {end: null}}) + }) + } + ) + + await t.test( + 'should not throw if given an empty `position.end` object', + async function () { + nodeAssert.doesNotThrow(function () { + assert({type: 'foo', position: {end: {}}}) + }) + } + ) + + await t.test( + 'should not throw if given a `position.start.line` to `null`', + async function () { + nodeAssert.doesNotThrow(function () { + assert({type: 'foo', position: {start: {line: null}}}) + }) + } + ) + + await t.test( + 'should not throw if given a `position.start.column` to `null`', + async function () { + nodeAssert.doesNotThrow(function () { + assert({type: 'foo', position: {start: {column: null}}}) + }) + } + ) + + await t.test( + 'should not throw if given a `position.end.line` to `null`', + async function () { + nodeAssert.doesNotThrow(function () { + assert({type: 'foo', position: {end: {line: null}}}) + }) + } + ) + + await t.test( + 'should not throw if given a `position.end.column` to `null`', + async function () { + nodeAssert.doesNotThrow(function () { + assert({type: 'foo', position: {end: {column: null}}}) + }) + } + ) + + await t.test( + 'should throw if `position.start.line` is less than 1', + async function () { + nodeAssert.throws(function () { + assert({type: 'foo', position: {start: {line: 0}}}) + }, /`position.start.line` should be gte `1`: `{ type: 'foo', position: { start: { line: 0 } } }`$/) + } + ) + + await t.test( + 'should throw if `position.start.column` is less than 1', + async function () { + nodeAssert.throws(function () { + assert({type: 'foo', position: {start: {column: 0}}}) + }, /`position.start.column` should be gte `1`: `{ type: 'foo', position: { start: { column: 0 } } }`$/) + } + ) + + await t.test( + 'should throw if `position.end.line` is less than 1', + async function () { + nodeAssert.throws(function () { + assert({type: 'foo', position: {end: {line: 0}}}) + }, /`position.end.line` should be gte `1`: `{ type: 'foo', position: { end: { line: 0 } } }`$/) + } + ) + + await t.test( + 'should throw if `position.end.column` is less than 1', + async function () { + nodeAssert.throws(function () { + assert({type: 'foo', position: {end: {column: 0}}}) + }, /`position.end.column` should be gte `1`: `{ type: 'foo', position: { end: { column: 0 } } }`$/) + } ) }) diff --git a/test/type.js b/test/type.js index 52e2afd..47ae94d 100644 --- a/test/type.js +++ b/test/type.js @@ -2,40 +2,40 @@ import nodeAssert from 'node:assert/strict' import test from 'node:test' import {assert} from '../index.js' -test('type', () => { - nodeAssert.throws( - () => { +test('type', async function (t) { + await t.test('should throw if not given a `type` (#1)', async function () { + nodeAssert.throws(function () { assert({}) - }, - /node should have a type: `{}`$/, - 'should throw if not given a `type` (#1)' - ) + }, /node should have a type: `{}`$/) + }) - nodeAssert.throws( - () => { + await t.test('should throw if not given a type (#2)', async function () { + nodeAssert.throws(function () { assert({value: 'foo'}) - }, - /node should have a type: `{ value: 'foo' }`$/, - 'should throw if not given a type (#2)' - ) + }, /node should have a type: `{ value: 'foo' }`$/) + }) - nodeAssert.throws( - () => { - assert({type: 1}) - }, - /`type` should be a string: `{ type: 1 }`$/, - 'should throw if not given a non-string type' + await t.test( + 'should throw if not given a non-string type', + async function () { + nodeAssert.throws(function () { + assert({type: 1}) + }, /`type` should be a string: `{ type: 1 }`$/) + } ) - nodeAssert.throws( - () => { + await t.test('should throw if given an empty string type', async function () { + nodeAssert.throws(function () { assert({type: ''}) - }, - /`type` should not be empty: `{ type: '' }`$/, - 'should throw if given an empty string type' - ) + }, /`type` should not be empty: `{ type: '' }`$/) + }) - nodeAssert.doesNotThrow(() => { - assert({type: 'foo'}) - }, 'should not throw if given a non-empty type string') + await t.test( + 'should not throw if given a non-empty type string', + async function () { + nodeAssert.doesNotThrow(function () { + assert({type: 'foo'}) + }) + } + ) }) diff --git a/test/value.js b/test/value.js index f2f50e5..4ddfde0 100644 --- a/test/value.js +++ b/test/value.js @@ -2,28 +2,43 @@ import nodeAssert from 'node:assert/strict' import test from 'node:test' import {assert} from '../index.js' -test('value', () => { - nodeAssert.throws( - () => { +test('value', async function (t) { + await t.test('should throw if given a non-string `value`', async function () { + nodeAssert.throws(function () { assert({type: 'foo', value: 1}) - }, - /`value` should be a string: `{ type: 'foo', value: 1 }`$/, - 'should throw if given a non-string `value`' - ) + }, /`value` should be a string: `{ type: 'foo', value: 1 }`$/) + }) - nodeAssert.doesNotThrow(() => { - assert({type: 'foo', value: ''}) - }, 'should not throw if given an empty string `value`') + await t.test( + 'should not throw if given an empty string `value`', + async function () { + nodeAssert.doesNotThrow(function () { + assert({type: 'foo', value: ''}) + }) + } + ) - nodeAssert.doesNotThrow(() => { - assert({type: 'foo', value: 'foo'}) - }, 'should not throw if given an string `value`') + await t.test( + 'should not throw if given an string `value`', + async function () { + nodeAssert.doesNotThrow(function () { + assert({type: 'foo', value: 'foo'}) + }) + } + ) - nodeAssert.doesNotThrow(() => { - assert({type: 'foo', value: undefined}) - }, 'should not throw if given an undefined `value`') + await t.test( + 'should not throw if given an undefined `value`', + async function () { + nodeAssert.doesNotThrow(function () { + assert({type: 'foo', value: undefined}) + }) + } + ) - nodeAssert.doesNotThrow(() => { - assert({type: 'foo', value: null}) - }, 'should not throw if given an null `value`') + await t.test('should not throw if given an null `value`', async function () { + nodeAssert.doesNotThrow(function () { + assert({type: 'foo', value: null}) + }) + }) }) diff --git a/test/void.js b/test/void.js index 7384f2c..1354d24 100644 --- a/test/void.js +++ b/test/void.js @@ -2,32 +2,34 @@ import assert from 'node:assert/strict' import test from 'node:test' import {_void} from '../index.js' -test('_void()', () => { - assert.throws( - () => { +test('_void()', async function (t) { + await t.test('should throw the same errors as `assert()`', async function () { + assert.throws(function () { _void({}) - }, - /node should have a type: `{}`$/, - 'should throw the same errors as `assert()`' - ) + }, /node should have a type: `{}`$/) + }) - assert.throws( - () => { - _void({type: 'text', value: 'foo'}) - }, - /void should not have `value`: `{ type: 'text', value: 'foo' }`$/, - 'should throw if the given node has a `value`' + await t.test( + 'should throw if the given node has a `value`', + async function () { + assert.throws(function () { + _void({type: 'text', value: 'foo'}) + }, /void should not have `value`: `{ type: 'text', value: 'foo' }`$/) + } ) - assert.throws( - () => { - _void({type: 'strong', children: []}) - }, - /void should not have `children`: `{ type: 'strong', children: \[] }`$/, - 'should throw if the given node has `children`' + await t.test( + 'should throw if the given node has `children`', + async function () { + assert.throws(function () { + _void({type: 'strong', children: []}) + }, /void should not have `children`: `{ type: 'strong', children: \[] }`$/) + } ) - assert.doesNotThrow(() => { - _void({type: 'break'}) - }, 'should not throw on valid void nodes') + await t.test('should not throw on valid void nodes', async function () { + assert.doesNotThrow(function () { + _void({type: 'break'}) + }) + }) }) From f19e56ac8f62683369b15b80ebefa648fcbe01cc Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 29 Jun 2023 14:04:24 +0200 Subject: [PATCH 80/85] Refactor `.npmrc` --- .npmrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.npmrc b/.npmrc index 9951b11..3757b30 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1,2 @@ -package-lock=false ignore-scripts=true +package-lock=false From 4e4061b404a7d7ebfbdfa93d2c1651ddf5eae0d7 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 29 Jun 2023 14:05:41 +0200 Subject: [PATCH 81/85] Refactor docs --- readme.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/readme.md b/readme.md index c98754d..ebc8ca3 100644 --- a/readme.md +++ b/readme.md @@ -46,7 +46,7 @@ do the same but for mdast, hast, and nlcst nodes, respectively. ## Install This package is [ESM only][esm]. -In Node.js (version 14.14+ and 16.0+), install with [npm][]: +In Node.js (version 16+), install with [npm][]: ```sh npm install unist-util-assert @@ -218,10 +218,13 @@ It exports the additional type [`AssertionError`][assertionerror]. ## Compatibility -Projects maintained by the unified collective are compatible with all maintained +Projects maintained by the unified collective are compatible with maintained versions of Node.js. -As of now, that is Node.js 14.14+ and 16.0+. -Our projects sometimes work with older versions, but this is not guaranteed. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, `unist-util-assert@^3`, +compatible with Node.js 12. ## Related @@ -260,9 +263,9 @@ abide by its terms. [downloads]: https://www.npmjs.com/package/unist-util-assert -[size-badge]: https://img.shields.io/bundlephobia/minzip/unist-util-assert.svg +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=unist-util-assert -[size]: https://bundlephobia.com/result?p=unist-util-assert +[size]: https://bundlejs.com/?q=unist-util-assert [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg From 6dacb525442a9dbf40f5c91983c149f419c7be8a Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 29 Jun 2023 14:10:30 +0200 Subject: [PATCH 82/85] Change to use `export` map --- index.test-d.ts | 2 +- lib/index.js | 2 +- lib/{inspect.browser.js => inspect.default.js} | 0 lib/{inspect.js => inspect.node.js} | 0 package.json | 13 ++++++------- test/children.js | 2 +- test/core.js | 2 +- test/literal.js | 2 +- test/node.js | 2 +- test/non-defined.js | 2 +- test/parent.js | 2 +- test/position.js | 2 +- test/type.js | 2 +- test/value.js | 2 +- test/void.js | 2 +- 15 files changed, 18 insertions(+), 19 deletions(-) rename lib/{inspect.browser.js => inspect.default.js} (100%) rename lib/{inspect.js => inspect.node.js} (100%) diff --git a/index.test-d.ts b/index.test-d.ts index 4802246..6f606cd 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,6 +1,6 @@ import {expectNotType, expectType} from 'tsd' import type {Node, Parent} from 'unist' -import {assert, parent} from './index.js' +import {assert, parent} from 'unist-util-assert' const emptyNode = {type: 'a'} const literalNode = {type: 'b', value: 'c'} diff --git a/lib/index.js b/lib/index.js index ba2ce1a..fcf3cee 100644 --- a/lib/index.js +++ b/lib/index.js @@ -26,7 +26,7 @@ */ import nodeAssert from 'node:assert' -import {inspect} from './inspect.js' +import {inspect} from 'unist-util-assert/do-not-use-conditional-inspect' const own = {}.hasOwnProperty diff --git a/lib/inspect.browser.js b/lib/inspect.default.js similarity index 100% rename from lib/inspect.browser.js rename to lib/inspect.default.js diff --git a/lib/inspect.js b/lib/inspect.node.js similarity index 100% rename from lib/inspect.js rename to lib/inspect.node.js diff --git a/package.json b/package.json index e269b38..4626574 100644 --- a/package.json +++ b/package.json @@ -24,14 +24,13 @@ ], "sideEffects": false, "type": "module", - "main": "index.js", - "browser": { - "./lib/inspect.js": "./lib/inspect.browser.js" + "exports": { + ".": "./index.js", + "./do-not-use-conditional-inspect": { + "node": "./lib/inspect.node.js", + "default": "./lib/inspect.default.js" + } }, - "react-native": { - "./lib/inspect.js": "./lib/inspect.browser.js" - }, - "types": "index.d.ts", "files": [ "lib/", "index.d.ts", diff --git a/test/children.js b/test/children.js index 29ea1ce..6068376 100644 --- a/test/children.js +++ b/test/children.js @@ -1,6 +1,6 @@ import nodeAssert from 'node:assert/strict' import test from 'node:test' -import {assert} from '../index.js' +import {assert} from 'unist-util-assert' test('children', async function (t) { await t.test( diff --git a/test/core.js b/test/core.js index 98d8e3a..62126ee 100644 --- a/test/core.js +++ b/test/core.js @@ -3,7 +3,7 @@ import test from 'node:test' test('assert', async function (t) { await t.test('should expose the public api', async function () { - assert.deepEqual(Object.keys(await import('../index.js')).sort(), [ + assert.deepEqual(Object.keys(await import('unist-util-assert')).sort(), [ '_void', 'assert', 'literal', diff --git a/test/literal.js b/test/literal.js index 14f32e4..c9d737d 100644 --- a/test/literal.js +++ b/test/literal.js @@ -1,6 +1,6 @@ import assert from 'node:assert/strict' import test from 'node:test' -import {literal} from '../index.js' +import {literal} from 'unist-util-assert' test('literal()', async function (t) { await t.test('should throw the same errors as `assert()`', async function () { diff --git a/test/node.js b/test/node.js index c1bba41..e9d9e84 100644 --- a/test/node.js +++ b/test/node.js @@ -1,6 +1,6 @@ import nodeAssert from 'node:assert/strict' import test from 'node:test' -import {assert} from '../index.js' +import {assert} from 'unist-util-assert' test('node', async function (t) { await t.test('should throw if not given a node (#1)', async function () { diff --git a/test/non-defined.js b/test/non-defined.js index d5c11e3..95c99fc 100644 --- a/test/non-defined.js +++ b/test/non-defined.js @@ -1,6 +1,6 @@ import nodeAssert from 'node:assert/strict' import test from 'node:test' -import {assert} from '../index.js' +import {assert} from 'unist-util-assert' test('non-defined', async function (t) { await t.test( diff --git a/test/parent.js b/test/parent.js index 416b0f9..511d7d0 100644 --- a/test/parent.js +++ b/test/parent.js @@ -1,6 +1,6 @@ import assert from 'node:assert/strict' import test from 'node:test' -import {parent} from '../index.js' +import {parent} from 'unist-util-assert' test('parent()', async function (t) { await t.test('should throw the same errors as `assert()`', async function () { diff --git a/test/position.js b/test/position.js index 73945da..c687359 100644 --- a/test/position.js +++ b/test/position.js @@ -1,6 +1,6 @@ import nodeAssert from 'node:assert/strict' import test from 'node:test' -import {assert} from '../index.js' +import {assert} from 'unist-util-assert' test('position', async function (t) { await t.test( diff --git a/test/type.js b/test/type.js index 47ae94d..d59e7d1 100644 --- a/test/type.js +++ b/test/type.js @@ -1,6 +1,6 @@ import nodeAssert from 'node:assert/strict' import test from 'node:test' -import {assert} from '../index.js' +import {assert} from 'unist-util-assert' test('type', async function (t) { await t.test('should throw if not given a `type` (#1)', async function () { diff --git a/test/value.js b/test/value.js index 4ddfde0..9afbc9f 100644 --- a/test/value.js +++ b/test/value.js @@ -1,6 +1,6 @@ import nodeAssert from 'node:assert/strict' import test from 'node:test' -import {assert} from '../index.js' +import {assert} from 'unist-util-assert' test('value', async function (t) { await t.test('should throw if given a non-string `value`', async function () { diff --git a/test/void.js b/test/void.js index 1354d24..d358bea 100644 --- a/test/void.js +++ b/test/void.js @@ -1,6 +1,6 @@ import assert from 'node:assert/strict' import test from 'node:test' -import {_void} from '../index.js' +import {_void} from 'unist-util-assert' test('_void()', async function (t) { await t.test('should throw the same errors as `assert()`', async function () { From e2abc8be675cce80b790fc60c2a77ad56a1184ad Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 29 Jun 2023 14:10:52 +0200 Subject: [PATCH 83/85] Change to require Node.js 16 --- readme.md | 4 ++-- tsconfig.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index ebc8ca3..e650bdb 100644 --- a/readme.md +++ b/readme.md @@ -223,8 +223,8 @@ versions of Node.js. When we cut a new major release, we drop support for unmaintained versions of Node. -This means we try to keep the current release line, `unist-util-assert@^3`, -compatible with Node.js 12. +This means we try to keep the current release line, `unist-util-assert@^4`, +compatible with Node.js 16. ## Related diff --git a/tsconfig.json b/tsconfig.json index 870d82c..82cc749 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,10 +5,10 @@ "declaration": true, "emitDeclarationOnly": true, "exactOptionalPropertyTypes": true, - "lib": ["es2020"], + "lib": ["es2022"], "module": "node16", "strict": true, - "target": "es2020" + "target": "es2022" }, "exclude": ["coverage/", "node_modules/"], "include": ["**/*.js"] From 74155db01bdc41511f1ac13b667fe7277f866186 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 7 Jul 2023 12:03:34 +0200 Subject: [PATCH 84/85] Update `@types/unist` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4626574..b9ea206 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "index.js" ], "dependencies": { - "@types/unist": "^2.0.0" + "@types/unist": "^3.0.0" }, "devDependencies": { "@types/node": "^20.0.0", From 963f4c869206ebf1fdea95d120cdcee6b064f0ca Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 7 Jul 2023 12:04:09 +0200 Subject: [PATCH 85/85] 4.0.0 --- package.json | 2 +- readme.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index b9ea206..6e7b325 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unist-util-assert", - "version": "3.0.2", + "version": "4.0.0", "description": "unist utility to assert nodes", "license": "MIT", "keywords": [ diff --git a/readme.md b/readme.md index e650bdb..50c4b55 100644 --- a/readme.md +++ b/readme.md @@ -55,14 +55,14 @@ npm install unist-util-assert In Deno with [`esm.sh`][esmsh]: ```js -import {assert} from 'https://esm.sh/unist-util-assert@3' +import {assert} from 'https://esm.sh/unist-util-assert@4' ``` In browsers with [`esm.sh`][esmsh]: ```html ```