brainspan
Version:
When dealing with units of measure, Brainspan does the thinking so you don't have to.
42 lines (31 loc) • 1.8 kB
Markdown
[](https://badge.fury.io/js/brainspan)
[](https://circleci.com/gh/grizzly-atoms/brainspan)
[](https://codecov.io/gh/grizzly-atoms/brainspan)
[](https://grizzly-atoms.github.io/brainspan/)
# Brainspan
When dealing with units of measure, Brainspan does the thinking so you don't have to. Brainspan was inspired by Rails Rails Numeric and ActiveSupport::Duration.
## Example Usage
### Use with Numeric Mixin:
```
require('brainspan').enableMixins();
(1).month.ago(); // Date representing the timestamp from a month prior to current time
(1).month.fromNow(); // Date representing the timestamp from a month in the future
(2).weeks.before(new Date(0)); // Date representing two weeks before the Unix Epoc
(8).days.after(new Date('2019-03-10')); // Date representing March 18, 2019
```
### If you prefer not to extend the Number prototype:
```
const { Duration } = require('brainspan');
const oneMonth = new Duration(Duration.SECONDS_PER_MONTH);
oneMonth.ago(); // Date representing the timestamp from a month prior to current time
oneMonth.fromNow(); // Date representing the timestamp from a month in the future
const twoWeeks = new Duration(Duration.SECONDS_PER_WEEK * 2);
twoWeeks.before(new Date(0)); // Date representing two weeks before the Unix Epoc
const eightDays = new Duration(Duration.SECONDS_PER_DAY * 8);
eightDays.after(new Date('2019-03-10')); // Date representing March 18, 2019
```
## Links
### API Documentation
https://grizzly-atoms.github.io/brainspan/
### NPM
https://www.npmjs.com/package/brainspan