Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/umbrellio/object-presenter
Simple, solid object presenters
https://github.com/umbrellio/object-presenter
decorator presenter
Last synced: about 2 months ago
JSON representation
Simple, solid object presenters
- Host: GitHub
- URL: https://github.com/umbrellio/object-presenter
- Owner: umbrellio
- License: mit
- Created: 2018-12-07T15:31:20.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-12-23T10:38:35.000Z (about 4 years ago)
- Last Synced: 2023-12-20T11:02:33.634Z (about 1 year ago)
- Topics: decorator, presenter
- Language: JavaScript
- Size: 28.3 KB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# object-presenter
[![Build Status](https://travis-ci.org/umbrellio/object-presenter.svg?branch=master)](https://travis-ci.org/umbrellio/object-presenter)
[![Coverage Status](https://coveralls.io/repos/github/umbrellio/object-presenter/badge.svg?branch=master)](https://coveralls.io/github/umbrellio/object-presenter?branch=master)Simple, solid object presenters.
## Installation
Install with yarn:
```sh
yarn add object-presenter
# or npm:
npm i -S object-presenter
```## Usage
```js
import ObjectPresenter from 'object-presenter'
import moment from 'moment'class UserPresenter extends ObjectPresenter {
get fullName() {
return `${this.object.firstName} ${this.object.lastName}`
}get birthdate() {
return moment(this.object.birthdate).format('MMM Do YY')
}
}const rawUser = { firstName: 'Elon', lastName: 'Musk', birthdate: 46976100000 }
const user = new UserPresenter(rawUser)console.log(user.fullName) // => Elon Musk
console.log(user.firstName) // => Elon
console.log(user.birthdate) // => Jun 28th 71console.log(user.serialize()) // => { firstName: 'Elon', lastName: 'Musk', fullName: 'Elon Musk', birthdate: 'Jun 28th 71' }
```To use in native ES6, import `object-presenter/es6` instead.
## License
Released under MIT License.
## Authors
Created by Alexander Komarov.