source: trip-planner-front/node_modules/stylus/lib/functions/base-convert.js@ 84d0fbb

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: 725 bytes
Line 
1var utils = require('../utils')
2 , nodes = require('../nodes');
3
4/**
5 * Return a `Literal` `num` converted to the provided `base`, padded to `width`
6 * with zeroes (default width is 2)
7 *
8 * @param {Number} num
9 * @param {Number} base
10 * @param {Number} width
11 * @return {Literal}
12 * @api public
13 */
14
15(module.exports = function(num, base, width) {
16 utils.assertPresent(num, 'number');
17 utils.assertPresent(base, 'base');
18 num = utils.unwrap(num).nodes[0].val;
19 base = utils.unwrap(base).nodes[0].val;
20 width = (width && utils.unwrap(width).nodes[0].val) || 2;
21 var result = Number(num).toString(base);
22 while (result.length < width) {
23 result = '0' + result;
24 }
25 return new nodes.Literal(result);
26}).raw = true;
Note: See TracBrowser for help on using the repository browser.