fetch-dot

1.2.0 • Public • Published

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

Package Sidebar

Install

npm i fetch-dot

Weekly Downloads

75

Version

1.2.0

License

none

Last publish

Collaborators

  • mikemclaren