Skip to content

Dyljyn/moment-range-alias

Repository files navigation

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

About

A class to convert a `moment-range` into an alias and vice versa

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy