You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
725 B
27 lines
725 B
9 years ago
|
var utils = require('../utils')
|
||
|
, nodes = require('../nodes');
|
||
|
|
||
|
/**
|
||
|
* Return a `Literal` `num` converted to the provided `base`, padded to `width`
|
||
|
* with zeroes (default width is 2)
|
||
|
*
|
||
|
* @param {Number} num
|
||
|
* @param {Number} base
|
||
|
* @param {Number} width
|
||
|
* @return {Literal}
|
||
|
* @api public
|
||
|
*/
|
||
|
|
||
|
(module.exports = function(num, base, width) {
|
||
|
utils.assertPresent(num, 'number');
|
||
|
utils.assertPresent(base, 'base');
|
||
|
num = utils.unwrap(num).nodes[0].val;
|
||
|
base = utils.unwrap(base).nodes[0].val;
|
||
|
width = (width && utils.unwrap(width).nodes[0].val) || 2;
|
||
|
var result = Number(num).toString(base);
|
||
|
while (result.length < width) {
|
||
|
result = '0' + result;
|
||
|
}
|
||
|
return new nodes.Literal(result);
|
||
|
}).raw = true;
|