Blame view

node_modules/stylus/lib/functions/slice.js 673 Bytes
ce4c83ff   wxy   初始提交
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  var utils = require('../utils'),
      nodes = require('../nodes');
  
  /**
   * This is a heler function for the slice method
   *
   * @param {String|Ident} vals
   * @param {Unit} start [0]
   * @param {Unit} end [vals.length]
   * @return {String|Literal|Null}
   * @api public
  */
  (module.exports = function slice(val, start, end) {
    start = start && start.nodes[0].val;
    end = end && end.nodes[0].val;
  
    val = utils.unwrap(val).nodes;
  
    if (val.length > 1) {
      return utils.coerce(val.slice(start, end), true);
    }
  
    var result = val[0].string.slice(start, end);
  
    return val[0] instanceof nodes.Ident
      ? new nodes.Ident(result)
      : new nodes.String(result);
  }).raw = true;