Skip to content

Commit 536dec8

Browse files
authored
promote boolean to constant (#692)
1 parent 9f9dd9c commit 536dec8

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/options.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ const TypedArray = Object.getPrototypeOf(Uint8Array);
77
const objectToString = Object.prototype.toString;
88

99
// This allows transforms to behave equivalently to channels.
10-
export function valueof(data, value, type) {
11-
const array = type === undefined ? Array : type;
12-
return typeof value === "string" ? array.from(data, field(value))
13-
: typeof value === "function" ? array.from(data, value)
14-
: typeof value === "number" || value instanceof Date ? array.from(data, constant(value))
15-
: value && typeof value.transform === "function" ? arrayify(value.transform(data), type)
16-
: arrayify(value, type); // preserve undefined type
10+
export function valueof(data, value, arrayType) {
11+
const array = arrayType === undefined ? Array : arrayType;
12+
const type = typeof value;
13+
return type === "string" ? array.from(data, field(value))
14+
: type === "function" ? array.from(data, value)
15+
: type === "number" || value instanceof Date || type === "boolean" ? array.from(data, constant(value))
16+
: value && typeof value.transform === "function" ? arrayify(value.transform(data), arrayType)
17+
: arrayify(value, arrayType); // preserve undefined type
1718
}
1819

1920
export const field = name => d => d[name];

0 commit comments

Comments
 (0)