@strongnguyen/oidc-provider
Version:
OAuth 2.0 Authorization Server implementation for Node.js with OpenID Connect
23 lines (19 loc) • 481 B
JavaScript
module.exports = (object, path, defaultValue) => {
const properties = path.split('.');
let current = object;
let result;
try {
properties.forEach((property, i) => {
if (i + 1 === properties.length) {
result = current[property];
}
current = current[property];
});
} catch (err) {
result = undefined;
}
if (typeof result === 'undefined' && typeof defaultValue !== 'undefined') {
return defaultValue;
}
return result;
};