validate.io-relative-time v1.0.2
Relative Time
Validates if a value is formatted as relative time.
Installation
$ npm install validate.io-relative-timeFor use in the browser, use browserify.
Usage
var isRelativeTime = require( 'validate.io-relative-time' );isRelativeTime( value )
Validates whether an input string is a relative time. Relative times have a time unit (ms, s, m, h, d, w, n, y) and the suffix -ago.
var value = '1s-ago';
var bool = isRelativeTime( value );
// returns trueNotes
The unit for months is `n`.This method first validates that the input `value` is a `string`. For non-string values, the method returns `false`.
Examples
console.log( isRelativeTime( '72000ms-ago' ) );
// returns true
console.log( isRelativeTime( '72s ago' ) );
// returns falseTo run the example code from the top-level application directory,
$ node ./examples/index.jsTests
Unit
Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:
$ make testAll new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-covIstanbul creates a ./reports/coverage directory. To access an HTML version of the report,
$ make view-covLicense
Copyright
Copyright © 2014. Athan Reines.