string-kit
Advanced tools
Comparing version 0.11.0 to 0.11.1
@@ -75,2 +75,3 @@ | ||
* `%k` number with metric system prefixes (like k, M, G, and so on...) | ||
* `%m` degrees/minutes/seconds notation | ||
* `%t` time duration, convert ms into H:min:s | ||
@@ -77,0 +78,0 @@ * `%h` unsigned hexadecimal |
@@ -480,2 +480,31 @@ /* | ||
// Degree, minutes and seconds. | ||
// Unlike %t which receive ms, here the input is in degree. | ||
modes.m = arg => { | ||
if ( typeof arg === 'string' ) { arg = parseFloat( arg ) ; } | ||
if ( typeof arg !== 'number' ) { return '(NaN)' ; } | ||
var minus = '' ; | ||
if ( arg < 0 ) { minus = '-' ; arg = -arg ; } | ||
var degrees = epsilonFloor( arg ) , | ||
frac = arg - degrees ; | ||
if ( ! frac ) { return minus + degrees + '°' ; } | ||
var minutes = epsilonFloor( frac * 60 ) , | ||
seconds = epsilonFloor( frac * 3600 - minutes * 60 ) ; | ||
if ( seconds ) { | ||
return minus + degrees + '°' + ( '' + minutes ).padStart( 2 , '0' ) + '′' + ( '' + seconds ).padStart( 2 , '0' ) + '″' ; | ||
} | ||
return minus + degrees + '°' + ( '' + minutes ).padStart( 2 , '0' ) + '′' ; | ||
} ; | ||
modes.m.noSanitize = true ; | ||
// time duration, transform ms into H:min:s | ||
@@ -898,2 +927,6 @@ // Later it should format Date as well: number=duration, date object=date | ||
function epsilonFloor( v ) { | ||
return Math.floor( v + EPSILON ) ; | ||
} | ||
// Round with precision | ||
@@ -900,0 +933,0 @@ function round( v , step ) { |
{ | ||
"name": "string-kit", | ||
"version": "0.11.0", | ||
"version": "0.11.1", | ||
"engines": { | ||
@@ -5,0 +5,0 @@ "node": ">=6.0.0" |
@@ -75,2 +75,3 @@ | ||
* `%k` number with metric system prefixes (like k, M, G, and so on...) | ||
* `%m` degrees/minutes/seconds notation | ||
* `%t` time duration, convert ms into H:min:s | ||
@@ -77,0 +78,0 @@ * `%h` unsigned hexadecimal |
@@ -270,2 +270,12 @@ /* | ||
it( "%m degree minute seconds notation" , () => { | ||
expect( format( '%m' , 0 ) ).to.be( '0°' ) ; | ||
expect( format( '%m' , 10 ) ).to.be( '10°' ) ; | ||
expect( format( '%m' , -10 ) ).to.be( '-10°' ) ; | ||
expect( format( '%m' , 1 + 17 / 60 ) ).to.be( '1°17′' ) ; | ||
expect( format( '%m' , 1 + 1 / 60 + 1 / 3600 ) ).to.be( '1°01′01″' ) ; | ||
expect( format( '%m' , 1 + 59 / 60 + 59 / 3600 ) ).to.be( '1°59′59″' ) ; | ||
expect( format( '%m' , - ( 1 + 59 / 60 + 59 / 3600 ) ) ).to.be( '-1°59′59″' ) ; | ||
} ) ; | ||
it( "%n natural" ) ; | ||
@@ -272,0 +282,0 @@ it( "%N more natural" ) ; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
252533
3813
376