This repository has been archived by the owner on Jan 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
theme fallback, general utils file
- Loading branch information
Showing
4 changed files
with
92 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* General utility methods | ||
*/ | ||
|
||
exports = module.exports = { | ||
/** | ||
* Basically like getProperty, different return | ||
* @method hasProperty | ||
* @param ns {string} A period delimited string of the namespace to find, sans root object | ||
* @param obj {object} The root object to search | ||
* @return {boolean} true if property exists, false otherwise | ||
*/ | ||
hasProperty: function (ns, obj) { | ||
if (!ns) { | ||
return obj; | ||
} | ||
var nsArray = ns.split('.'), | ||
nsLen = nsArray.length, | ||
newNs; | ||
|
||
// if nsLen === 0, then obj is just returned | ||
while (nsLen > 0) { | ||
newNs = nsArray.shift(); | ||
if (obj[newNs]) { | ||
obj = obj[newNs]; | ||
} else { | ||
return false; | ||
} | ||
nsLen = nsArray.length; | ||
} | ||
return true; | ||
}, | ||
/** | ||
* Find a namespaced property | ||
* @method getProperty | ||
* @param ns {string} A period delimited string of the namespace to find, sans root object | ||
* @param obj {object} The root object to search | ||
* @return {object} the object, either the namespaced obejct or the root object | ||
*/ | ||
getProperty: function (ns, obj) { | ||
if (!ns) { | ||
return obj; | ||
} | ||
var nsArray = ns.split('.'), | ||
nsLen = nsArray.length, | ||
newNs; | ||
|
||
// if nsLen === 0, then obj is just returned | ||
while (nsLen > 0) { | ||
newNs = nsArray.shift(); | ||
if (obj[newNs]) { | ||
obj = obj[newNs]; | ||
} | ||
nsLen = nsArray.length; | ||
} | ||
return obj; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters