0.1.0 • Published 9 years ago

extract-prop v0.1.0

Weekly downloads
2
License
ISC
Repository
github
Last release
9 years ago

extract-props

Delete a property from an object and return it

Install

npm install extract-prop

Usage

var extractProp = require('extract-prop');

var body = {
	name: 'frank',
	email: 'frank@example.com',
	populate: 'posts'
};

// this value exists in the object
var pop = extractProp(body, 'populate');
// this value doesn't exist in the object, but has a fallback value
var order = extractProp(body, 'order', 'default value');
// this value just doesn't exist in the object
var nonexistent = extractProp(body, 'nonexistent');

console.log(body);
/*
	will log: { name: 'frank', email: 'frank@example.com' }
*/

console.log(pop);
/*
	will log: 'posts'
*/

console.log(order);
/*
	will log: 'default value'
*/

console.log(nonexistent);
/*
	will log: undefined
*/
0.1.0

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago