Last change
on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
663 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | var utils = require('../utils')
|
---|
| 2 | , nodes = require('../nodes');
|
---|
| 3 |
|
---|
| 4 | /**
|
---|
| 5 | * Splits the given `val` by `delim`
|
---|
| 6 | *
|
---|
| 7 | * @param {String} delim
|
---|
| 8 | * @param {String|Ident} val
|
---|
| 9 | * @return {Expression}
|
---|
| 10 | * @api public
|
---|
| 11 | */
|
---|
| 12 |
|
---|
| 13 | function split(delim, val){
|
---|
| 14 | utils.assertString(delim, 'delimiter');
|
---|
| 15 | utils.assertString(val, 'val');
|
---|
| 16 | var splitted = val.string.split(delim.string);
|
---|
| 17 | var expr = new nodes.Expression();
|
---|
| 18 | var ItemNode = val instanceof nodes.Ident
|
---|
| 19 | ? nodes.Ident
|
---|
| 20 | : nodes.String;
|
---|
| 21 | for (var i = 0, len = splitted.length; i < len; ++i) {
|
---|
| 22 | expr.nodes.push(new ItemNode(splitted[i]));
|
---|
| 23 | }
|
---|
| 24 | return expr;
|
---|
| 25 | }
|
---|
| 26 | split.params = ['delim', 'val'];
|
---|
| 27 | module.exports = split;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.