Comparing version 0.1.2 to 0.1.3
{ | ||
"name": "css-time", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"author": "Phil Booth <pmbooth@gmail.com>", | ||
@@ -20,2 +20,3 @@ "description": "A tiny library that converts milliseconds to and from CSS time.", | ||
"time", | ||
"milliseconds", | ||
"conversion", | ||
@@ -22,0 +23,0 @@ "convert" |
{ | ||
"name": "css-time", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"author": "Phil Booth <pmbooth@gmail.com>", | ||
@@ -17,2 +17,3 @@ "description": "A tiny library that converts milliseconds to and from CSS time.", | ||
"time", | ||
"milliseconds", | ||
"conversion", | ||
@@ -19,0 +20,0 @@ "convert" |
@@ -59,4 +59,3 @@ # css-time.js | ||
Returns the number of milliseconds | ||
represented by the CSS time string | ||
passed in the argument. | ||
represented by a CSS time string. | ||
@@ -63,0 +62,0 @@ ##### Examples |
@@ -9,3 +9,5 @@ /*globals define, module, window, setTimeout */ | ||
var functions = { | ||
var regex = /^([\-\+]?[0-9]+(\.[0-9]+)?)(m?s)$/, | ||
functions = { | ||
from: from, | ||
@@ -22,17 +24,7 @@ to: to | ||
function from (cssTime) { | ||
verifyCssTime(cssTime); | ||
var matches = regex.exec(cssTime); | ||
if (cssTime.charAt(cssTime.length - 2) === 'm') { | ||
return parseFloat(cssTime.substring(0, cssTime.length - 2)); | ||
} | ||
return parseFloat(cssTime.substring(0, cssTime.length - 1)) * 1000; | ||
return parseFloat(matches[1]) * (matches[3] === 's' ? 1000 : 1); | ||
} | ||
function verifyCssTime (cssTime) { | ||
if (/^[\-\+]?[0-9]+(\.[0-9]+)?m?s$/.test(cssTime) === false) { | ||
throw new Error('Invalid CSS time'); | ||
} | ||
} | ||
// Public function `to`. | ||
@@ -43,11 +35,7 @@ // | ||
function to (milliseconds) { | ||
verifyMilliseconds(milliseconds); | ||
return milliseconds + 'ms'; | ||
} | ||
function verifyMilliseconds (milliseconds) { | ||
if (typeof milliseconds !== 'number' || isNaN(milliseconds)) { | ||
throw new Error('Invalid milliseconds'); | ||
} | ||
return milliseconds + 'ms'; | ||
} | ||
@@ -54,0 +42,0 @@ |
@@ -1,1 +0,1 @@ | ||
(function(){"use strict";function t(t){return n(t),"m"===t.charAt(t.length-2)?parseFloat(t.substring(0,t.length-2)):1e3*parseFloat(t.substring(0,t.length-1))}function n(t){if(/^[\-\+]?[0-9]+(\.[0-9]+)?m?s$/.test(t)===!1)throw Error("Invalid CSS time")}function e(t){return o(t),t+"ms"}function o(t){if("number"!=typeof t||isNaN(t))throw Error("Invalid milliseconds")}function i(){"function"==typeof define&&define.amd?define(["css-time"],r):"object"==typeof module&&null!==module?module.exports=r:window.cssTime=r}var r={from:t,to:e};i()})(); | ||
(function(){"use strict";function e(e){var n=t.exec(e);return parseFloat(n[1])*("s"===n[3]?1e3:1)}function n(e){if("number"!=typeof e||isNaN(e))throw Error("Invalid milliseconds");return e+"ms"}function o(){"function"==typeof define&&define.amd?define(["css-time"],i):"object"==typeof module&&null!==module?module.exports=i:window.cssTime=i}var t=/^([\-\+]?[0-9]+(\.[0-9]+)?)(m?s)$/,i={from:e,to:n};o()})(); |
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
11863
260
114