Last change
on this file since 84d0fbb was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
674 bytes
|
Line | |
---|
1 | var utils = require('../utils'),
|
---|
2 | nodes = require('../nodes');
|
---|
3 |
|
---|
4 | /**
|
---|
5 | * This is a helper function for the slice method
|
---|
6 | *
|
---|
7 | * @param {String|Ident} vals
|
---|
8 | * @param {Unit} start [0]
|
---|
9 | * @param {Unit} end [vals.length]
|
---|
10 | * @return {String|Literal|Null}
|
---|
11 | * @api public
|
---|
12 | */
|
---|
13 | (module.exports = function slice(val, start, end) {
|
---|
14 | start = start && start.nodes[0].val;
|
---|
15 | end = end && end.nodes[0].val;
|
---|
16 |
|
---|
17 | val = utils.unwrap(val).nodes;
|
---|
18 |
|
---|
19 | if (val.length > 1) {
|
---|
20 | return utils.coerce(val.slice(start, end), true);
|
---|
21 | }
|
---|
22 |
|
---|
23 | var result = val[0].string.slice(start, end);
|
---|
24 |
|
---|
25 | return val[0] instanceof nodes.Ident
|
---|
26 | ? new nodes.Ident(result)
|
---|
27 | : new nodes.String(result);
|
---|
28 | }).raw = true;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.