validate.io-relative-time

1.0.2 • Public • Published

Relative Time

NPM version Build Status Coverage Status Dependencies

Validates if a value is formatted as relative time.

Installation

$ npm install validate.io-relative-time

For 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 true

Notes

  • 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 false

To run the example code from the top-level application directory,

$ node ./examples/index.js

Tests

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 test

All 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-cov

Istanbul creates a ./reports/coverage directory. To access an HTML version of the report,

$ make view-cov

License

MIT license.

Copyright

Copyright © 2014. Athan Reines.

Package Sidebar

Install

npm i validate.io-relative-time

Weekly Downloads

0

Version

1.0.2

License

none

Last publish

Collaborators

  • kgryte