1.2.0 • Published 8 years ago

fetch-dot v1.2.0

Weekly downloads
33
License
-
Repository
github
Last release
8 years ago

fetchDot Build Status Coverage Status

A pure function that allows you to retrieve a member of an object or an array utilizing dot notation. Super useful in situations where your code may not know what the schema of an object will be, but some configuration or user might.

Usage

const obj = {
	test: 'Test property.',
	nestedObj: {
		test: 'A nested test property.'
	},
	arr: [
		'An array item'
	]
};

fetchDot('test', obj);
// 'Test property.'

fetchDot('nestedObj.test', obj);
// 'A nested test property.'

fetchDot('arr[0]', obj);
// 'An array item'

// If a property does not exist (no matter how nested it is), the function will
// simply return undefined
fetchDot('does.not.exist', obj);
// undefined