ts-optchain
Version:
Optional Chaining for TypeScript
21 lines (20 loc) • 634 B
JavaScript
/**
* Copyright (C) 2019-present, Rimeto, LLC.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Proxy based implementation of optional chaining w/ default values.
*/
function oc(data) {
return new Proxy((function (defaultValue) { return (data == null ? defaultValue : data); }), {
get: function (target, key) {
var obj = target();
return oc(typeof obj === 'object' ? obj[key] : undefined);
},
});
}
exports.oc = oc;
;