Dot makes it possible to transform javascript objects using dot notation or array of strings.
Repository
Current version released
5 years ago
Versions
Dot makes it possible to transform javascript objects using dot notation or array of strings.
Check examples directory.
API
isObj
Test if variable is object or not @Returns Boolan (TRUE | FALSE)
import dotObject from "https://deno.land/x/dot/mod.ts"
dotObject.isObj({foo: 'bar'});
//=> true
dotObject.isObj([1, 2, 3]);
//=> true
dotObject.isObj('foo');
//=> falseisEmpty
Test if object is undefined or empty @Returns Boolan (TRUE | FALSE)
import dotObject from "https://deno.land/x/dot/mod.ts"
dotObject.isEmpty({foo: 'bar'});
//=> false
dotObject.isEmpty(undefined);
//=> true
dotObject.isEmpty({});
//=> truegetPathSegments
Convert dot notation to the array of strings @Returns string[]
import dotObject from "https://deno.land/x/dot/mod.ts"
dotObject.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 dotObject from "https://deno.land/x/dot/mod.ts"
const student = {
name: 'Test',
class: {
rank: 1
}
}
dotObject.get(student, 'name');
//=> Test
dotObject.get(student, 'class.rank');
//=> 1
dotObject.get(student, 'class.test', 'defalut');
//=> default
dotObject.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 dotObject from "https://deno.land/x/dot/mod.ts"
const student = {
name: 'Test',
class: {
rank: 1
}
}
dotObject.getArrayValue(student, ['name']);
//=> Test
dotObject.getArrayValue(student, ['class', 'rank']);
//=> 1
dotObject.getArrayValue(student, ['class', 'test'], 'defalut');
//=> default
dotObject.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
Cache RDBMS is MIT licensed.