/meteor-ejson-moment

An EJSON custom type for Meteor that allows you to send Moment.js objects via DDP

Primary LanguageJavaScriptMIT LicenseMIT

alon:ejson-moment

Build Status

A Meteor package that adds a Moment.js objects as custom EJSON type.

This allows Moment objects to be transmitted over DDP, which allows you to:

  • publish Moment instances of if you pass them to publish handlers.
  • use Moment instances in the return values or arguments to methods.
  • store Moment instances client-side in Minimongo.
  • allowing your type in reactive variables.

Installation

$ meteor add alon:ejson-moment

Table of Contents

  1. alon:ejson-moment
    1. Installation
    2. Table of Contents
    3. Examples
      1. method call

Examples

var momentInstance = moment();

method call

Server:

Meteor.methods({
  getMoment: function (m) {
    var ret = moment();
    var Moment = ret.constructor;
    var isMoment = m instanceof Moment;

    console.log('called getMoment. The argument is a Moment? %b.', isMoment);
    return ret;
  }
});

Client:

Meteor.call('getMoment', moment(), function (err, result) {
  console.log(result);
});