https://github.com/mderazon/object-roomba
Clean your dirty objects
https://github.com/mderazon/object-roomba
Last synced: 6 months ago
JSON representation
Clean your dirty objects
- Host: GitHub
- URL: https://github.com/mderazon/object-roomba
- Owner: mderazon
- Created: 2015-08-18T21:40:47.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T17:50:21.000Z (over 3 years ago)
- Last Synced: 2025-10-11T23:36:03.776Z (10 months ago)
- Language: JavaScript
- Size: 43 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# object-roomba [](https://travis-ci.org/mderazon/object-roomba) [](https://github.com/prettier/prettier)
> Clean your dirty objects
Useful when needing to parse objects from source that doesn't support data types decelerations like csv files etc. Not intended for complex objects
## Usage
```js
const roomba = require('object-roomba');
const schema = {
age: Number,
expiration: Date,
is_active: Boolean,
name: String,
address: input => {
if (!input) {
return null;
}
return input;
}
};
const clean = roomba(schema);
let dirtyObj = {
age: '18',
expiration: '2015-08-17 19:30:30.219',
is_active: 'false',
name: 'Michael D',
address: ''
};
cleanObj = clean(dirtyObj);
console.log(cleanObj);
// {
// age: 18,
// expiration: Mon Aug 17 2015 19:30:30 GMT+0300 (IDT),
// is_active: false,
// name: 'Michael D',
// address: null
// }
```
### Currently only supporting simple types
- String
- Number
- Date
- Boolean
### Options
You can pass options to roomba:
```js
const clean = roomba(opts, schema);
```
Available options are:
- `remove_extra_fields` - By default, fields that are not in the schema are kept untouched, you can remove them from the cleaned obj by setting this to true.