nl_tokens: ### deep * ( object path [ value [ overwrite ]] ) * Follow a path deep into an object creating intermediate objects or arrays as necessary . If value is specified sets the value of that key if unset . If overwrite is true sets even if the value is already set . Returns the root object on set or the current value on get .
pl_tokens: function ( object , path , value , overwrite ) { overwrite = overwrite || false ; value = value || null ; // Break the path, if it's not already an array. path = underscore . isString ( path ) ? path . split ( '.' ) : underscore . isArray ( path ) ? path : [ ] ; // Get the next step var <mask> = path . shift ( ) ; // Different behavior depending on if we're at the last step if ( path . length ) { // More children, so make sure there's a container at the next level if ( ! object [ part ] ) { object [ part ] = ! underscore . isNaN ( + path [ 0 ] ) ? [ ] : { } ; } // Recurse, returning either the object or the old value var next = underscore . deep ( object [ part ] , path , value , overwrite ) ; return value ? object : next ; } else { // If no value, return the part. if ( ! value ) { return object [ part ] ; } else { object [ part ] = overwrite ? value : ( object [ part ] || value ) ; return object ; } } }