UNPKG
zeroise
Version:
latest (0.1.0)
0.1.0
Add leading zeros to fill a certain number to the given size.
github.com/tyxla/zeroise
tyxla/zeroise
zeroise
/
index.js
14 lines
(11 loc)
•
295 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
var
zeroise =
function
(
number
, threshold, pad
) {
if
(
typeof
pad ===
'undefined'
) { pad =
'0'
; }
var
width =
number
.
toString
().
length
;
if
( width >= threshold ) {
return
number
+
""
; }
return
Array
(threshold - width +
1
).
join
(pad) +
number
; }
module
.
exports
= zeroise;