44 * @license MIT
55 */
66( function ( undefined ) {
7- 'use strict' ;
7+ 'use strict' ;
88
9- // Node.js support
10- var _ ;
11- var mixins = { } ;
12- if ( typeof module !== 'undefined' && module . exports ) {
13- _ = require ( 'lodash' ) ;
14- module . exports = mixins ;
15- }
16- else {
17- _ = window . _ ;
18- }
9+ // Node.js support
10+ var _ ;
11+ var mixins = { } ;
12+ if ( typeof module !== 'undefined' && module . exports ) {
13+ _ = require ( 'lodash' ) ;
14+ module . exports = mixins ;
15+ }
16+ else {
17+ _ = window . _ ;
18+ }
1919
20- _ . extend ( mixins , {
21- /**
22- * Executes a deep check for the existence of a property in an object tree.
23- * @param {Object } object - The root object of the object tree.
24- * @param {string } propertyPath - The dot separated propertyPath.
25- * @returns {boolean }
26- */
27- deepIn : function ( object , propertyPath ) {
28- var properties = propertyPath . split ( '.' ) ;
29- while ( properties . length ) {
30- var property = properties . shift ( ) ;
31- if ( _ . isObject ( object ) && property in object ) {
32- object = object [ property ] ;
33- }
34- else {
35- return false ;
36- }
37- }
20+ _ . extend ( mixins , {
21+ /**
22+ * Executes a deep check for the existence of a property in an object tree.
23+ * @param {Object } object - The root object of the object tree.
24+ * @param {string } propertyPath - The dot separated propertyPath.
25+ * @returns {boolean }
26+ */
27+ deepIn : function ( object , propertyPath ) {
28+ var properties = propertyPath . split ( '.' ) ;
29+ while ( properties . length ) {
30+ var property = properties . shift ( ) ;
31+ if ( _ . isObject ( object ) && property in object ) {
32+ object = object [ property ] ;
33+ }
34+ else {
35+ return false ;
36+ }
37+ }
3838
39- return true ;
40- } ,
41- /**
42- * Executes a deep check for the existence of a own property in an object tree.
43- * @param {Object } object - The root object of the object tree.
44- * @param {string } propertyPath - The dot separated propertyPath.
45- * @returns {boolean }
46- */
47- deepHas : function ( object , propertyPath ) {
48- var properties = propertyPath . split ( '.' ) ;
49- while ( properties . length ) {
50- var property = properties . shift ( ) ;
51- if ( _ . isObject ( object ) && object . hasOwnProperty ( property ) ) {
52- object = object [ property ] ;
53- }
54- else {
55- return false ;
56- }
57- }
39+ return true ;
40+ } ,
41+ /**
42+ * Executes a deep check for the existence of a own property in an object tree.
43+ * @param {Object } object - The root object of the object tree.
44+ * @param {string } propertyPath - The dot separated propertyPath.
45+ * @returns {boolean }
46+ */
47+ deepHas : function ( object , propertyPath ) {
48+ var properties = propertyPath . split ( '.' ) ;
49+ while ( properties . length ) {
50+ var property = properties . shift ( ) ;
51+ if ( _ . isObject ( object ) && object . hasOwnProperty ( property ) ) {
52+ object = object [ property ] ;
53+ }
54+ else {
55+ return false ;
56+ }
57+ }
5858
59- return true ;
60- } ,
61- /**
62- * Retrieves the value of a property in an object tree.
63- * @param {Object } object - The root object of the object tree.
64- * @param {string } propertyPath - The dot separated propertyPath.
65- * @returns {* } - The value, or undefined if it doesn't exists.
66- */
67- deepGet : function ( object , propertyPath ) {
68- if ( _ . deepIn ( object , propertyPath ) ) {
69- return _ . reduce ( propertyPath . split ( '.' ) , function ( object , property ) {
70- return object [ property ] ;
71- } , object ) ;
72- }
73- else {
74- return undefined ;
75- }
76- } ,
77- /**
78- * Retrieves the own value of a property in an object tree.
79- * @param {Object } object - The root object of the object tree.
80- * @param {string } propertyPath - The dot separated propertyPath.
81- * @returns {* } - The value, or undefined if it doesn't exists.
82- */
83- deepOwn : function ( object , propertyPath ) {
84- if ( _ . deepHas ( object , propertyPath ) ) {
85- return _ . reduce ( propertyPath . split ( '.' ) , function ( object , property ) {
86- return object [ property ] ;
87- } , object ) ;
88- }
89- else {
90- return undefined ;
91- }
92- } ,
93- /**
94- * Sets a value of a property in an object tree. Any missing objects will be created.
95- * @param {Object } object - The root object of the object tree.
96- * @param {string } propertyPath - The dot separated propertyPath.
97- * @param {* } value - The value to set.
98- * @returns {Object } The object.
99- */
100- deepSet : function ( object , propertyPath , value ) {
101- var properties , property , currentObject ;
59+ return true ;
60+ } ,
61+ /**
62+ * Retrieves the value of a property in an object tree.
63+ * @param {Object } object - The root object of the object tree.
64+ * @param {string } propertyPath - The dot separated propertyPath.
65+ * @returns {* } - The value, or undefined if it doesn't exists.
66+ */
67+ deepGet : function ( object , propertyPath ) {
68+ if ( _ . deepIn ( object , propertyPath ) ) {
69+ return _ . reduce ( propertyPath . split ( '.' ) , function ( object , property ) {
70+ return object [ property ] ;
71+ } , object ) ;
72+ }
73+ else {
74+ return undefined ;
75+ }
76+ } ,
77+ /**
78+ * Retrieves the own value of a property in an object tree.
79+ * @param {Object } object - The root object of the object tree.
80+ * @param {string } propertyPath - The dot separated propertyPath.
81+ * @returns {* } - The value, or undefined if it doesn't exists.
82+ */
83+ deepOwn : function ( object , propertyPath ) {
84+ if ( _ . deepHas ( object , propertyPath ) ) {
85+ return _ . reduce ( propertyPath . split ( '.' ) , function ( object , property ) {
86+ return object [ property ] ;
87+ } , object ) ;
88+ }
89+ else {
90+ return undefined ;
91+ }
92+ } ,
93+ /**
94+ * Sets a value of a property in an object tree. Any missing objects will be created.
95+ * @param {Object } object - The root object of the object tree.
96+ * @param {string } propertyPath - The dot separated propertyPath.
97+ * @param {* } value - The value to set.
98+ * @returns {Object } The object.
99+ */
100+ deepSet : function ( object , propertyPath , value ) {
101+ var properties , property , currentObject ;
102102
103- properties = propertyPath . split ( '.' ) ;
104- currentObject = object ;
105- while ( properties . length ) {
106- property = properties . shift ( ) ;
107- if ( ! _ . isObject ( currentObject [ property ] ) ) {
108- currentObject [ property ] = { } ;
109- }
110- if ( ! properties . length ) {
111- currentObject [ property ] = value ;
112- }
113- currentObject = currentObject [ property ] ;
114- }
103+ properties = propertyPath . split ( '.' ) ;
104+ currentObject = object ;
105+ while ( properties . length ) {
106+ property = properties . shift ( ) ;
107+ if ( ! _ . isObject ( currentObject [ property ] ) ) {
108+ currentObject [ property ] = { } ;
109+ }
110+ if ( ! properties . length ) {
111+ currentObject [ property ] = value ;
112+ }
113+ currentObject = currentObject [ property ] ;
114+ }
115115
116- return object ;
117- } ,
118- /**
119- * Executes a deep pluck on an collection of object trees.
120- * @param {Object|Array } collection - The collection of object trees.
121- * @param {string } propertyPath - The dot separated propertyPath.
122- * @returns {Array }
123- */
124- deepPluck : function ( collection , propertyPath ) {
125- return _ . map ( collection , function ( item ) {
126- return _ . deepGetValue ( item , propertyPath ) ;
127- } ) ;
128- }
129- } ) ;
116+ return object ;
117+ } ,
118+ /**
119+ * Executes a deep pluck on an collection of object trees.
120+ * @param {Object|Array } collection - The collection of object trees.
121+ * @param {string } propertyPath - The dot separated propertyPath.
122+ * @returns {Array }
123+ */
124+ deepPluck : function ( collection , propertyPath ) {
125+ return _ . map ( collection , function ( item ) {
126+ return _ . deepGetValue ( item , propertyPath ) ;
127+ } ) ;
128+ }
129+ } ) ;
130130
131- // support pre 1.2.0 function names
132- mixins . deepSetValue = mixins . deepSet ;
133- mixins . deepGetValue = mixins . deepGet ;
134- mixins . deepGetOwnValue = mixins . deepOwn ;
131+ // support pre 1.2.0 function names
132+ mixins . deepSetValue = mixins . deepSet ;
133+ mixins . deepGetValue = mixins . deepGet ;
134+ mixins . deepGetOwnValue = mixins . deepOwn ;
135135
136- _ . mixin ( mixins ) ;
137- } ) ( ) ;
136+ _ . mixin ( mixins ) ;
137+ } ) ( ) ;
0 commit comments