UNPKG

599 BJavaScriptView Raw
1/**
2 @function accessor
3 @desc Wraps an object key in a simple accessor function.
4 @param {String} key The key to be returned from each Object passed to the function.
5 @param {*} [def] A default value to be returned if the key is not present.
6 @example <caption>this</caption>
7accessor("id");
8 @example <caption>returns this</caption>
9function(d) {
10 return d["id"];
11}
12*/
13export default function(key, def) {
14 if (def === void 0) { return function (d) { return d[key]; }; }
15 return function (d) { return d[key] === void 0 ? def : d[key]; };
16}
17
18//# sourceMappingURL=accessor.js.map
\No newline at end of file