mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2024-06-02 13:39:43 +00:00
19 lines
518 B
JavaScript
19 lines
518 B
JavaScript
|
'use strict';
|
||
|
|
||
|
function safeProperty(test, name, type, defaultValue) {
|
||
|
if (test == null || test == undefined) return defaultValue;
|
||
|
if (typeof test[name] !== type) return defaultValue;
|
||
|
if (typeof test[name] === "string" && test[name] === '') return defaultValue;
|
||
|
return test[name];
|
||
|
}
|
||
|
|
||
|
function safeChoice(test, candidates, defaultValue) {
|
||
|
return candidates.includes(test) ?
|
||
|
test : defaultValue;
|
||
|
}
|
||
|
function safeUrl(test) {
|
||
|
|
||
|
}
|
||
|
|
||
|
module.exports = { safeProperty, safeChoice };
|