1- /**
2- * @author Titus Wormer
3- * @copyright 2016 Titus Wormer
4- * @license MIT
5- * @module unist-util-assert
6- * @fileoverview Assert `unist` nodes.
7- */
8-
91'use strict' ;
102
11- /* eslint-env commonjs */
12- /* eslint-disable no-useless-concat */
13-
143/* Dependencies. */
154var assert = require ( 'assert' ) ;
165var array = require ( 'x-is-array' ) ;
@@ -19,6 +8,7 @@ var object = require('x-is-object');
198var inspect ;
209
2110try {
11+ // eslint-disable-next-line import/no-dynamic-require, no-useless-concat
2212 inspect = require ( 'ut' + 'il' ) . inspect ;
2313} catch ( err ) { /* Empty. */ }
2414
@@ -36,14 +26,8 @@ var ID = '__unist__';
3626/* List of specced properties. */
3727var defined = [ 'type' , 'value' , 'children' , 'position' ] ;
3828
39- /**
40- * Wrapper around `Node` which adds the current node
41- * (and parent, if available), to the message.
42- *
43- * @param {Node } node - Node to checl.
44- * @param {Node? } [parent] - Parent of `node`.
45- * @throws {Error } - Prettified error.
46- */
29+ /* Wrapper around `Node` which adds the current node
30+ * (and parent, if available), to the message. */
4731function wrap ( fn ) {
4832 return wrapped ;
4933
@@ -66,13 +50,7 @@ function wrap(fn) {
6650 }
6751}
6852
69- /**
70- * Assert.
71- *
72- * @param {Node } node - Value to assert.
73- * @throws {Error } - If the given value doesn’t adhere to
74- * unist.
75- */
53+ /* Assert. */
7654function unist ( node ) {
7755 var type ;
7856 var children ;
@@ -114,15 +92,8 @@ function unist(node) {
11492 }
11593}
11694
117- /**
118- * Assert `value` (which lives at `key`) can be stringified
119- * and re-parsed to the same (deep) value.
120- *
121- * @param {* } value - Value to assert.
122- * @param {string } key - Property at which `value` lives.
123- * @throws {Error } - If the given value doesn’t adhere to
124- * `Parent`.
125- */
95+ /* Assert `value` (which lives at `key`) can be stringified
96+ * and re-parsed to the same (deep) value. */
12697function vanilla ( key , value ) {
12798 try {
12899 assert . deepEqual ( value , JSON . parse ( JSON . stringify ( value ) ) ) ;
@@ -131,16 +102,9 @@ function vanilla(key, value) {
131102 }
132103}
133104
134- /**
135- * Stringify a value to inspect it. Tries `JSON.stringify()`,
105+ /* Stringify a value to inspect it. Tries `JSON.stringify()`,
136106 * and if that fails uses `String()` instead. If `stringify()`
137- * works, ``
138- *
139- * @param {* } value - Value to assert.
140- * @param {string } key - Property at which `value` lives.
141- * @throws {Error } - If the given value doesn’t adhere to
142- * `Parent`.
143- */
107+ * works. */
144108function view ( value ) {
145109 try {
146110 /* eslint-disable no-else-return */
@@ -156,56 +120,32 @@ function view(value) {
156120 }
157121}
158122
159- /**
160- * Assert `node` is a parent node.
161- *
162- * @param {Node } node - Value to assert.
163- * @throws {Error } - If the given value doesn’t adhere to
164- * `Parent`.
165- */
123+ /* Assert `node` is a parent node. */
166124function parent ( node ) {
167125 unist ( node ) ;
168126
169127 assert . equal ( 'value' in node , false , 'parent should not have `value`' ) ;
170128 assert . ok ( 'children' in node , 'parent should have `children`' ) ;
171129}
172130
173- /**
174- * Assert `node` is a text node.
175- *
176- * @param {Node } node - Value to assert.
177- * @throws {Error } - If the given value doesn’t adhere to
178- * `Text`.
179- */
131+ /* Assert `node` is a text node. */
180132function text ( node ) {
181133 unist ( node ) ;
182134
183135 assert . equal ( 'children' in node , false , 'text should not have `children`' ) ;
184136 assert . ok ( 'value' in node , 'text should have `value`' ) ;
185137}
186138
187- /**
188- * Assert `node` is a Unist node, but neither parent nor
189- * text.
190- *
191- * @param {Node } node - Value to assert.
192- * @throws {Error } - If the given value doesn’t adhere to
193- * Unist, is a `Parent`, or a `Text`.
194- */
139+ /* Assert `node` is a Unist node, but neither parent nor
140+ * text. */
195141function empty ( node ) {
196142 unist ( node ) ;
197143
198144 assert . equal ( 'value' in node , false , 'void should not have `value`' ) ;
199145 assert . equal ( 'children' in node , false , 'void should not have `children`' ) ;
200146}
201147
202- /**
203- * Assert `location` is a Unist Location.
204- *
205- * @param {Location } location - Location to assert.
206- * @throws {Error } - If the given value doesn’t adhere to
207- * Unist Location.
208- */
148+ /* Assert `location` is a Unist Location. */
209149function location ( location ) {
210150 if ( location != null ) {
211151 assert . ok ( object ( location ) , '`position` should be an object' ) ;
@@ -215,13 +155,7 @@ function location(location) {
215155 }
216156}
217157
218- /**
219- * Assert `location` is a Unist Location.
220- *
221- * @param {Location } location - Location to assert.
222- * @throws {Error } - If the given value doesn’t adhere to
223- * Unist Location.
224- */
158+ /* Assert `location` is a Unist Location. */
225159function position ( position , name ) {
226160 if ( position != null ) {
227161 assert . ok ( object ( position ) , '`' + name + '` should be an object' ) ;
0 commit comments