1.1.4 • Published 6 months ago

@webkrafters/get-property v1.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

get-property

Usage:

import getProperties from '@webkrafters/get-property';
const property = getProperties(data, path, defaultValue?); // => PropertyInfo

Parameters:

Example:

A successful query:

import getProperties from '@webkrafters/get-property';

const source = {
    address: {
        city: 'Test City',
        state: 'My Province'
    },
    matrix: [
        [ [ 0, 3, 1 ], [ 4, 0, 3 ] ],
        [ [ 4, 1, 9 ], [ 7, 4, 9 ] ],
        [ [ 8, 7, 3 ], [ 0, 3, 1 ] ]
    ],
    registered: {
        time: new Date(),
        timezone: 'Eastern Time'
    },
    tags: [ 'test', 'foo', 'bar', 'baz', 'boo', 'tap', 'bak' ]
};

const property = getProperties(
	source,
	'registered.timezone',
	'Mountain Time'
);
// returns property info object => {
// 	_value: 'Eastern Time',
// 	exists: true,
// 	index: NaN,
// 	isSelf: false,
// 	key: 'timezone',
// 	source: {
// 	    time: new Date(),
// 	    timezone: 'Eastern Time'
// 	},
// 	trail: [ 'registered', 'timezone' ],
// 	value: 'Eastern Time'
// }

Example:

An unsuccessful query.

// USING SAME SOURCE OBJECT AS ABOVE USAGE
// ---------------------------------------
const property = getProperties(
	source,
	'matrix[1][0][8]',
	'n.a.'
);
// returns property info object => {
// 	_value: undefined,
// 	exists: false,
// 	index: 8,
// 	isSelf: false,
// 	key: '8',
// 	source: [ 4, 1, 9 ],
// 	trail: [ 'matrix', 1, 0 ],
// 	value: 'n.a.'
// }

License

MIT

1.1.4

6 months ago

1.1.3

6 months ago

1.1.2

1 year ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago