npm

moment-range-alias
TypeScript icon, indicating that this package has built-in type declarations

0.2.4 • Public • Published

moment-range-alias

How to use

Setup

import { thisOperationFactory } from 'moment-range-alias/dist/operations';

const thisOperation = thisOperationFactory();
/// Or with a custom date to compare with
const thisOperation = thisOperationFactory(moment('2018-01-05'));

const rangeAlias = new RangeAlias()
    .setOperations(thisOperation)

getAlias()

Retrieve the alias of a range

// Compare date: 2018-01-05

const range = moment.range(
    moment('2018-01-01'),
    moment('2018-01-06')
);

rangeAlias.getAlias(range); // returns 'tw'

getRange()

Retrieve a range based on an alias

// Get the range of "t(his) w(eek)"
rangeAlias.getRange('tw');

// Get the range of "t(his) M(onth)"
rangeAlias.getRange('tM');

// Get the range of "t(his) y(ear)"
rangeAlias.getRange('ty');

getAvailableAliases()

Retrieve all possible aliases within a range

const range = moment.range(null, null); // Infinite
const range = moment.range(moment()); // start date
const range = moment.range(null, moment()); // end date
const range = moment.range(moment().startOf('month'), moment()); // start + end date

// Returns array of possible aliases
rangeAlias.getAvailableAliases(range); // ['lM', 'tM', 'lw', 'tw']

Readme

Keywords

none

Package Sidebar

Install

npm i moment-range-alias

Weekly Downloads

0

Version

0.2.4

License

MIT

Unpacked Size

52.2 kB

Total Files

40

Last publish

Collaborators

  • dyljyn