https://github.com/s-bhalode/sparkxcel
https://github.com/s-bhalode/sparkxcel
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/s-bhalode/sparkxcel
- Owner: s-bhalode
- License: mit
- Created: 2024-01-16T13:09:25.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-22T17:54:25.000Z (about 2 years ago)
- Last Synced: 2025-07-09T03:06:56.596Z (10 months ago)
- Language: JavaScript
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DTO (Data Transfer Objects)
## Overview
This library was created to solve the problem of taking a data model from a datasource and needing to remove, add, merge, or translate the data model to a similar or completely different object.
There are similar libraries in other languages (DataMapper, DTO(C#), etc). I could never find a solution that allowed me to quickly and easily utilize a couple of different approaches: *projection*, *translation*, and *merging*.
## Getting Started
## Projection
There are two simple ways to project (like a SQL SELECT statement) or simplify an object. I found myself deleting the properties on the object, or using libraries such as lodash to restrict the output. I decided to use Lazy.js for performance reasons.
### Only
Given an array of property names, the resulting object will only contain the supplied properties.
**Example**
```js
let Dto = require('dto');
let model = { name: { first: 'Simran', last: 'Bhalode'}, age: 21, gender: 'Female'};
let result = Dto.take.only(model, ['age', 'gender']);
// result = { age: 21, gender: 'Female' }
```
### Without
Given an array of property names, the resulting object will remove any properties supplied.
**Example**
```js
let Dto = require('dto');
let model = { name: { first: 'Simran', last: 'Bhalode'}, age: 21, gender: 'Female'};
let result = Dto.take.without(model, ['name']);
// result = { age: 21, gender: 'Female' }
```