You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var valueParser = require('postcss-value-parser');
92
179
```
93
180
94
-
### valueParser.unit(value)
181
+
### valueParser.unit(quantity)
95
182
96
-
Returns parsed value.
183
+
Parses `quantity`, distinguishing the number from the unit. Returns an object like the following:
97
184
98
185
```js
99
-
//.2rem
186
+
//Given 2rem
100
187
{
101
-
number:'.2',
188
+
number:'2',
102
189
unit:'rem'
103
190
}
104
191
```
105
192
193
+
If the `quantity` argument cannot be parsed as a number, returns `false`.
194
+
195
+
*This function does not parse complete values*: you cannot pass it `1px solid black` and expect `px` as
196
+
the unit. Instead, you should pass it single quantities only. Parse `1px solid black`, then pass it
197
+
the stringified `1px` node (a `word` node) to parse the number and unit.
198
+
106
199
### valueParser.stringify(nodes)
107
200
108
-
Stringifies node and array of nodes.
201
+
Stringifies a node or array of nodes.
202
+
203
+
### valueParser.walk(nodes, callback[, bubble])
204
+
205
+
Walks each provided node, recursively walking all descendent nodes within functions.
109
206
110
-
### valueParser.walk(nodes, cb[, bubble])
207
+
Returning `false` in the `callback` will prevent traversal of descendent nodes (within functions).
208
+
You can use this feature to for shallow iteration, walking over only the *immediate* children.
209
+
*Note: This only applies if `bubble` is `false` (which is the default).*
111
210
112
-
Walks each provided node, recursively for each node in a function.
211
+
By default, the tree is walked from the outermost node inwards.
212
+
To reverse the direction, pass `true` for the `bubble` argument.
113
213
114
-
Returning `false` in the callback will prevent traversal of deeper, nested nodes(inside a function). You can use this to walk over only the immediate children. *note: This only applies if `bubble` is `false`(default).*
214
+
The `callback` is invoked with three arguments: `callback(node, index, nodes)`.
115
215
116
-
Returns `this` instance.
216
+
-`node`: The current node.
217
+
-`index`: The index of the current node.
218
+
-`nodes`: The complete nodes array passed to `walk()`.
117
219
118
-
-`nodes`: array - `value-parser` nodes
119
-
-`cb(node, index, nodes)`: function - Function to execute for each node
120
-
-`bubble`: boolean - Walk from the deepest nodes upwards
220
+
Returns the `valueParser` instance.
121
221
122
-
### var p = valueParser(value)
222
+
### var parsed = valueParser(value)
123
223
124
-
Returns parsed tree.
224
+
Returns the parsed node tree.
125
225
126
-
### p.nodes
226
+
### parsed.nodes
127
227
128
-
Root nodes list.
228
+
The array of nodes.
129
229
130
-
### p.toString()
230
+
### parsed.toString()
131
231
132
-
Stringify tree to the value.
232
+
Stringifies the node tree.
133
233
134
-
### p.walk(cb[, bubble])
234
+
### parsed.walk(callback[, bubble])
135
235
136
-
Walks each node since `p.nodes`.
236
+
Walks each node inside `parsed.nodes`. See the documentation for `valueParser.walk()` above.
0 commit comments