mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-08-17 00:31:42 +02:00
.github
.idea
bld
lib
linux
resources
Content
api
bridge.js
jquery.js
patch.js
ready.js
td.js
utils.js
error
images
introduction
login
notification
plugins
tweetdeck
update
.all.js
bootstrap.js
load.js
Design
Guide
Plugins
..code-workspace
windows
.gitattributes
.gitignore
LICENSE.md
README.md
TweetDuck.sln
TweetDuck.sln.DotSettings
Version.cs
global.json
50 lines
1.0 KiB
JavaScript
50 lines
1.0 KiB
JavaScript
/**
|
|
* Throws if an object is missing any property in the chain.
|
|
* @param {Object} obj
|
|
* @param {...string} chain
|
|
*/
|
|
export function ensurePropertyExists(obj, ...chain) {
|
|
for (const prop of chain) {
|
|
if (obj.hasOwnProperty(prop)) {
|
|
obj = obj[prop];
|
|
}
|
|
else {
|
|
throw "Missing property '" + prop + "' in chain [obj]." + chain.join(".");
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Returns true if an object has every property in the chain.
|
|
* Otherwise, returns false and triggers a debug-only error message.
|
|
* @param {Object} obj
|
|
* @param {...string} chain
|
|
* @returns {boolean}
|
|
*/
|
|
export function checkPropertyExists(obj, ...chain) {
|
|
try {
|
|
ensurePropertyExists(obj, ...chain);
|
|
return true;
|
|
} catch (err) {
|
|
crashDebug(err);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Reports an error to the console, and also shows an error message if in debug mode.
|
|
*/
|
|
export function crashDebug(message) {
|
|
console.error(message);
|
|
debugger;
|
|
|
|
if ("$TD" in window) {
|
|
window.$TD.crashDebug(message);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* No-op function.
|
|
*/
|
|
export function noop() {}
|