firenze-behavior-timestamp

0.4.0 • Public • Published

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

Package Sidebar

Install

npm i firenze-behavior-timestamp

Weekly Downloads

4

Version

0.4.0

License

MIT

Last publish

Collaborators

  • fahad19