1.0.0 • Published 9 years ago

moment-fp v1.0.0

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

moment-fp

A complete functional wrapper around Moment.js.

npm install moment-fp

View the documentation

Why moment-fp?

  • All functions are curried by default.
  • No mutations of moment objects

Example

import * as _ from 'ramda';

const dates = [
    [2010, 1, 1],
    [2011, 1, 1],
    [2012, 1, 1],
    [2013, 1, 1]
];


/**
 * Using `moment-fp`
 */
import * as M from '../dist/index';

const etc = _.compose(
    _.map(M.format('YYYY-MM-DD')),
    _.reject(_.compose(_.equals(2011), M.year)),
    _.map(M.add(1, 'day')),
    _.map(M.moment)
)(dates);

// [ '2010-02-02', '2012-02-02', '2013-02-02' ]
console.log(etc);


/**
 * Using vanilla moment
 */
import moment from 'moment';

const etc2 = _.compose(
    _.map(momDate => momDate.format('YYYY-MM-DD')),
    _.reject(_.compose(_.equals(2011), momDate => momDate.year())),
    _.map(momDate => momDate.add(1, 'day')),
    _.map(arrDate => moment(arrDate))
)(dates);

// [ '2010-02-02', '2012-02-02', '2013-02-02' ]
console.log(etc2);