css-time

A tiny library that converts milliseconds to and from CSS time.

css-time.js

A tiny JavaScript library that converts milliseconds to and from CSS time.

npm install css-time
jam install css-time
git clone git@github.com:philbooth/css-time.js.git
var cssTime = require('css-time');
require('css-time', function (cssTime) {
});
<script type="text/javascript" src="css-time.min.js"></script>

Two functions are exported, from and to.

Returns the number of milliseconds represented by the CSS time string passed in the argument.

cssTime.from('500ms'); // returns 500
 
cssTime.from('-1.5s'); // returns -1500

Returns a CSS time string representing the number of milliseconds passed in the argument.

cssTime.to(500); // returns '500ms'
 
cssTime.to(-0.5); // returns '-0.5ms'

The build environment relies on Node.js, NPM, Jake, JSHint, Mocha, Chai and UglifyJS. Assuming that you already have Node.js and NPM set up, you just need to run npm install to install all of the dependencies as listed in package.json.

The unit tests are in test/css-time.js. You can run them with the command npm test or jake test.