verify-image-url 1.2.3 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Awesome Stickz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # verify-image-url
2
+
3
+ A package to check if a URL is an image URL or not and also get the valid image link from it
4
+
5
+ ## Install
6
+
7
+ ```
8
+ $ npm i verify-image-url
9
+ ```
10
+
11
+ ## Example
12
+
13
+ ```js
14
+ const { verifyImageURL } = require('verify-image-url');
15
+
16
+ await verifyImageURL('https://example.com/example.png');
17
+ // -> { isImage: true, imageURL: 'https://example.com/example.png' }
18
+
19
+ await verifyImageURL('https://example.com/example.png', { timeout: 10000 }); // Sets timeout to 10 seconds, default is 5
20
+
21
+ await verifyImageURL('https://prnt.sc/zrfn0r');
22
+ // -> { isImage: true, imageURL: 'https://image.prntscr.com/image/-ndZGuDMRfu7oDAR-fESzg.png' }
23
+ // This link is from og:image meta tag since prnt.sc is a site where you can upload screenshots and get the web page url from it which isn't your image link but it's in the meta tag
24
+ ```
@@ -1,6 +1,6 @@
1
1
  export declare const verifyImageURL: (url: string, options?: {
2
2
  timeout: number;
3
- } | undefined) => Promise<{
3
+ }) => Promise<{
4
4
  isImage: boolean;
5
5
  imageURL: string;
6
6
  }>;
@@ -11,16 +11,16 @@ const got_1 = __importDefault(require("got"));
11
11
  const verifyImageURL = async (url, options) => {
12
12
  var _a;
13
13
  const getReturnValue = (isImage = false, imageURL = url) => ({ isImage, imageURL });
14
- if (!is_url_1.default(url))
14
+ if (!(0, is_url_1.default)(url))
15
15
  return getReturnValue();
16
16
  try {
17
- const responseBuffer = (await got_1.default(url, { headers: { 'User-Agent': 'got' }, timeout: (_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : 5000 })).rawBody;
18
- const imageType = image_type_1.default(responseBuffer);
17
+ const responseBuffer = (await (0, got_1.default)(url, { headers: { 'User-Agent': 'got' }, timeout: (_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : 5000 })).rawBody;
18
+ const imageType = (0, image_type_1.default)(responseBuffer);
19
19
  if (!(imageType === null || imageType === void 0 ? void 0 : imageType.mime.startsWith('image'))) {
20
20
  if (responseBuffer.includes('og:image')) {
21
21
  const dom = new jsdom_1.JSDOM(responseBuffer);
22
22
  const meta = dom.window.document.querySelector('meta[property="og:image"]');
23
- if (!meta || !meta.content || !is_url_1.default(meta.content))
23
+ if (!meta || !meta.content || !(0, is_url_1.default)(meta.content))
24
24
  return getReturnValue();
25
25
  if (!/^https?:/.test(meta.content)) {
26
26
  if (/^\/\//.test(meta.content))
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "verify-image-url",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "A package to check if a URL is an image URL or not and also get the valid image link from it",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
9
  "prepare": "npm run build"