Skip to content

Commit 7d4ead2

Browse files
committed
Add stricter type-checking on helper functions
1 parent e19d35e commit 7d4ead2

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

src/components/_helpers/line.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const findMidpoints = ([tuple], index, points) => {
2323
return (tuple + next) / 2;
2424
};
2525

26-
export const normalize = (points, compression = 0, xCeil = 0, yCeil = 0) => {
26+
export const normalize = (points = [], compression = 0, xCeil = 0, yCeil = 0) => {
2727
const [xMax, yMax, xMin, yMin] = points.reduce((accum, elem) => ([
2828
Math.max(elem[0], accum[0]),
2929
Math.max(elem[1], accum[1]),

src/components/_services/drawPath.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const defaultFn = (point) => `L${point.join(',')}`;
66
* @param {Function} transform - (optional) A transformation callback function
77
* @param {Object} payload - (optional) The payload for the transformation function
88
*/
9-
export const drawPath = (points = [], transform = defaultFn, payload) => points
9+
export const drawPath = (points = [], transform = defaultFn, payload = 0) => points
1010
.sort((a, b) => a[0] - b[0]) // Sort the points by X values
1111
.reduce((path, point, index) => (
1212
index
1313
? `${path} ${transform(point, index, points, payload)}`
14-
: `M${point.join(',')}`), []);
14+
: `M${point.join(',')}`), '');

src/components/_services/findCtrlPoint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ export const findCtrlPoint = (smoothing = 0, ...args) => {
3232
outX -= Math.min(Math.abs(smoothing), 1) * proximity;
3333
const outY = slope * outX + intercept;
3434

35-
return [outX, outY];
35+
return [outX || 0, outY || 0];
3636
};

src/components/_transformations/smooth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { findCtrlPoint } from '../_services';
77
* @param {Array.<Array>} points - The entire points array
88
* @param {Number} ratio - (optional) A smoothing ratio, from 0 to 1
99
*/
10-
export const smooth = (point, index, points, ratio = 0) => `S${findCtrlPoint(
10+
export const smooth = (point = [0, 0], index = 0, points = [], ratio = 0) => `S${findCtrlPoint(
1111
ratio,
1212
points[index - 1],
1313
point,

0 commit comments

Comments
 (0)