UNPKG

d3plus-common

Version:

Common functions and methods used across D3plus modules.

18 lines (17 loc) 599 B
/** @function accessor @desc Wraps an object key in a simple accessor function. @param {String} key The key to be returned from each Object passed to the function. @param {*} [def] A default value to be returned if the key is not present. @example <caption>this</caption> accessor("id"); @example <caption>returns this</caption> function(d) { return d["id"]; } */ export default function(key, def) { if (def === void 0) { return function (d) { return d[key]; }; } return function (d) { return d[key] === void 0 ? def : d[key]; }; } //# sourceMappingURL=accessor.js.map