0.4.0 • Published 8 years ago

firenze-behavior-timestamp v0.4.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

firenze-behavior-timestamp

Build Status Coverage Status npm Join the chat at https://gitter.im/fahad19/firenze

Timestamp behavior for firenze.js.

Automatically generate timestamps on certain fields, when saving records.

Install it with npm or Bower:

$ npm install --save firenze-behavior-timestamp

$ bower install --save firenze-behavior-timestamp

Contents

What it does

When saving a new model, it will automatically populate timestamp as value on speficied field(s).

For example, when saving a post:

var posts = new Posts();
var post = posts.model({
  title: 'Hello World'
});

post.save().then(function (model) {
  var created = model.get('created'); // `2015-01-01 12:00:00`
});

It will automatically save the value of current timestamp in created field.

Usage

Node.js

With npm:

$ npm install --save firenze-behavior-timestamp

Now you can require it as follows:

var TimestampBehavior = require('firenze-behavior-timestamp');

// create your Database instance...

db.createCollection({
  behaviors: [
    {
      'class': TimestampBehavior,
      options: {
        created: {
          on: 'create'                  // 'create', 'update', or 'always'
          format: 'YYYY-MM-DD HH:mm:ss' // 'object' for Date object, or moment.js format
        }
      }
    }
  ]
});

Browser

Or Bower:

$ bower installl --save firenze-behavior-timestamp

Can be loaded in your HTML page as follows:

<script src="bower_components/firenze/dist/firenze.full.min.js"></script>
<script src="bower_components/moment/min/moment.min.js"></script>
<script src="bower_components/firenze-behavior-timestamp/dist/firenze-behavior-timestamp.min.js"></script>

<script>
  // Timestamp behavior is available in `firenze.TimestampBehavior`
</script>

Testing

Tests are written with mocha, and can be run via npm:

$ npm test

License

MIT © Fahad Ibnay Heylaal

0.4.0

8 years ago

0.3.0

8 years ago

0.2.0

9 years ago