New:Microsoft Teams Notifications Are Now Available in Socket.Learn more →
Get Started

brainspan

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

brainspan

When dealing with units of measure, Brainspan does the thinking so you don't have to.

latest
Source
npmnpm
Version
0.0.2-9
Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

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

API Documentation

https://grizzly-atoms.github.io/brainspan/

NPM

https://www.npmjs.com/package/brainspan

Keywords

duration

FAQs

Package last updated on 13 Mar 2019

Related posts