source: trip-planner-front/node_modules/stylus/lib/functions/s.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 881 bytes
Line 
1var utils = require('../utils')
2 , nodes = require('../nodes')
3 , Compiler = require('../visitor/compiler');
4
5/**
6 * Return a `Literal` with the given `fmt`, and
7 * variable number of arguments.
8 *
9 * @param {String} fmt
10 * @param {Node} ...
11 * @return {Literal}
12 * @api public
13 */
14
15(module.exports = function s(fmt){
16 fmt = utils.unwrap(fmt).nodes[0];
17 utils.assertString(fmt);
18 var self = this
19 , str = fmt.string
20 , args = arguments
21 , i = 1;
22
23 // format
24 str = str.replace(/%(s|d)/g, function(_, specifier){
25 var arg = args[i++] || nodes.null;
26 switch (specifier) {
27 case 's':
28 return new Compiler(arg, self.options).compile();
29 case 'd':
30 arg = utils.unwrap(arg).first;
31 if ('unit' != arg.nodeName) throw new Error('%d requires a unit');
32 return arg.val;
33 }
34 });
35
36 return new nodes.Literal(str);
37}).raw = true;
Note: See TracBrowser for help on using the repository browser.