npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

backbone-moment

v1.0.0

Published

Adds a moment.js getter/setter to Backbone.Model

Downloads

7

Readme

Backbone-moment

Travis Status Code Climate Score Coverage Dependency Status

About Backbone-moment

This plugin modifies Backbone.Model adding a convenient getter/setter for date attributes using moment.js

var myModel = new Backbone.Model();

var fooDate = moment('1997-1-1');

myModel.setMoment('fooDate', fooDate, { silent: true });

myModel.get('fooDate'); // returns "1997-01-01T06:00:00+00:00"

moment.isMoment(myModel.getMoment('fooDate')); // is true

// [http://momentjs.com/docs/#/query/is-same/](http://momentjs.com/docs/#/query/is-same/)
myModel.getMoment('fooDate').isSame(fooDate); // is true

Additionally you can use the shorthand moment for getting and setting

var fooDate = moment('1997-1-1');

myModel.moment('fooDate', fooDate, { silent: true });

myModel.moment('fooDate').isSame(fooDate); // is true

You can clear a moment by setting undefined, null, or ````

myModel.moment('fooDate', undefined);

myModel.moment('fooDate'); // returns undefined

Backbone.__moment is a reference to moment. If you have a modified or specially loaded moment, you will need to shim in a copy.

require('backbone-moment');
Backbone.__moment = require('my-moment');

By default backbone-moment stores dates as UTC strings Override Backbone.Model.formatMoment if you need to change this behavior

var MyModel = Backbone.Model.extend({
  formatMoment: function(attr, date){
    return Backbone.__moment(date).utc().format();
  }
});

Project Details

Library Downloads

You can download the latest builds directly from the dist folder above.

Available Packages

Via npm

$ npm install backbone-moment

Via bower

$ bower install backbone-moment

Currently Backbone-moment is available via npm and bower. If you would like add it to another channel, please open an issue.

Changelog

For change logs and release notes, see the changelog file.

Compatibility and Requirements

Backbone-moment supports IE8+ and modern browsers.

Github Issues

Report issues with Backbone-moment, and submit pull requests to fix problems or to create summarized and documented feature requests (preferably with the feature implemented in the pull request).

===

This library is © 2015 Paul Falgout. Distributed under MIT license.