Skip to content

Commit a7fb31f

Browse files
committed
add checks in main package api
1 parent 7ad10c2 commit a7fb31f

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

internal/check.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@ export const checkCanvasOptions = (canvasOptions: any) => {
4242
typeCheck(`canvasOptions.offsetY`, offsetY, ["number", "undefined"]);
4343
}
4444
};
45+
46+
export const checkSvgOptions = (svgOptions: any) => {
47+
typeCheck(`svgOptions`, svgOptions, ["object", "undefined"]);
48+
};

public/blobs.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {genFromOptions} from "../internal/gen";
22
import {renderPath} from "../internal/render/svg";
33
import {renderPath2D} from "../internal/render/canvas";
44
import {mapPoints} from "../internal/util";
5-
import {checkBlobOptions} from "../internal/check";
5+
import {checkBlobOptions, checkCanvasOptions, checkSvgOptions} from "../internal/check";
66

77
export interface BlobOptions {
88
seed: string | number;
@@ -23,7 +23,12 @@ export interface SvgOptions {
2323
}
2424

2525
export const canvasPath = (blobOptions: BlobOptions, canvasOptions: CanvasOptions = {}): Path2D => {
26-
// TODO check options
26+
try {
27+
checkBlobOptions(blobOptions);
28+
checkCanvasOptions(canvasOptions);
29+
} catch (e) {
30+
throw `(blobs2): ${e}`;
31+
}
2732
return renderPath2D(
2833
mapPoints(genFromOptions(blobOptions), ({curr}) => {
2934
curr.x += canvasOptions.offsetX || 0;
@@ -34,7 +39,12 @@ export const canvasPath = (blobOptions: BlobOptions, canvasOptions: CanvasOption
3439
};
3540

3641
export const svg = (blobOptions: BlobOptions, svgOptions: SvgOptions = {}): string => {
37-
// TODO check options
42+
try {
43+
checkBlobOptions(blobOptions);
44+
checkSvgOptions(svgOptions);
45+
} catch (e) {
46+
throw `(blobs2): ${e}`;
47+
}
3848
const path = svgPath(blobOptions);
3949
const size = Math.floor(blobOptions.size);
4050
const fill = svgOptions.fill === undefined ? "#ec576b" : svgOptions.fill;

0 commit comments

Comments
 (0)