0.2.4 • Published 4 years ago

moment-range-alias v0.2.4

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

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']
0.2.4

4 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago