1
+ ( function ( f ) { if ( typeof exports === "object" && typeof module !== "undefined" ) { module . exports = f ( ) } else if ( typeof define === "function" && define . amd ) { define ( [ ] , f ) } else { var g ; if ( typeof window !== "undefined" ) { g = window } else if ( typeof global !== "undefined" ) { g = global } else if ( typeof self !== "undefined" ) { g = self } else { g = this } g . unistUtilFindAllBefore = f ( ) } } ) ( function ( ) { var define , module , exports ; return ( function e ( t , n , r ) { function s ( o , u ) { if ( ! n [ o ] ) { if ( ! t [ o ] ) { var a = typeof require == "function" && require ; if ( ! u && a ) return a ( o , ! 0 ) ; if ( i ) return i ( o , ! 0 ) ; var f = new Error ( "Cannot find module '" + o + "'" ) ; throw f . code = "MODULE_NOT_FOUND" , f } var l = n [ o ] = { exports :{ } } ; t [ o ] [ 0 ] . call ( l . exports , function ( e ) { var n = t [ o ] [ 1 ] [ e ] ; return s ( n ?n :e ) } , l , l . exports , e , t , n , r ) } return n [ o ] . exports } var i = typeof require == "function" && require ; for ( var o = 0 ; o < r . length ; o ++ ) s ( r [ o ] ) ; return s } ) ( { 1 :[ function ( require , module , exports ) {
2
+ 'use strict' ;
3
+
4
+ var is = require ( 'unist-util-is' ) ;
5
+
6
+ module . exports = findAllBefore ;
7
+
8
+ /* Find nodes before `index` in `parent` which pass `test`. */
9
+ function findAllBefore ( parent , index , test ) {
10
+ var results = [ ] ;
11
+ var children ;
12
+ var child ;
13
+
14
+ if ( ! parent || ! parent . type || ! parent . children ) {
15
+ throw new Error ( 'Expected parent node' ) ;
16
+ }
17
+
18
+ children = parent . children ;
19
+
20
+ if ( index && index . type ) {
21
+ index = children . indexOf ( index ) ;
22
+ }
23
+
24
+ if ( isNaN ( index ) || index < 0 || index === Infinity ) {
25
+ throw new Error ( 'Expected positive finite index or child node' ) ;
26
+ }
27
+
28
+ /* Performance. */
29
+ if ( index > children . length ) {
30
+ index = children . length ;
31
+ }
32
+
33
+ while ( index -- ) {
34
+ child = children [ index ] ;
35
+
36
+ if ( is ( test , child , index , parent ) ) {
37
+ results . push ( child ) ;
38
+ }
39
+ }
40
+
41
+ return results ;
42
+ }
43
+
44
+ } , { "unist-util-is" :2 } ] , 2 :[ function ( require , module , exports ) {
45
+ /**
46
+ * @author Titus Wormer
47
+ * @copyright 2015 Titus Wormer
48
+ * @license MIT
49
+ * @module unist:util:is
50
+ * @fileoverview Utility to check if a node passes a test.
51
+ */
52
+
53
+ 'use strict' ;
54
+
55
+ /* eslint-env commonjs */
56
+
57
+ /**
58
+ * Test.
59
+ *
60
+ * @typedef {Function } is~test
61
+ * @param {Node } node - Node to test.
62
+ * @param {number } index - Position of `node` in `parent`.
63
+ * @param {Node } parent - Parent of `node`.
64
+ * @return {boolean? } - Whether this iteration passes.
65
+ */
66
+
67
+ /**
68
+ * Utility to return true.
69
+ *
70
+ * @type {is~test }
71
+ */
72
+ function first ( ) {
73
+ return true ;
74
+ }
75
+
76
+ /**
77
+ * Utility to convert a string into a function which checks
78
+ * a given node’s type for said string.
79
+ *
80
+ * @param {string } test - Node type to test.
81
+ * @return {is~test } - Tester.
82
+ */
83
+ function typeFactory ( test ) {
84
+ return function ( node ) {
85
+ return Boolean ( node && node . type === test ) ;
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Utility to convert a node into a function which checks
91
+ * a given node for strict equality.
92
+ *
93
+ * @param {Node } test - Node to test.
94
+ * @return {is~test } - Tester.
95
+ */
96
+ function nodeFactory ( test ) {
97
+ return function ( node ) {
98
+ return node === test ;
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Assert if `test` passes for `node`.
104
+ * When a `parent` node is known the `index` of node
105
+ *
106
+ * @example
107
+ * is(null, {type: 'strong'}); // true
108
+ *
109
+ * @example
110
+ * is('strong', {type: 'strong'}); // true
111
+ * is('emphasis', {type: 'strong'}); // false
112
+ *
113
+ * @example
114
+ * var node = {type: 'strong'};
115
+ * is(node, node) // true
116
+ * is(node, {type: 'strong'}) // false
117
+ *
118
+ * @example
119
+ * var node = {type: 'strong'};
120
+ * var parent = {type: 'paragraph', children: [node]};
121
+ * function test(node, n) {return n === 5};
122
+ * is(test, {type: 'strong'}); // false
123
+ * is(test, {type: 'strong'}, 4, parent); // false
124
+ * is(test, {type: 'strong'}, 5, parent); // true
125
+ *
126
+ * @example
127
+ * var node = {type: 'strong'};
128
+ * var parent = {type: 'paragraph', children: [node]};
129
+ * is('strong'); // throws
130
+ * is('strong', node, 0) // throws
131
+ * is('strong', node, null, parent) // throws
132
+ * is('strong', node, 0, {type: 'paragraph'}) // throws
133
+ * is('strong', node, -1, parent) // throws
134
+ * is('strong', node, Infinity, parent) // throws
135
+ *
136
+ * @param {(string|Node|is~test)? } test - Tester.
137
+ * @param {Node } node - Node to test.
138
+ * @param {number? } [index] - Position of `node` in `parent`.
139
+ * @param {Node? } [parent] - Parent of `node`.
140
+ * @param {* } [context] - Context to invoke `test` with.
141
+ * @return {boolean } - Whether `test` passes.
142
+ */
143
+ function is ( test , node , index , parent , context ) {
144
+ var hasParent = parent !== null && parent !== undefined ;
145
+ var hasIndex = index !== null && index !== undefined ;
146
+
147
+ if ( typeof test === 'string' ) {
148
+ test = typeFactory ( test ) ;
149
+ } else if ( test && test . type ) {
150
+ test = nodeFactory ( test ) ;
151
+ } else if ( test === null || test === undefined ) {
152
+ test = first ;
153
+ } else if ( typeof test !== 'function' ) {
154
+ throw new Error ( 'Expected function, string, or node as test' ) ;
155
+ }
156
+
157
+ if ( ! node || ! node . type ) {
158
+ throw new Error ( 'Expected node' ) ;
159
+ }
160
+
161
+ if (
162
+ hasIndex &&
163
+ ( typeof index !== 'number' || index < 0 || index === Infinity )
164
+ ) {
165
+ throw new Error ( 'Expected positive finite index or child node' ) ;
166
+ }
167
+
168
+ if ( hasParent && ( ! parent || ! parent . type || ! parent . children ) ) {
169
+ throw new Error ( 'Expected parent node' ) ;
170
+ }
171
+
172
+ if ( hasParent !== hasIndex ) {
173
+ throw new Error ( 'Expected both parent and index' ) ;
174
+ }
175
+
176
+ return Boolean ( test . call ( context , node , index , parent ) ) ;
177
+ }
178
+
179
+ /*
180
+ * Expose.
181
+ */
182
+
183
+ module . exports = is ;
184
+
185
+ } , { } ] } , { } , [ 1 ] ) ( 1 )
186
+ } ) ;
0 commit comments