0.1.6 • Published 9 years ago
o-shiny v0.1.6
o-shiny
Removes inherited properties, nulls, functions as well as empty strings, arrays and objects from JavaScript objects.
Installation
npm install o-shiny
Usage
Using an object as input
var shine = require('o-shiny');
var object = {
keyA: '',
keyB: {},
keyC: []
keyD: null,
keyE: function() {},
keyF: 'o-shiny'
};
var shinyObject = shine(object);
Result
{
keyF: 'o-shiny'
}
Using a JSON string as input
var json = '{"key": "o-shiny"}';
var shinyObject = shine(json);
Result
{
key: 'o-shiny'
}
Options
By default, shine will remove inherited properties, nulls, functions as well as empty strings, arrays and objects. They may all be individually overriden.
Defaults
var allow = {
hasOwnProperty: true,
nulls: false,
functions: false,
emptyStrings: false,
emptyArrays: false,
emptyObjects: false,
blacklist: [],
whitelist: []
};
blacklist
: an array of keys to remove even if their content is otherwise valid
whitelist
: an array of keys to leave in the resulting object, except if their content is invalid
Tests
mocha