Skip to content

Commit

Permalink
Resolve canvasGradient is undefined in node (#10328)
Browse files Browse the repository at this point in the history
* Resolve canvasgradient is not defined in node

* Remove trailing white space

* export isPaternOrGradient helper with typings

* fix lint failure, single qoute

* Allow for string inputs too to function
  • Loading branch information
LeeLenaleee committed May 3, 2022
1 parent a976504 commit 2c268f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/helpers/helpers.color.js
@@ -1,6 +1,13 @@
import colorLib from '@kurkle/color';

const isPatternOrGradient = (value) => value instanceof CanvasGradient || value instanceof CanvasPattern;
export function isPatternOrGradient(value) {
if (value && typeof value === 'object') {
const type = value.toString();
return type === '[object CanvasPattern]' || type === '[object CanvasGradient]';
}

return false;
}

export function color(value) {
return isPatternOrGradient(value) ? value : colorLib(value);
Expand Down
4 changes: 4 additions & 0 deletions types/helpers/helpers.color.d.ts
@@ -1,3 +1,5 @@
import { AnyObject } from '../basic';

export function color(value: CanvasGradient): CanvasGradient;
export function color(value: CanvasPattern): CanvasPattern;
export function color(
Expand All @@ -8,6 +10,8 @@ export function color(
| [number, number, number, number]
): ColorModel;

export function isPatternOrGradient(value: string | AnyObject): boolean;

export interface ColorModel {
rgbString(): string;
hexString(): string;
Expand Down

0 comments on commit 2c268f0

Please sign in to comment.