mirror of
				https://github.com/fooflington/selfdefined.git
				synced 2025-10-30 21:58:32 +00:00 
			
		
		
		
	update
This commit is contained in:
		
							
								
								
									
										7
									
								
								node_modules/object-path/.npmignore
									
									
									
										generated
									
									
										vendored
									
									
										Executable file
									
								
							
							
						
						
									
										7
									
								
								node_modules/object-path/.npmignore
									
									
									
										generated
									
									
										vendored
									
									
										Executable file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| node_modules | ||||
| .c9revisions | ||||
| .settings | ||||
| .idea | ||||
| npm-debug.log | ||||
| generated | ||||
| coverage | ||||
							
								
								
									
										6
									
								
								node_modules/object-path/.travis.yml
									
									
									
										generated
									
									
										vendored
									
									
										Executable file
									
								
							
							
						
						
									
										6
									
								
								node_modules/object-path/.travis.yml
									
									
									
										generated
									
									
										vendored
									
									
										Executable file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| language: node_js | ||||
| node_js: | ||||
|   - "0.12" | ||||
|   - "0.10" | ||||
|   - "iojs" | ||||
| after_success: "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage" | ||||
							
								
								
									
										21
									
								
								node_modules/object-path/LICENSE
									
									
									
										generated
									
									
										vendored
									
									
										Executable file
									
								
							
							
						
						
									
										21
									
								
								node_modules/object-path/LICENSE
									
									
									
										generated
									
									
										vendored
									
									
										Executable file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| The MIT License (MIT) | ||||
|  | ||||
| Copyright (c) 2013 Mario Casciaro | ||||
|  | ||||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
| of this software and associated documentation files (the "Software"), to deal | ||||
| in the Software without restriction, including without limitation the rights | ||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
| copies of the Software, and to permit persons to whom the Software is | ||||
| furnished to do so, subject to the following conditions: | ||||
|  | ||||
| The above copyright notice and this permission notice shall be included in | ||||
| all copies or substantial portions of the Software. | ||||
|  | ||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||
| THE SOFTWARE. | ||||
							
								
								
									
										110
									
								
								node_modules/object-path/README.md
									
									
									
										generated
									
									
										vendored
									
									
										Executable file
									
								
							
							
						
						
									
										110
									
								
								node_modules/object-path/README.md
									
									
									
										generated
									
									
										vendored
									
									
										Executable file
									
								
							| @@ -0,0 +1,110 @@ | ||||
|  | ||||
|  | ||||
| object-path | ||||
| =========== | ||||
|  | ||||
| Access deep properties using a path | ||||
|  | ||||
| [](http://badge.fury.io/js/object-path) | ||||
| [](https://travis-ci.org/mariocasciaro/object-path) | ||||
| [](https://coveralls.io/r/mariocasciaro/object-path) | ||||
| [](https://david-dm.org/mariocasciaro/object-path#info=devDependencies) | ||||
|  | ||||
|  | ||||
| ## Install | ||||
|  | ||||
| ### Node.js | ||||
|  | ||||
| ``` | ||||
| npm install object-path | ||||
| ``` | ||||
|  | ||||
| ### Browser | ||||
|  | ||||
| ``` | ||||
| bower install object-path | ||||
| ``` | ||||
|  | ||||
| ### Typescript typings | ||||
|  | ||||
| ``` | ||||
| tsd query object-path --action install --save | ||||
| ``` | ||||
|  | ||||
| ## Usage | ||||
|  | ||||
| ```javascript | ||||
|  | ||||
| var obj = { | ||||
|   a: { | ||||
|     b: "d", | ||||
|     c: ["e", "f"] | ||||
|   } | ||||
| }; | ||||
|  | ||||
| var objectPath = require("object-path"); | ||||
|  | ||||
| //get deep property | ||||
| objectPath.get(obj, "a.b");  //returns "d" | ||||
|  | ||||
| //get the first non-undefined value | ||||
| objectPath.coalesce(obj, ['a.z', 'a.d', ['a','b']], 'default'); | ||||
|  | ||||
| //empty a given path (but do not delete it) depending on their type,so it retains reference to objects and arrays. | ||||
| //functions that are not inherited from prototype are set to null. | ||||
| //object instances are considered objects and just own property names are deleted | ||||
| objectPath.empty(obj, 'a.b'); // obj.a.b is now '' | ||||
| objectPath.empty(obj, 'a.c'); // obj.a.c is now [] | ||||
| objectPath.empty(obj, 'a'); // obj.a is now {} | ||||
|  | ||||
| //works also with arrays | ||||
| objectPath.get(obj, "a.c.1");  //returns "f" | ||||
| objectPath.get(obj, ["a","c","1"]);  //returns "f" | ||||
|  | ||||
| //can return a default value with get | ||||
| objectPath.get(obj, ["a.c.b"], "DEFAULT");  //returns "DEFAULT", since a.c.b path doesn't exists, if omitted, returns undefined | ||||
|  | ||||
| //set | ||||
| objectPath.set(obj, "a.h", "m"); // or objectPath.set(obj, ["a","h"], "m"); | ||||
| objectPath.get(obj, "a.h");  //returns "m" | ||||
|  | ||||
| //set will create intermediate object/arrays | ||||
| objectPath.set(obj, "a.j.0.f", "m"); | ||||
|  | ||||
| //will insert values in array | ||||
| objectPath.insert(obj, "a.c", "m", 1); // obj.a.c = ["e", "m", "f"] | ||||
|  | ||||
| //push into arrays (and create intermediate objects/arrays) | ||||
| objectPath.push(obj, "a.k", "o"); | ||||
|  | ||||
| //ensure a path exists (if it doesn't, set the default value you provide) | ||||
| objectPath.ensureExists(obj, "a.k.1", "DEFAULT"); | ||||
|  | ||||
| //deletes a path | ||||
| objectPath.del(obj, "a.b"); // obj.a.b is now undefined | ||||
| objectPath.del(obj, ["a","c",0]); // obj.a.c is now ['f'] | ||||
|  | ||||
| //tests path existence | ||||
| objectPath.has(obj, "a.b"); // true | ||||
| objectPath.has(obj, ["a","d"]); // false | ||||
|  | ||||
| //bind object | ||||
| var model = objectPath({ | ||||
|   a: { | ||||
|     b: "d", | ||||
|     c: ["e", "f"] | ||||
|   } | ||||
| }); | ||||
|  | ||||
| //now any method from above is supported directly w/o passing an object | ||||
| model.get("a.b");  //returns "d" | ||||
| model.get(["a.c.b"], "DEFAULT");  //returns "DEFAULT" | ||||
| model.del("a.b"); // obj.a.b is now undefined | ||||
| model.has("a.b"); // false | ||||
|  | ||||
| ``` | ||||
|  | ||||
| ### Credits | ||||
|  | ||||
| * [Mario Casciaro](https://github.com/mariocasciaro) - Author | ||||
| * [Paulo Cesar](https://github.com/pocesar) - Major contributor | ||||
							
								
								
									
										17
									
								
								node_modules/object-path/bower.json
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								node_modules/object-path/bower.json
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| { | ||||
|   "name": "object-path", | ||||
|   "version": "0.8.2", | ||||
|   "main": "index.js", | ||||
|   "keywords": [ | ||||
|     "deep", | ||||
|     "path", | ||||
|     "access", | ||||
|     "bean", | ||||
|     "object" | ||||
|   ], | ||||
|   "ignore" : [ | ||||
|     "test.js", | ||||
|     "coverage", | ||||
|     "*.yml" | ||||
|   ] | ||||
| } | ||||
							
								
								
									
										22
									
								
								node_modules/object-path/component.json
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								node_modules/object-path/component.json
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | ||||
| { | ||||
|   "name": "object-path", | ||||
|   "description": "Access deep properties using a path", | ||||
|   "version": "0.6.0", | ||||
|   "author": { | ||||
|     "name": "Mario Casciaro" | ||||
|   }, | ||||
|   "homepage": "https://github.com/mariocasciaro/object-path", | ||||
|   "repository": { | ||||
|     "type": "git", | ||||
|     "url": "git://github.com/mariocasciaro/object-path.git" | ||||
|   }, | ||||
|   "main": "index.js", | ||||
|   "scripts": ["index.js"], | ||||
|   "keywords": [ | ||||
|     "deep", | ||||
|     "path", | ||||
|     "access", | ||||
|     "bean" | ||||
|   ], | ||||
|   "license": "MIT" | ||||
| } | ||||
							
								
								
									
										278
									
								
								node_modules/object-path/index.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										278
									
								
								node_modules/object-path/index.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,278 @@ | ||||
| (function (root, factory){ | ||||
|   'use strict'; | ||||
|  | ||||
|   /*istanbul ignore next:cant test*/ | ||||
|   if (typeof module === 'object' && typeof module.exports === 'object') { | ||||
|     module.exports = factory(); | ||||
|   } else if (typeof define === 'function' && define.amd) { | ||||
|     // AMD. Register as an anonymous module. | ||||
|     define([], factory); | ||||
|   } else { | ||||
|     // Browser globals | ||||
|     root.objectPath = factory(); | ||||
|   } | ||||
| })(this, function(){ | ||||
|   'use strict'; | ||||
|  | ||||
|   var | ||||
|     toStr = Object.prototype.toString, | ||||
|     _hasOwnProperty = Object.prototype.hasOwnProperty; | ||||
|  | ||||
|   function isEmpty(value){ | ||||
|     if (!value) { | ||||
|       return true; | ||||
|     } | ||||
|     if (isArray(value) && value.length === 0) { | ||||
|         return true; | ||||
|     } else if (!isString(value)) { | ||||
|         for (var i in value) { | ||||
|             if (_hasOwnProperty.call(value, i)) { | ||||
|                 return false; | ||||
|             } | ||||
|         } | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
|   } | ||||
|  | ||||
|   function toString(type){ | ||||
|     return toStr.call(type); | ||||
|   } | ||||
|  | ||||
|   function isNumber(value){ | ||||
|     return typeof value === 'number' || toString(value) === "[object Number]"; | ||||
|   } | ||||
|  | ||||
|   function isString(obj){ | ||||
|     return typeof obj === 'string' || toString(obj) === "[object String]"; | ||||
|   } | ||||
|  | ||||
|   function isObject(obj){ | ||||
|     return typeof obj === 'object' && toString(obj) === "[object Object]"; | ||||
|   } | ||||
|  | ||||
|   function isArray(obj){ | ||||
|     return typeof obj === 'object' && typeof obj.length === 'number' && toString(obj) === '[object Array]'; | ||||
|   } | ||||
|  | ||||
|   function isBoolean(obj){ | ||||
|     return typeof obj === 'boolean' || toString(obj) === '[object Boolean]'; | ||||
|   } | ||||
|  | ||||
|   function getKey(key){ | ||||
|     var intKey = parseInt(key); | ||||
|     if (intKey.toString() === key) { | ||||
|       return intKey; | ||||
|     } | ||||
|     return key; | ||||
|   } | ||||
|  | ||||
|   function set(obj, path, value, doNotReplace){ | ||||
|     if (isNumber(path)) { | ||||
|       path = [path]; | ||||
|     } | ||||
|     if (isEmpty(path)) { | ||||
|       return obj; | ||||
|     } | ||||
|     if (isString(path)) { | ||||
|       return set(obj, path.split('.').map(getKey), value, doNotReplace); | ||||
|     } | ||||
|     var currentPath = path[0]; | ||||
|  | ||||
|     if (path.length === 1) { | ||||
|       var oldVal = obj[currentPath]; | ||||
|       if (oldVal === void 0 || !doNotReplace) { | ||||
|         obj[currentPath] = value; | ||||
|       } | ||||
|       return oldVal; | ||||
|     } | ||||
|  | ||||
|     if (obj[currentPath] === void 0) { | ||||
|       //check if we assume an array | ||||
|       if(isNumber(path[1])) { | ||||
|         obj[currentPath] = []; | ||||
|       } else { | ||||
|         obj[currentPath] = {}; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     return set(obj[currentPath], path.slice(1), value, doNotReplace); | ||||
|   } | ||||
|  | ||||
|   function del(obj, path) { | ||||
|     if (isNumber(path)) { | ||||
|       path = [path]; | ||||
|     } | ||||
|  | ||||
|     if (isEmpty(obj)) { | ||||
|       return void 0; | ||||
|     } | ||||
|  | ||||
|     if (isEmpty(path)) { | ||||
|       return obj; | ||||
|     } | ||||
|     if(isString(path)) { | ||||
|       return del(obj, path.split('.')); | ||||
|     } | ||||
|  | ||||
|     var currentPath = getKey(path[0]); | ||||
|     var oldVal = obj[currentPath]; | ||||
|  | ||||
|     if(path.length === 1) { | ||||
|       if (oldVal !== void 0) { | ||||
|         if (isArray(obj)) { | ||||
|           obj.splice(currentPath, 1); | ||||
|         } else { | ||||
|           delete obj[currentPath]; | ||||
|         } | ||||
|       } | ||||
|     } else { | ||||
|       if (obj[currentPath] !== void 0) { | ||||
|         return del(obj[currentPath], path.slice(1)); | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     return obj; | ||||
|   } | ||||
|  | ||||
|   var objectPath = function(obj) { | ||||
|     return Object.keys(objectPath).reduce(function(proxy, prop) { | ||||
|       if (typeof objectPath[prop] === 'function') { | ||||
|         proxy[prop] = objectPath[prop].bind(objectPath, obj); | ||||
|       } | ||||
|  | ||||
|       return proxy; | ||||
|     }, {}); | ||||
|   }; | ||||
|  | ||||
|   objectPath.has = function (obj, path) { | ||||
|     if (isEmpty(obj)) { | ||||
|       return false; | ||||
|     } | ||||
|  | ||||
|     if (isNumber(path)) { | ||||
|       path = [path]; | ||||
|     } else if (isString(path)) { | ||||
|       path = path.split('.'); | ||||
|     } | ||||
|  | ||||
|     if (isEmpty(path) || path.length === 0) { | ||||
|       return false; | ||||
|     } | ||||
|  | ||||
|     for (var i = 0; i < path.length; i++) { | ||||
|       var j = path[i]; | ||||
|       if ((isObject(obj) || isArray(obj)) && _hasOwnProperty.call(obj, j)) { | ||||
|         obj = obj[j]; | ||||
|       } else { | ||||
|         return false; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     return true; | ||||
|   }; | ||||
|  | ||||
|   objectPath.ensureExists = function (obj, path, value){ | ||||
|     return set(obj, path, value, true); | ||||
|   }; | ||||
|  | ||||
|   objectPath.set = function (obj, path, value, doNotReplace){ | ||||
|     return set(obj, path, value, doNotReplace); | ||||
|   }; | ||||
|  | ||||
|   objectPath.insert = function (obj, path, value, at){ | ||||
|     var arr = objectPath.get(obj, path); | ||||
|     at = ~~at; | ||||
|     if (!isArray(arr)) { | ||||
|       arr = []; | ||||
|       objectPath.set(obj, path, arr); | ||||
|     } | ||||
|     arr.splice(at, 0, value); | ||||
|   }; | ||||
|  | ||||
|   objectPath.empty = function(obj, path) { | ||||
|     if (isEmpty(path)) { | ||||
|       return obj; | ||||
|     } | ||||
|     if (isEmpty(obj)) { | ||||
|       return void 0; | ||||
|     } | ||||
|  | ||||
|     var value, i; | ||||
|     if (!(value = objectPath.get(obj, path))) { | ||||
|       return obj; | ||||
|     } | ||||
|  | ||||
|     if (isString(value)) { | ||||
|       return objectPath.set(obj, path, ''); | ||||
|     } else if (isBoolean(value)) { | ||||
|       return objectPath.set(obj, path, false); | ||||
|     } else if (isNumber(value)) { | ||||
|       return objectPath.set(obj, path, 0); | ||||
|     } else if (isArray(value)) { | ||||
|       value.length = 0; | ||||
|     } else if (isObject(value)) { | ||||
|       for (i in value) { | ||||
|         if (_hasOwnProperty.call(value, i)) { | ||||
|           delete value[i]; | ||||
|         } | ||||
|       } | ||||
|     } else { | ||||
|       return objectPath.set(obj, path, null); | ||||
|     } | ||||
|   }; | ||||
|  | ||||
|   objectPath.push = function (obj, path /*, values */){ | ||||
|     var arr = objectPath.get(obj, path); | ||||
|     if (!isArray(arr)) { | ||||
|       arr = []; | ||||
|       objectPath.set(obj, path, arr); | ||||
|     } | ||||
|  | ||||
|     arr.push.apply(arr, Array.prototype.slice.call(arguments, 2)); | ||||
|   }; | ||||
|  | ||||
|   objectPath.coalesce = function (obj, paths, defaultValue) { | ||||
|     var value; | ||||
|  | ||||
|     for (var i = 0, len = paths.length; i < len; i++) { | ||||
|       if ((value = objectPath.get(obj, paths[i])) !== void 0) { | ||||
|         return value; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     return defaultValue; | ||||
|   }; | ||||
|  | ||||
|   objectPath.get = function (obj, path, defaultValue){ | ||||
|     if (isNumber(path)) { | ||||
|       path = [path]; | ||||
|     } | ||||
|     if (isEmpty(path)) { | ||||
|       return obj; | ||||
|     } | ||||
|     if (isEmpty(obj)) { | ||||
|       return defaultValue; | ||||
|     } | ||||
|     if (isString(path)) { | ||||
|       return objectPath.get(obj, path.split('.'), defaultValue); | ||||
|     } | ||||
|  | ||||
|     var currentPath = getKey(path[0]); | ||||
|  | ||||
|     if (path.length === 1) { | ||||
|       if (obj[currentPath] === void 0) { | ||||
|         return defaultValue; | ||||
|       } | ||||
|       return obj[currentPath]; | ||||
|     } | ||||
|  | ||||
|     return objectPath.get(obj[currentPath], path.slice(1), defaultValue); | ||||
|   }; | ||||
|  | ||||
|   objectPath.del = function(obj, path) { | ||||
|     return del(obj, path); | ||||
|   }; | ||||
|  | ||||
|   return objectPath; | ||||
| }); | ||||
							
								
								
									
										75
									
								
								node_modules/object-path/package.json
									
									
									
										generated
									
									
										vendored
									
									
										Executable file
									
								
							
							
						
						
									
										75
									
								
								node_modules/object-path/package.json
									
									
									
										generated
									
									
										vendored
									
									
										Executable file
									
								
							| @@ -0,0 +1,75 @@ | ||||
| { | ||||
|   "_args": [ | ||||
|     [ | ||||
|       "object-path@0.9.2", | ||||
|       "/Users/tatiana/selfdefined" | ||||
|     ] | ||||
|   ], | ||||
|   "_from": "object-path@0.9.2", | ||||
|   "_id": "object-path@0.9.2", | ||||
|   "_inBundle": false, | ||||
|   "_integrity": "sha1-D9mnT8X60a45aLWGvaXGMr1sBaU=", | ||||
|   "_location": "/object-path", | ||||
|   "_phantomChildren": {}, | ||||
|   "_requested": { | ||||
|     "type": "version", | ||||
|     "registry": true, | ||||
|     "raw": "object-path@0.9.2", | ||||
|     "name": "object-path", | ||||
|     "escapedName": "object-path", | ||||
|     "rawSpec": "0.9.2", | ||||
|     "saveSpec": null, | ||||
|     "fetchSpec": "0.9.2" | ||||
|   }, | ||||
|   "_requiredBy": [ | ||||
|     "/tfunk" | ||||
|   ], | ||||
|   "_resolved": "https://registry.npmjs.org/object-path/-/object-path-0.9.2.tgz", | ||||
|   "_spec": "0.9.2", | ||||
|   "_where": "/Users/tatiana/selfdefined", | ||||
|   "author": { | ||||
|     "name": "Mario Casciaro" | ||||
|   }, | ||||
|   "bugs": { | ||||
|     "url": "https://github.com/mariocasciaro/object-path/issues" | ||||
|   }, | ||||
|   "description": "Access deep properties using a path", | ||||
|   "devDependencies": { | ||||
|     "chai": "~1.9.1", | ||||
|     "coveralls": "~2.11.1", | ||||
|     "istanbul": "~0.3.0", | ||||
|     "mocha": "~1.20.1", | ||||
|     "mocha-lcov-reporter": "~0.0.1" | ||||
|   }, | ||||
|   "engines": { | ||||
|     "node": ">=0.8.0" | ||||
|   }, | ||||
|   "homepage": "https://github.com/mariocasciaro/object-path", | ||||
|   "keywords": [ | ||||
|     "deep", | ||||
|     "path", | ||||
|     "access", | ||||
|     "bean", | ||||
|     "get", | ||||
|     "property", | ||||
|     "dot", | ||||
|     "prop", | ||||
|     "object", | ||||
|     "obj", | ||||
|     "notation", | ||||
|     "segment", | ||||
|     "value", | ||||
|     "nested", | ||||
|     "key" | ||||
|   ], | ||||
|   "license": "MIT", | ||||
|   "name": "object-path", | ||||
|   "repository": { | ||||
|     "type": "git", | ||||
|     "url": "git://github.com/mariocasciaro/object-path.git" | ||||
|   }, | ||||
|   "scripts": { | ||||
|     "test": "node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha test.js --report html -- -R spec" | ||||
|   }, | ||||
|   "version": "0.9.2" | ||||
| } | ||||
							
								
								
									
										684
									
								
								node_modules/object-path/test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										684
									
								
								node_modules/object-path/test.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,684 @@ | ||||
| var expect = require('chai').expect, | ||||
|   objectPath = require('./index.js'); | ||||
|  | ||||
|  | ||||
| function getTestObj() { | ||||
|   return { | ||||
|     a: 'b', | ||||
|     b: { | ||||
|       c: [], | ||||
|       d: ['a', 'b'], | ||||
|       e: [{},{f: 'g'}], | ||||
|       f: 'i' | ||||
|     } | ||||
|   }; | ||||
| } | ||||
|  | ||||
| describe('get', function() { | ||||
|   it('should return the value under shallow object', function() { | ||||
|     var obj = getTestObj(); | ||||
|     expect(objectPath.get(obj, 'a')).to.be.equal('b'); | ||||
|     expect(objectPath.get(obj, ['a'])).to.be.equal('b'); | ||||
|   }); | ||||
|  | ||||
|   it('should work with number path', function() { | ||||
|     var obj = getTestObj(); | ||||
|     expect(objectPath.get(obj.b.d, 0)).to.be.equal('a'); | ||||
|     expect(objectPath.get(obj.b, 0)).to.be.equal(void 0); | ||||
|   }); | ||||
|  | ||||
|   it('should return the value under deep object', function() { | ||||
|     var obj = getTestObj(); | ||||
|     expect(objectPath.get(obj, 'b.f')).to.be.equal('i'); | ||||
|     expect(objectPath.get(obj, ['b','f'])).to.be.equal('i'); | ||||
|   }); | ||||
|  | ||||
|   it('should return the value under array', function() { | ||||
|     var obj = getTestObj(); | ||||
|     expect(objectPath.get(obj, 'b.d.0')).to.be.equal('a'); | ||||
|     expect(objectPath.get(obj, ['b','d',0])).to.be.equal('a'); | ||||
|   }); | ||||
|  | ||||
|   it('should return the value under array deep', function() { | ||||
|     var obj = getTestObj(); | ||||
|     expect(objectPath.get(obj, 'b.e.1.f')).to.be.equal('g'); | ||||
|     expect(objectPath.get(obj, ['b','e',1,'f'])).to.be.equal('g'); | ||||
|   }); | ||||
|  | ||||
|   it('should return undefined for missing values under object', function() { | ||||
|     var obj = getTestObj(); | ||||
|     expect(objectPath.get(obj, 'a.b')).to.not.exist; | ||||
|     expect(objectPath.get(obj, ['a','b'])).to.not.exist; | ||||
|   }); | ||||
|  | ||||
|   it('should return undefined for missing values under array', function() { | ||||
|     var obj = getTestObj(); | ||||
|     expect(objectPath.get(obj, 'b.d.5')).to.not.exist; | ||||
|     expect(objectPath.get(obj, ['b','d','5'])).to.not.exist; | ||||
|   }); | ||||
|  | ||||
|   it('should return the value under integer-like key', function() { | ||||
|     var obj = { '1a': 'foo' }; | ||||
|     expect(objectPath.get(obj, '1a')).to.be.equal('foo'); | ||||
|     expect(objectPath.get(obj, ['1a'])).to.be.equal('foo'); | ||||
|   }); | ||||
|  | ||||
|   it('should return the default value when the key doesnt exist', function() { | ||||
|     var obj = { '1a': 'foo' }; | ||||
|     expect(objectPath.get(obj, '1b', null)).to.be.equal(null); | ||||
|     expect(objectPath.get(obj, ['1b'], null)).to.be.equal(null); | ||||
|   }); | ||||
|  | ||||
|   it('should return the default value when path is empty', function() { | ||||
|     var obj = { '1a': 'foo' }; | ||||
|     expect(objectPath.get(obj, '', null)).to.be.deep.equal({ '1a': 'foo' }); | ||||
|     expect(objectPath.get(obj, [])).to.be.deep.equal({ '1a': 'foo' }); | ||||
|     expect(objectPath.get({  }, ['1'])).to.be.equal(undefined); | ||||
|   }); | ||||
|  | ||||
|   it('should skip non own properties with isEmpty', function(){ | ||||
|     var Base = function(enabled){ }; | ||||
|     Base.prototype = { | ||||
|       one: { | ||||
|         two: true | ||||
|       } | ||||
|     }; | ||||
|     var Extended = function(){ | ||||
|       Base.call(this,  true); | ||||
|     }; | ||||
|     Extended.prototype = Object.create(Base.prototype); | ||||
|  | ||||
|     var extended = new Extended(); | ||||
|  | ||||
|     expect(objectPath.get(extended, ['one','two'])).to.be.equal(undefined); | ||||
|     extended.enabled = true; | ||||
|  | ||||
|     expect(objectPath.get(extended, 'enabled')).to.be.equal(true); | ||||
|   }); | ||||
| }); | ||||
|  | ||||
|  | ||||
| describe('set', function() { | ||||
|   it('should set value under shallow object', function() { | ||||
|     var obj = getTestObj(); | ||||
|     objectPath.set(obj, 'c', {m: 'o'}); | ||||
|     expect(obj).to.have.deep.property('c.m', 'o'); | ||||
|     obj = getTestObj(); | ||||
|     objectPath.set(obj, ['c'], {m: 'o'}); | ||||
|     expect(obj).to.have.deep.property('c.m', 'o'); | ||||
|   }); | ||||
|  | ||||
|   it('should set value using number path', function() { | ||||
|     var obj = getTestObj(); | ||||
|     objectPath.set(obj.b.d, 0, 'o'); | ||||
|     expect(obj).to.have.deep.property('b.d.0', 'o'); | ||||
|   }); | ||||
|  | ||||
|   it('should set value under deep object', function() { | ||||
|     var obj = getTestObj(); | ||||
|     objectPath.set(obj, 'b.c', 'o'); | ||||
|     expect(obj).to.have.deep.property('b.c', 'o'); | ||||
|     obj = getTestObj(); | ||||
|     objectPath.set(obj, ['b','c'], 'o'); | ||||
|     expect(obj).to.have.deep.property('b.c', 'o'); | ||||
|   }); | ||||
|  | ||||
|   it('should set value under array', function() { | ||||
|     var obj = getTestObj(); | ||||
|     objectPath.set(obj, 'b.e.1.g', 'f'); | ||||
|     expect(obj).to.have.deep.property('b.e.1.g', 'f'); | ||||
|     obj = getTestObj(); | ||||
|     objectPath.set(obj, ['b','e',1,'g'], 'f'); | ||||
|     expect(obj).to.have.deep.property('b.e.1.g', 'f'); | ||||
|   }); | ||||
|  | ||||
|   it('should create intermediate objects', function() { | ||||
|     var obj = getTestObj(); | ||||
|     objectPath.set(obj, 'c.d.e.f', 'l'); | ||||
|     expect(obj).to.have.deep.property('c.d.e.f', 'l'); | ||||
|     obj = getTestObj(); | ||||
|     objectPath.set(obj, ['c','d','e','f'], 'l'); | ||||
|     expect(obj).to.have.deep.property('c.d.e.f', 'l'); | ||||
|   }); | ||||
|  | ||||
|   it('should create intermediate arrays', function() { | ||||
|     var obj = getTestObj(); | ||||
|     objectPath.set(obj, 'c.0.1.m', 'l'); | ||||
|     expect(obj.c).to.be.an('array'); | ||||
|     expect(obj.c[0]).to.be.an('array'); | ||||
|     expect(obj).to.have.deep.property('c.0.1.m', 'l'); | ||||
|     obj = getTestObj(); | ||||
|     objectPath.set(obj, ['c','0', 1,'m'], 'l'); | ||||
|     expect(obj.c).to.be.an('object'); | ||||
|     expect(obj.c[0]).to.be.an('array'); | ||||
|     expect(obj).to.have.deep.property('c.0.1.m', 'l'); | ||||
|   }); | ||||
|  | ||||
|   it('should set value under integer-like key', function() { | ||||
|     var obj = getTestObj(); | ||||
|     objectPath.set(obj, '1a', 'foo'); | ||||
|     expect(obj).to.have.deep.property('1a', 'foo'); | ||||
|     obj = getTestObj(); | ||||
|     objectPath.set(obj, ['1a'], 'foo'); | ||||
|     expect(obj).to.have.deep.property('1a', 'foo'); | ||||
|   }); | ||||
|  | ||||
|   it('should set value under empty array', function() { | ||||
|     var obj = []; | ||||
|     objectPath.set(obj, [0], 'foo'); | ||||
|     expect(obj[0]).to.be.equal('foo'); | ||||
|     obj = []; | ||||
|     objectPath.set(obj, '0', 'foo'); | ||||
|     expect(obj[0]).to.be.equal('foo'); | ||||
|   }); | ||||
| }); | ||||
|  | ||||
|  | ||||
| describe('push', function() { | ||||
|   it('should push value to existing array', function() { | ||||
|     var obj = getTestObj(); | ||||
|     objectPath.push(obj, 'b.c', 'l'); | ||||
|     expect(obj).to.have.deep.property('b.c.0', 'l'); | ||||
|     obj = getTestObj(); | ||||
|     objectPath.push(obj, ['b','c'], 'l'); | ||||
|     expect(obj).to.have.deep.property('b.c.0', 'l'); | ||||
|   }); | ||||
|  | ||||
|   it('should push value to new array', function() { | ||||
|     var obj = getTestObj(); | ||||
|     objectPath.push(obj, 'b.h', 'l'); | ||||
|     expect(obj).to.have.deep.property('b.h.0', 'l'); | ||||
|     obj = getTestObj(); | ||||
|     objectPath.push(obj, ['b','h'], 'l'); | ||||
|     expect(obj).to.have.deep.property('b.h.0', 'l'); | ||||
|   }); | ||||
|  | ||||
|   it('should push value to existing array using number path', function() { | ||||
|     var obj = getTestObj(); | ||||
|     objectPath.push(obj.b.e, 0, 'l'); | ||||
|     expect(obj).to.have.deep.property('b.e.0.0', 'l'); | ||||
|   }); | ||||
|  | ||||
| }); | ||||
|  | ||||
|  | ||||
| describe('ensureExists', function() { | ||||
|   it('should create the path if it does not exists', function() { | ||||
|     var obj = getTestObj(); | ||||
|     var oldVal = objectPath.ensureExists(obj, 'b.g.1.l', 'test'); | ||||
|     expect(oldVal).to.not.exist; | ||||
|     expect(obj).to.have.deep.property('b.g.1.l', 'test'); | ||||
|     oldVal = objectPath.ensureExists(obj, 'b.g.1.l', 'test1'); | ||||
|     expect(oldVal).to.be.equal('test'); | ||||
|     expect(obj).to.have.deep.property('b.g.1.l', 'test'); | ||||
|   }); | ||||
|  | ||||
|  | ||||
|   it('should return the object if path is empty', function() { | ||||
|     var obj = getTestObj(); | ||||
|     expect(objectPath.ensureExists(obj, [], 'test')).to.have.property('a', 'b'); | ||||
|   }); | ||||
|  | ||||
|   it('Issue #26', function() { | ||||
|     var any = {}; | ||||
|     objectPath.ensureExists(any, ['1','1'], {}); | ||||
|     expect(any).to.be.an('object'); | ||||
|     expect(any[1]).to.be.an('object'); | ||||
|     expect(any[1][1]).to.be.an('object'); | ||||
|   }); | ||||
| }); | ||||
|  | ||||
| describe('coalesce', function(){ | ||||
|   it('should return the first non-undefined value', function(){ | ||||
|     var obj = { | ||||
|       should: {have: 'prop'} | ||||
|     }; | ||||
|  | ||||
|     expect(objectPath.coalesce(obj, [ | ||||
|       'doesnt.exist', | ||||
|       ['might','not','exist'], | ||||
|       'should.have' | ||||
|     ])).to.equal('prop'); | ||||
|   }); | ||||
|  | ||||
|   it('should work with falsy values (null, 0, \'\', false)', function(){ | ||||
|     var obj = { | ||||
|       is: { | ||||
|         false: false, | ||||
|         null: null, | ||||
|         empty: '', | ||||
|         zero: 0 | ||||
|       } | ||||
|     }; | ||||
|  | ||||
|     expect(objectPath.coalesce(obj, [ | ||||
|       'doesnt.exist', | ||||
|       'is.zero' | ||||
|     ])).to.equal(0); | ||||
|  | ||||
|     expect(objectPath.coalesce(obj, [ | ||||
|       'doesnt.exist', | ||||
|       'is.false' | ||||
|     ])).to.equal(false); | ||||
|  | ||||
|     expect(objectPath.coalesce(obj, [ | ||||
|       'doesnt.exist', | ||||
|       'is.null' | ||||
|     ])).to.equal(null); | ||||
|  | ||||
|     expect(objectPath.coalesce(obj, [ | ||||
|       'doesnt.exist', | ||||
|       'is.empty' | ||||
|     ])).to.equal(''); | ||||
|   }); | ||||
|  | ||||
|   it('returns defaultValue if no paths found', function(){ | ||||
|     var obj = { | ||||
|       doesnt: 'matter' | ||||
|     }; | ||||
|  | ||||
|     expect(objectPath.coalesce(obj, ['some.inexistant','path',['on','object']], 'false')).to.equal('false'); | ||||
|   }); | ||||
| }); | ||||
|  | ||||
| describe('empty', function(){ | ||||
|   it('should ignore invalid arguments safely', function(){ | ||||
|     var obj = {}; | ||||
|     expect(objectPath.empty()).to.equal(void 0); | ||||
|     expect(objectPath.empty(obj, 'path')).to.equal(void 0); | ||||
|     expect(objectPath.empty(obj, '')).to.equal(obj); | ||||
|  | ||||
|     obj.path = true; | ||||
|  | ||||
|     expect(objectPath.empty(obj, 'inexistant')).to.equal(obj); | ||||
|   }); | ||||
|  | ||||
|   it('should empty each path according to their types', function(){ | ||||
|     function Instance(){ | ||||
|       this.notOwn = true; | ||||
|     } | ||||
|  | ||||
|     /*istanbul ignore next: not part of code */ | ||||
|     Instance.prototype.test = function(){}; | ||||
|     /*istanbul ignore next: not part of code */ | ||||
|     Instance.prototype.arr = []; | ||||
|  | ||||
|     var | ||||
|       obj = { | ||||
|         string: 'some string', | ||||
|         array: ['some','array',[1,2,3]], | ||||
|         number: 21, | ||||
|         boolean: true, | ||||
|         object: { | ||||
|           some:'property', | ||||
|           sub: { | ||||
|             'property': true | ||||
|           } | ||||
|         }, | ||||
|         instance: new Instance() | ||||
|       }; | ||||
|  | ||||
|     /*istanbul ignore next: not part of code */ | ||||
|     obj['function'] = function(){}; | ||||
|  | ||||
|     objectPath.empty(obj, ['array','2']); | ||||
|     expect(obj.array[2]).to.deep.equal([]); | ||||
|  | ||||
|     objectPath.empty(obj, 'object.sub'); | ||||
|     expect(obj.object.sub).to.deep.equal({}); | ||||
|  | ||||
|     objectPath.empty(obj, 'instance.test'); | ||||
|     expect(obj.instance.test).to.equal(null); | ||||
|     expect(Instance.prototype.test).to.be.a('function'); | ||||
|  | ||||
|     objectPath.empty(obj, 'string'); | ||||
|     objectPath.empty(obj, 'number'); | ||||
|     objectPath.empty(obj, 'boolean'); | ||||
|     objectPath.empty(obj, 'function'); | ||||
|     objectPath.empty(obj, 'array'); | ||||
|     objectPath.empty(obj, 'object'); | ||||
|     objectPath.empty(obj, 'instance'); | ||||
|  | ||||
|     expect(obj.string).to.equal(''); | ||||
|     expect(obj.array).to.deep.equal([]); | ||||
|     expect(obj.number).to.equal(0); | ||||
|     expect(obj.boolean).to.equal(false); | ||||
|     expect(obj.object).to.deep.equal({}); | ||||
|     expect(obj.instance.notOwn).to.be.an('undefined'); | ||||
|     expect(obj.instance.arr).to.be.an('array'); | ||||
|     expect(obj['function']).to.equal(null); | ||||
|   }); | ||||
| }); | ||||
|  | ||||
| describe('del', function(){ | ||||
|   it('should return undefined on empty object', function(){ | ||||
|     expect(objectPath.del({}, 'a')).to.equal(void 0); | ||||
|   }); | ||||
|  | ||||
|   it('should work with number path', function(){ | ||||
|     var obj = getTestObj(); | ||||
|     objectPath.del(obj.b.d, 1); | ||||
|     expect(obj.b.d).to.deep.equal(['a']); | ||||
|   }); | ||||
|  | ||||
|   it('should delete deep paths', function(){ | ||||
|     var obj = getTestObj(); | ||||
|  | ||||
|     expect(objectPath.del(obj)).to.be.equal(obj); | ||||
|  | ||||
|     objectPath.set(obj, 'b.g.1.0', 'test'); | ||||
|     objectPath.set(obj, 'b.g.1.1', 'test'); | ||||
|     objectPath.set(obj, 'b.h.az', 'test'); | ||||
|  | ||||
|     expect(obj).to.have.deep.property('b.g.1.0','test'); | ||||
|     expect(obj).to.have.deep.property('b.g.1.1','test'); | ||||
|     expect(obj).to.have.deep.property('b.h.az','test'); | ||||
|  | ||||
|     objectPath.del(obj, 'b.h.az'); | ||||
|     expect(obj).to.not.have.deep.property('b.h.az'); | ||||
|     expect(obj).to.have.deep.property('b.h'); | ||||
|  | ||||
|     objectPath.del(obj, 'b.g.1.1'); | ||||
|     expect(obj).to.not.have.deep.property('b.g.1.1'); | ||||
|     expect(obj).to.have.deep.property('b.g.1.0','test'); | ||||
|  | ||||
|     objectPath.del(obj, ['b','g','1','0']); | ||||
|     expect(obj).to.not.have.deep.property('b.g.1.0'); | ||||
|     expect(obj).to.have.deep.property('b.g.1'); | ||||
|  | ||||
|     expect(objectPath.del(obj, ['b'])).to.not.have.deep.property('b.g'); | ||||
|     expect(obj).to.be.deep.equal({'a':'b'}); | ||||
|   }); | ||||
|  | ||||
|   it('should remove items from existing array', function(){ | ||||
|     var obj = getTestObj(); | ||||
|  | ||||
|     objectPath.del(obj, 'b.d.0'); | ||||
|     expect(obj.b.d).to.have.length(1); | ||||
|     expect(obj.b.d).to.be.deep.equal(['b']); | ||||
|  | ||||
|     objectPath.del(obj, 'b.d.0'); | ||||
|     expect(obj.b.d).to.have.length(0); | ||||
|     expect(obj.b.d).to.be.deep.equal([]); | ||||
|   }); | ||||
|  | ||||
|   it('should skip undefined paths', function(){ | ||||
|     var obj = getTestObj(); | ||||
|  | ||||
|     expect(objectPath.del(obj, 'do.not.exist')).to.be.equal(obj); | ||||
|     expect(objectPath.del(obj, 'a.c')).to.be.equal('b'); | ||||
|   }); | ||||
| }); | ||||
|  | ||||
| describe('insert', function(){ | ||||
|   it('should insert value into existing array', function(){ | ||||
|     var obj = getTestObj(); | ||||
|  | ||||
|     objectPath.insert(obj, 'b.c', 'asdf'); | ||||
|     expect(obj).to.have.deep.property('b.c.0', 'asdf'); | ||||
|     expect(obj).to.not.have.deep.property('b.c.1'); | ||||
|   }); | ||||
|  | ||||
|   it('should create intermediary array', function(){ | ||||
|     var obj = getTestObj(); | ||||
|  | ||||
|     objectPath.insert(obj, 'b.c.0', 'asdf'); | ||||
|     expect(obj).to.have.deep.property('b.c.0.0', 'asdf'); | ||||
|   }); | ||||
|  | ||||
|   it('should insert in another index', function(){ | ||||
|     var obj = getTestObj(); | ||||
|  | ||||
|     objectPath.insert(obj, 'b.d', 'asdf', 1); | ||||
|     expect(obj).to.have.deep.property('b.d.1', 'asdf'); | ||||
|     expect(obj).to.have.deep.property('b.d.0', 'a'); | ||||
|     expect(obj).to.have.deep.property('b.d.2', 'b'); | ||||
|   }); | ||||
|  | ||||
|   it('should handle sparse array', function(){ | ||||
|     var obj = getTestObj(); | ||||
|     obj.b.d = new Array(4); | ||||
|     obj.b.d[0] = 'a'; | ||||
|     obj.b.d[1] = 'b'; | ||||
|  | ||||
|     objectPath.insert(obj, 'b.d', 'asdf', 3); | ||||
|     expect(obj.b.d).to.have.members([ | ||||
|       'a', | ||||
|       'b', | ||||
|       , | ||||
|       , | ||||
|       'asdf' | ||||
|     ]); | ||||
|   }); | ||||
| }); | ||||
|  | ||||
| describe('has', function () { | ||||
|   it('should return false for empty object', function () { | ||||
|     expect(objectPath.has({}, 'a')).to.be.false; | ||||
|   }); | ||||
|  | ||||
|   it('should return false for empty path', function () { | ||||
|     var obj = getTestObj(); | ||||
|     expect(objectPath.has(obj, '')).to.be.false; | ||||
|     expect(objectPath.has(obj, [])).to.be.false; | ||||
|     expect(objectPath.has(obj, [''])).to.be.false; | ||||
|   }); | ||||
|  | ||||
|   it('should test under shallow object', function() { | ||||
|     var obj = getTestObj(); | ||||
|     expect(objectPath.has(obj, 'a')).to.be.true; | ||||
|     expect(objectPath.has(obj, ['a'])).to.be.true; | ||||
|     expect(objectPath.has(obj, 'z')).to.be.false; | ||||
|     expect(objectPath.has(obj, ['z'])).to.be.false; | ||||
|   }); | ||||
|  | ||||
|   it('should work with number path', function() { | ||||
|     var obj = getTestObj(); | ||||
|     expect(objectPath.has(obj.b.d, 0)).to.be.true; | ||||
|     expect(objectPath.has(obj.b, 0)).to.be.false; | ||||
|     expect(objectPath.has(obj.b.d, 10)).to.be.false; | ||||
|     expect(objectPath.has(obj.b, 10)).to.be.false; | ||||
|   }); | ||||
|  | ||||
|   it('should test under deep object', function() { | ||||
|     var obj = getTestObj(); | ||||
|     expect(objectPath.has(obj, 'b.f')).to.be.true; | ||||
|     expect(objectPath.has(obj, ['b','f'])).to.be.true; | ||||
|     expect(objectPath.has(obj, 'b.g')).to.be.false; | ||||
|     expect(objectPath.has(obj, ['b','g'])).to.be.false; | ||||
|   }); | ||||
|  | ||||
|   it('should test value under array', function() { | ||||
|     var obj = getTestObj(); | ||||
|     expect(objectPath.has(obj, 'b.d.0')).to.be.true; | ||||
|     expect(objectPath.has(obj, ['b','d',0])).to.be.true; | ||||
|   }); | ||||
|  | ||||
|   it('should test the value under array deep', function() { | ||||
|     var obj = getTestObj(); | ||||
|     expect(objectPath.has(obj, 'b.e.1.f')).to.be.true; | ||||
|     expect(objectPath.has(obj, ['b','e',1,'f'])).to.be.true; | ||||
|     expect(objectPath.has(obj, 'b.e.1.f.g.h.i')).to.be.false; | ||||
|     expect(objectPath.has(obj, ['b','e',1,'f','g','h','i'])).to.be.false; | ||||
|   }); | ||||
|  | ||||
|   it('should test the value under integer-like key', function() { | ||||
|     var obj = { '1a': 'foo' }; | ||||
|     expect(objectPath.has(obj, '1a')).to.be.true; | ||||
|     expect(objectPath.has(obj, ['1a'])).to.be.true; | ||||
|   }); | ||||
|  | ||||
|   it('should distinct nonexistent key and key = undefined', function() { | ||||
|     var obj = {}; | ||||
|     expect(objectPath.has(obj, 'key')).to.be.false; | ||||
|  | ||||
|     obj.key = undefined; | ||||
|     expect(objectPath.has(obj, 'key')).to.be.true; | ||||
|   }); | ||||
| }); | ||||
|  | ||||
|  | ||||
|  | ||||
| describe('bind object', function () { | ||||
|   // just get one scenario from each feature, so whole functionality is proxied well | ||||
|   it('should return the value under shallow object', function() { | ||||
|     var obj = getTestObj(); | ||||
|     var model = objectPath(obj); | ||||
|     expect(model.get('a')).to.be.equal('b'); | ||||
|     expect(model.get(['a'])).to.be.equal('b'); | ||||
|   }); | ||||
|  | ||||
|   it('should set value under shallow object', function() { | ||||
|     var obj = getTestObj(); | ||||
|     var model = objectPath(obj); | ||||
|     model.set('c', {m: 'o'}); | ||||
|     expect(obj).to.have.deep.property('c.m', 'o'); | ||||
|     obj = getTestObj(); | ||||
|     model = objectPath(obj); | ||||
|     model.set(['c'], {m: 'o'}); | ||||
|     expect(obj).to.have.deep.property('c.m', 'o'); | ||||
|   }); | ||||
|  | ||||
|   it('should push value to existing array', function() { | ||||
|     var obj = getTestObj(); | ||||
|     var model = objectPath(obj); | ||||
|     model.push('b.c', 'l'); | ||||
|     expect(obj).to.have.deep.property('b.c.0', 'l'); | ||||
|     obj = getTestObj(); | ||||
|     model = objectPath(obj); | ||||
|     model.push(['b','c'], 'l'); | ||||
|     expect(obj).to.have.deep.property('b.c.0', 'l'); | ||||
|   }); | ||||
|  | ||||
|   it('should create the path if it does not exists', function() { | ||||
|     var obj = getTestObj(); | ||||
|     var model = objectPath(obj); | ||||
|     var oldVal = model.ensureExists('b.g.1.l', 'test'); | ||||
|     expect(oldVal).to.not.exist; | ||||
|     expect(obj).to.have.deep.property('b.g.1.l', 'test'); | ||||
|     oldVal = model.ensureExists('b.g.1.l', 'test1'); | ||||
|     expect(oldVal).to.be.equal('test'); | ||||
|     expect(obj).to.have.deep.property('b.g.1.l', 'test'); | ||||
|   }); | ||||
|  | ||||
|   it('should return the first non-undefined value', function(){ | ||||
|     var obj = { | ||||
|       should: {have: 'prop'} | ||||
|     }; | ||||
|     var model = objectPath(obj); | ||||
|  | ||||
|     expect(model.coalesce([ | ||||
|       'doesnt.exist', | ||||
|       ['might','not','exist'], | ||||
|       'should.have' | ||||
|     ])).to.equal('prop'); | ||||
|   }); | ||||
|  | ||||
|   it('should empty each path according to their types', function(){ | ||||
|     function Instance(){ | ||||
|       this.notOwn = true; | ||||
|     } | ||||
|  | ||||
|     /*istanbul ignore next: not part of code */ | ||||
|     Instance.prototype.test = function(){}; | ||||
|     /*istanbul ignore next: not part of code */ | ||||
|     Instance.prototype.arr = []; | ||||
|  | ||||
|     var | ||||
|       obj = { | ||||
|         string: 'some string', | ||||
|         array: ['some','array',[1,2,3]], | ||||
|         number: 21, | ||||
|         boolean: true, | ||||
|         object: { | ||||
|           some:'property', | ||||
|           sub: { | ||||
|             'property': true | ||||
|           } | ||||
|         }, | ||||
|         instance: new Instance() | ||||
|       }; | ||||
|  | ||||
|     /*istanbul ignore next: not part of code */ | ||||
|     obj['function'] = function(){}; | ||||
|  | ||||
|     var model = objectPath(obj); | ||||
|  | ||||
|     model.empty(['array','2']); | ||||
|     expect(obj.array[2]).to.deep.equal([]); | ||||
|  | ||||
|     model.empty('object.sub'); | ||||
|     expect(obj.object.sub).to.deep.equal({}); | ||||
|  | ||||
|     model.empty('instance.test'); | ||||
|     expect(obj.instance.test).to.equal(null); | ||||
|     expect(Instance.prototype.test).to.be.a('function'); | ||||
|  | ||||
|     model.empty('string'); | ||||
|     model.empty('number'); | ||||
|     model.empty('boolean'); | ||||
|     model.empty('function'); | ||||
|     model.empty('array'); | ||||
|     model.empty('object'); | ||||
|     model.empty('instance'); | ||||
|  | ||||
|     expect(obj.string).to.equal(''); | ||||
|     expect(obj.array).to.deep.equal([]); | ||||
|     expect(obj.number).to.equal(0); | ||||
|     expect(obj.boolean).to.equal(false); | ||||
|     expect(obj.object).to.deep.equal({}); | ||||
|     expect(obj.instance.notOwn).to.be.an('undefined'); | ||||
|     expect(obj.instance.arr).to.be.an('array'); | ||||
|     expect(obj['function']).to.equal(null); | ||||
|   }); | ||||
|  | ||||
|   it('should delete deep paths', function(){ | ||||
|     var obj = getTestObj(); | ||||
|     var model = objectPath(obj); | ||||
|  | ||||
|     expect(model.del()).to.be.equal(obj); | ||||
|  | ||||
|     model.set('b.g.1.0', 'test'); | ||||
|     model.set('b.g.1.1', 'test'); | ||||
|     model.set('b.h.az', 'test'); | ||||
|  | ||||
|     expect(obj).to.have.deep.property('b.g.1.0','test'); | ||||
|     expect(obj).to.have.deep.property('b.g.1.1','test'); | ||||
|     expect(obj).to.have.deep.property('b.h.az','test'); | ||||
|  | ||||
|     model.del('b.h.az'); | ||||
|     expect(obj).to.not.have.deep.property('b.h.az'); | ||||
|     expect(obj).to.have.deep.property('b.h'); | ||||
|  | ||||
|     model.del('b.g.1.1'); | ||||
|     expect(obj).to.not.have.deep.property('b.g.1.1'); | ||||
|     expect(obj).to.have.deep.property('b.g.1.0','test'); | ||||
|  | ||||
|     model.del(['b','g','1','0']); | ||||
|     expect(obj).to.not.have.deep.property('b.g.1.0'); | ||||
|     expect(obj).to.have.deep.property('b.g.1'); | ||||
|  | ||||
|     expect(model.del(['b'])).to.not.have.deep.property('b.g'); | ||||
|     expect(obj).to.be.deep.equal({'a':'b'}); | ||||
|   }); | ||||
|  | ||||
|   it('should insert value into existing array', function(){ | ||||
|     var obj = getTestObj(); | ||||
|     var model = objectPath(obj); | ||||
|  | ||||
|     model.insert('b.c', 'asdf'); | ||||
|     expect(obj).to.have.deep.property('b.c.0', 'asdf'); | ||||
|     expect(obj).to.not.have.deep.property('b.c.1'); | ||||
|   }); | ||||
|  | ||||
|   it('should test under shallow object', function() { | ||||
|     var obj = getTestObj(); | ||||
|     var model = objectPath(obj); | ||||
|  | ||||
|     expect(model.has('a')).to.be.true; | ||||
|     expect(model.has(['a'])).to.be.true; | ||||
|     expect(model.has('z')).to.be.false; | ||||
|     expect(model.has(['z'])).to.be.false; | ||||
|   }); | ||||
|  | ||||
| }); | ||||
		Reference in New Issue
	
	Block a user
	 tatianamac
					tatianamac