@muft/dot
v1.0.1
Published
dot makes it possible to transform javascript objects using dot notation or array of strings.
Readme
dot makes it possible to transform javascript objects using dot notation or array of strings.
Check examples directory examples
isObj
Test if variable is object or not @Returns Boolan (TRUE | FALSE)
import { isObj } from '@muft/dot'
isObj({foo: 'bar'});
//=> true
isObj([1, 2, 3]);
//=> false
isObj('foo');
//=> falseisEmpty
Test if object is undefined or empty @Returns Boolan (TRUE | FALSE)
import { isEmpty } from '@muft/dot'
isEmpty({foo: 'bar'});
//=> false
isEmpty(undefined);
//=> true
isEmpty({});
//=> truegetPathSegments
Convert dot notation to the array of strings @Returns string[]
import { getPathSegments } from '@muft/dot'
getPathSegments('app.name');
//=> ['app', 'name']get
Parse object values out of dot notation string if value not find the it will returns defalut value. @Returns any
import { get } from '@muft/dot'
const student = {
name: 'Test',
class: {
rank: 1
}
}
get(student, 'name');
//=> Test
get(student, 'class.rank');
//=> 1
get(student, 'class.test', 'defalut');
//=> default
get(student, 'class.test');
//=> nullgetArrayValue
Parse object values out of string array if value not find the it will returns defalut value. @Returns any
import { getArrayValue } from '@muft/dot'
const student = {
name: 'Test',
class: {
rank: 1
}
}
getArrayValue(student, ['name']);
//=> Test
getArrayValue(student, ['class', 'rank']);
//=> 1
getArrayValue(student, ['class', 'test'], 'defalut');
//=> default
getArrayValue(student, ['class', 'test']);
//=> nullContribute
If you would like to contribute to the project, please fork it and send us a pull request. Please add tests for any new features or bug fixes.
Stay in touch
- Author - Aman Khanakia
- Website - https://khanakia.com
License
This Project is MIT licensed.
