object-array-path-exists
Determines if the path of an object / array is valid.
This library supports arrays and objects that are nested.
Returns true if path exists. Returns false if path does not exist.
Installing
npm install object-array-path-exists
yarn add object-array-path-exists
Initializing
;var pathExists = ;
Examples
Example set 1 - BASIC
//basic nested objectconst obj1 = country: province: city: "Toronto" ; //valid; //true; //true //invalid; //false; //false;
//basic nested objectconst obj2 = element: batallion: unit: squad: team: "Alpha" ; //valid; //true; //true //invalid; //false; //false
//basic arrayconst arr1 = 1 2 3; //valid; //true; //true //invalid; //false; //false
//basic nested arrayconst arr2 = 1 "2a" "2b" 3 "4a" "4b"; //valid; //true; //true //invalid; //false; //false
Example set 2 - INTERMEDIATE
//nested object - non standard key (bracket notation)const obj3 = "123-country": "123-province": "123-city": "Toronto" ; //valid; //true; //true //invalid (Note: incorrect path formats); //false; //false; //false
//nested object - non standard key (bracket notation)const obj4 = "123-element": "123-batallion": "123-unit": "123-squad": "123-team": "Alpha" ; //valid paths; //true; //true //invalid (Note: incorrect object/array format); //false; //false; //false; //false
Example set 3 - ADVANCED
//object and array combinationconst arrObj1 = id: 0 name: "name 0" id: 1 name: "name 1" ; //valid; //true; //true //invalid; //false; //false
//object and array combinationconst arrObj2 = series: "pokemon" name: firstName: "pika" lastName: "chu" type: "electric" species: "mouse" movies: "movie 0" "movie 1a" "movie 1b" "movie 1c" "movie 2" "movie 3" "movie 4" "movie 5" ; //valid; //true; //true //invalid; //false; //false