Skip to content
When dealing with units of measure, Brainspan does the thinking so you don't have to.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
__tests__
docs
mixins
.esdoc.json
.eslintignore
.eslintrc.json
.gitignore
.npmignore
.nvmrc
Duration.js
README.md
index.js
package-lock.json
package.json

README.md

npm version CircleCI codecov esdoc

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

You can’t perform that action at this time.