File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change 1+ const config = require ( './../../src/models/time' ) ;
2+ const expect = require ( 'chai' ) . expect ;
3+
4+ describe ( 'time class' , ( ) => {
5+ it ( 'Formats numbers' , ( ) => {
6+ expect ( ( new Number ( 1 ) ) . padLeft ( 2 , "0" ) ) . to . equal ( '01' ) ;
7+ expect ( ( new Number ( 12 ) ) . padLeft ( 2 , "0" ) ) . to . equal ( '12' ) ;
8+ expect ( ( new Number ( 123 ) ) . padLeft ( 2 , "0" ) ) . to . equal ( '123' ) ;
9+ expect ( ( new Number ( 1234 ) ) . padLeft ( 2 , "0" ) ) . to . equal ( '1234' ) ;
10+ } ) ;
11+ } ) ;
12+
Original file line number Diff line number Diff line change @@ -9,8 +9,15 @@ const roundedRegex = /(\[\%([^\>\]]*)\:([^\]]*)\])/ig;
99const conditionalSimpleRegex = / ( [ 0 - 9 ] * ) \> ( .* ) / ig;
1010const defaultRegex = / ( \[ \% ( [ ^ \] ] * ) \] ) / ig;
1111
12+ /**
13+ * Adds leading zeroes to the number
14+ *
15+ * @param {Number } n
16+ * @param {String } str
17+ * @returns {String }
18+ */
1219Number . prototype . padLeft = function ( n , str ) {
13- return Array ( n - String ( this ) . length + 1 ) . join ( str || '0' ) + this ;
20+ return Array ( Math . max ( 0 , n - String ( this ) . length + 1 ) ) . join ( str || '0' ) + this ;
1421} ;
1522
1623/**
You can’t perform that action at this time.
0 commit comments