nl_tokens: Takes a namespace string and fetches that location out from an object / Map . If the namespace doesn t exists it is created then returned . Also allows you to set a value at that namespace ( last parameter ) . @example // will create / fetch within obj : hello : { world : { how : { are : { you : { doing : {} } } } } } autoNamespace ( hello . world . how . are . you . doing obj )
pl_tokens: function autoNamespace ( ns_string , objToSearch , valueToSet ) { //throwTypeErrorIfNotOfType('sjl', 'autoNamespace', 'ns_string', ns_string, String); var parent = objToSearch , shouldSetValue = ! isUndefined ( valueToSet ) , classOfObjToSearch = classOf ( objToSearch ) ; if ( classOfObjToSearch !== _Object && objToSearch instanceof Function === false ) { throw new TypeError ( 'sjl.autoNamespace expects a Constructor or an instance obj to search on.' + 'Value received: `' + classOfObjToSearch + '`.' ) ; } ns_string . split ( '.' ) . forEach ( function ( part , index , parts ) { if ( part in parent === false || isUndefined ( parent [ part ] ) ) { parent [ part ] = { } ; } if ( index === parts . length - 1 && shouldSetValue ) { parent [ part ] = valueToSet ; } <mask> = parent [ part ] ; } ) ; return parent ; }