# mongorito-timestamps

> Created and updated timestamps for Mongorito

Latest version **1.0.1** (published 2017-06-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install mongorito-timestamps
pnpm add mongorito-timestamps
yarn add mongorito-timestamps
bun add mongorito-timestamps
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-06-26 |
| First published | 2017-05-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 6 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Vadim Demedes |
| Maintainers | vdemedes |
| Keywords | mongorito, mongorito-plugin |

## Links

- npm: https://www.npmjs.com/package/mongorito-timestamps
- Repository: https://github.com/vadimdemedes/mongorito-timestamps
- Homepage: https://github.com/vadimdemedes/mongorito-timestamps#readme
- Issues: https://github.com/vadimdemedes/mongorito-timestamps/issues
- npm.io page: https://npm.io/package/mongorito-timestamps

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [@temporal-architect/claude-plugin](https://npm.io/package/@temporal-architect/claude-plugin.md) — 335 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2017-06-26
- 1.0.0 — 2017-05-17

## README

# mongorito-timestamps [![Build Status](https://travis-ci.org/vadimdemedes/mongorito-timestamps.svg?branch=master)](https://travis-ci.org/vadimdemedes/mongorito-timestamps)

> Plugin to add "created" and "updated" timestamps for Mongorito models.


## Installation

```
$ npm install --save mongorito-timestamps
```


## Usage

```js
const {Database, Model} = require('mongorito');
const timestamps = require('mongorito-timestamps');

class Post extends Model {}

const db = new Database('localhost/blog');
await db.connect();

db.use(timestamps());
db.register(Post);

const post = new Post({title: 'Hello'});
await post.save();

post.get('created_at');
//=> 2017-05-17T18:02:06.612Z

post.get('updated_at');
//=> same as `created_at`

post.set({title: 'World'});
await post.save();

post.get('created_at');
//=> same as previous `created_at`

post.get('updated_at');
//=> 2017-05-17T18:02:06.971Z
```


## API

### timestamps([options])

Configures and returns a `timestamps` plugin. Accepts an optional `options` object to customize field names and a function, which generates the timestamps.

#### options

##### createdAt

Type: `string`<br>
Default: `created_at`

Name of the field, which stores the date when the document was created. This field doesn't change after the initial creation.

##### updatedAt

Type: `string`<br>
Default: `updated_at`

Name of the field, which stores the date when the document was updated. This field changes on every save of the document.

##### getTimestamp

Type: `function`<br>
Default:

```js
const getTimestamp = () => new Date();
```

Function, which generates a timestamp.


## License

MIT © [Vadim Demedes](https://github.com/vadimdemedes)

---
_Source: https://npm.io/package/mongorito-timestamps · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
