Skip to content

Commit f68f877

Browse files
committed
simpler maybeIdentity
1 parent ca94a09 commit f68f877

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/options.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,18 @@ export function slice(values, type = Array) {
214214
}
215215

216216
// Returns true if any of x, x1, or x2 is not (strictly) undefined.
217-
export function hasX({x, x1, x2}) {
218-
return x !== undefined || x1 !== undefined || x2 !== undefined;
217+
export function hasX(options) {
218+
return options?.x !== undefined || options?.x1 !== undefined || options?.x2 !== undefined;
219219
}
220220

221221
// Returns true if any of y, y1, or y2 is not (strictly) undefined.
222-
export function hasY({y, y1, y2}) {
223-
return y !== undefined || y1 !== undefined || y2 !== undefined;
222+
export function hasY(options) {
223+
return options?.y !== undefined || options?.y1 !== undefined || options?.y2 !== undefined;
224224
}
225225

226226
// Returns true if has x or y, or if interval is not (strictly) undefined.
227227
export function hasXY(options) {
228-
return hasX(options) || hasY(options) || options.interval !== undefined;
228+
return hasX(options) || hasY(options) || options?.interval !== undefined;
229229
}
230230

231231
// Disambiguates an options object (e.g., {y: "x2"}) from a primitive value.

src/transforms/identity.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {hasX, hasY, identity} from "../options.js";
22

3-
export function maybeIdentityX(options = {}, k = "x") {
4-
return hasX(options) ? options : {...options, [k]: identity};
3+
export function maybeIdentityX(options) {
4+
return hasX(options) ? options : {...options, x: identity};
55
}
66

7-
export function maybeIdentityY(options = {}, k = "y") {
8-
return hasY(options) ? options : {...options, [k]: identity};
7+
export function maybeIdentityY(options) {
8+
return hasY(options) ? options : {...options, y: identity};
99
}

0 commit comments

Comments
 (0)