-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
7,340 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@typescript-eslint"], | ||
"env": { | ||
"es6": true, | ||
"node": true, | ||
"mocha": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"parserOptions": { | ||
"ecmaVersion": 2018, | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"no-console": "off", | ||
"linebreak-style": "off", | ||
"quotes": ["error", "double", { "allowTemplateLiterals": true }], | ||
"keyword-spacing": ["error", { "before": true }], | ||
"space-before-blocks": ["error"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
.nyc_output | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"cache": false, | ||
"check-coverage": true, | ||
"extension": [".ts"], | ||
"include": ["**/src/*.ts"], | ||
"reporter": ["cobertura", "text-summary"], | ||
"statements": 90, | ||
"branches": 90, | ||
"functions": 90, | ||
"lines": 90 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* This method validates a File (input) or an image URL | ||
* @param src - The image to validate, an input File or a local or remote image url | ||
* @param config - an optional config object that defines the method behaviour | ||
* @returns - Returns true for valid images, throws or returns false for invalid images | ||
*/ | ||
export declare const validateImage: (src: string | File, config?: { | ||
throw: boolean; | ||
} | undefined) => Promise<boolean | undefined>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.validateImage = void 0; | ||
/** | ||
* This method validates a File (input) or an image URL | ||
* @param src - The image to validate, an input File or a local or remote image url | ||
* @param config - an optional config object that defines the method behaviour | ||
* @returns - Returns true for valid images, throws or returns false for invalid images | ||
*/ | ||
const validateImage = (src, config) => { | ||
if (typeof window === "undefined") { | ||
throw new Error("Cannot use this utility method in a non browser environment"); | ||
} | ||
let url = ""; | ||
if (typeof src === "string") { | ||
url = src; | ||
} | ||
else { | ||
url = URL.createObjectURL(src); | ||
} | ||
const image = new Image(); | ||
image.src = url; | ||
image.setAttribute("crossOrigin", "anonymous"); | ||
return new Promise((resolve, reject) => { | ||
image.addEventListener("error", () => (config === null || config === void 0 ? void 0 : config.throw) | ||
? reject("The selected media resource is unsuitable") | ||
: resolve(false)); | ||
image.addEventListener("load", () => resolve(true), false); | ||
}); | ||
}; | ||
exports.validateImage = validateImage; |
Oops, something went wrong.