Skip to content

Commit 07765a0

Browse files
authored
better string coercion (#555)
1 parent 9df1f18 commit 07765a0

File tree

12 files changed

+18
-18
lines changed

12 files changed

+18
-18
lines changed

src/curve.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const curves = new Map([
4646

4747
export function Curve(curve = curveLinear, tension) {
4848
if (typeof curve === "function") return curve; // custom curve
49-
const c = curves.get((curve + "").toLowerCase());
49+
const c = curves.get(`${curve}`.toLowerCase());
5050
if (!c) throw new Error(`unknown curve: ${curve}`);
5151
if (tension !== undefined) {
5252
switch (c) {

src/defined.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function descendingDefined(a, b) {
1313
}
1414

1515
export function nonempty(x) {
16-
return x != null && (x + "") !== "";
16+
return x != null && `${x}` !== "";
1717
}
1818

1919
export function filter(index, ...channels) {

src/mark.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class Mark {
2828
throw new Error(`missing channel value: ${name}`);
2929
}
3030
if (name !== undefined) {
31-
const key = name + "";
31+
const key = `${name}`;
3232
if (key === "__proto__") throw new Error("illegal channel name");
3333
if (names.has(key)) throw new Error(`duplicate channel: ${key}`);
3434
names.add(key);
@@ -49,7 +49,7 @@ export class Mark {
4949
}
5050
const channels = this.channels.map(channel => {
5151
const {name} = channel;
52-
return [name == null ? undefined : name + "", Channel(data, channel)];
52+
return [name == null ? undefined : `${name}`, Channel(data, channel)];
5353
});
5454
if (this.sort != null) channelSort(channels, facetChannels, data, this.sort);
5555
return {index, channels};
@@ -120,7 +120,7 @@ export const field = name => d => d[name];
120120
export const indexOf = (d, i) => i;
121121
export const identity = {transform: d => d};
122122
export const zero = () => 0;
123-
export const string = x => x == null ? x : x + "";
123+
export const string = x => x == null ? x : `${x}`;
124124
export const number = x => x == null ? x : +x;
125125
export const boolean = x => x == null ? x : !!x;
126126
export const first = d => d[0];
@@ -158,7 +158,7 @@ export function maybeKeyword(input, name, allowed) {
158158

159159
// Validates the specified required string against the allowed list of keywords.
160160
export function keyword(input, name, allowed) {
161-
const i = (input + "").toLowerCase();
161+
const i = `${input}`.toLowerCase();
162162
if (!allowed.includes(i)) throw new Error(`invalid ${name}: ${input}`);
163163
return i;
164164
}

src/marks/link.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class Link extends Mark {
4444
c.point(X1[i], Y1[i]);
4545
c.point(X2[i], Y2[i]);
4646
c.lineEnd();
47-
return p + "";
47+
return `${p}`;
4848
})
4949
.call(applyChannelStyles, channels))
5050
.node();

src/scales/quantitative.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const interpolators = new Map([
3939
]);
4040

4141
export function Interpolator(interpolate) {
42-
const i = (interpolate + "").toLowerCase();
42+
const i = `${interpolate}`.toLowerCase();
4343
if (!interpolators.has(i)) throw new Error(`unknown interpolator: ${i}`);
4444
return interpolators.get(i);
4545
}

src/scales/schemes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function schemei(interpolate) {
171171
}
172172

173173
export function ordinalScheme(scheme) {
174-
const s = (scheme + "").toLowerCase();
174+
const s = `${scheme}`.toLowerCase();
175175
if (!ordinalSchemes.has(s)) throw new Error(`unknown scheme: ${s}`);
176176
return ordinalSchemes.get(s);
177177
}
@@ -235,7 +235,7 @@ const quantitativeSchemes = new Map([
235235
]);
236236

237237
export function quantitativeScheme(scheme) {
238-
const s = (scheme + "").toLowerCase();
238+
const s = `${scheme}`.toLowerCase();
239239
if (!quantitativeSchemes.has(s)) throw new Error(`unknown scheme: ${s}`);
240240
return quantitativeSchemes.get(s);
241241
}

src/transforms/group.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export function maybeGroup(I, X) {
178178
export function maybeReduce(reduce, value) {
179179
if (reduce && typeof reduce.reduce === "function") return reduce;
180180
if (typeof reduce === "function") return reduceFunction(reduce);
181-
switch ((reduce + "").toLowerCase()) {
181+
switch (`${reduce}`.toLowerCase()) {
182182
case "first": return reduceFirst;
183183
case "last": return reduceLast;
184184
case "count": return reduceCount;

src/transforms/map.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function map(outputs = {}, options = {}) {
4141
function maybeMap(map) {
4242
if (map && typeof map.map === "function") return map;
4343
if (typeof map === "function") return mapFunction(map);
44-
switch ((map + "").toLowerCase()) {
44+
switch (`${map}`.toLowerCase()) {
4545
case "cumsum": return mapCumsum;
4646
}
4747
throw new Error("invalid map");

src/transforms/normalize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function normalizeY(basis, options) {
1616
export function normalize(basis) {
1717
if (basis === undefined) return normalizeFirst;
1818
if (typeof basis === "function") return normalizeBasis((I, S) => basis(take(S, I)));
19-
switch ((basis + "").toLowerCase()) {
19+
switch (`${basis}`.toLowerCase()) {
2020
case "first": return normalizeFirst;
2121
case "last": return normalizeLast;
2222
case "mean": return normalizeMean;

src/transforms/stack.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function stack(x, y = () => 1, ky, {offset, order, reverse}, options) {
124124

125125
function maybeOffset(offset) {
126126
if (offset == null) return;
127-
switch ((offset + "").toLowerCase()) {
127+
switch (`${offset}`.toLowerCase()) {
128128
case "expand": case "normalize": return offsetExpand;
129129
case "center": case "silhouette": return offsetCenter;
130130
case "wiggle": return offsetWiggle;

0 commit comments

Comments
 (0)