@remusao/guess-url-type
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -0,1 +1,13 @@ | ||
# v1.1.1 (Tue Apr 07 2020) | ||
#### :bug: Bug Fix | ||
- Add tests and fix guess-url-type [#115](https://github.com/remusao/mono/pull/115) ([@remusao](https://github.com/remusao)) | ||
#### Authors: 1 | ||
- Rémi ([@remusao](https://github.com/remusao)) | ||
--- | ||
# v1.1.0 (Mon Apr 06 2020) | ||
@@ -2,0 +14,0 @@ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const STYLE_EXTENSIONS = new Set(['css', 'scss']); | ||
const IMAGE_EXTENSIONS = new Set([ | ||
'bmp', | ||
'bmp', | ||
'dib', | ||
'eps', | ||
'gif', | ||
'heic', | ||
'heif', | ||
'ico', | ||
'j2k', | ||
'jfi', | ||
'jfif', | ||
'jif', | ||
'jp2', | ||
'jpe', | ||
'jpeg', | ||
'jpeg', | ||
'jpf', | ||
'jpg', | ||
'jpg', | ||
'jpm', | ||
'jpx', | ||
'mj2', | ||
'png', | ||
'svg', | ||
'svgz', | ||
'tif', | ||
'tiff', | ||
'webp', | ||
]); | ||
const MEDIA_EXTENSIONS = new Set([ | ||
'avi', | ||
'flv', | ||
'mp3', | ||
'mp4', | ||
'wav', | ||
'weba', | ||
'webm', | ||
'wmv', | ||
]); | ||
const SCRIPT_EXTENSIONS = new Set(['js', 'ts', 'jsx', 'esm']); | ||
const DOCUMENT_EXTENSIONS = new Set(['htm', 'html', 'xhtml']); | ||
const FONT_EXTENSIONS = new Set(['woff', 'woff2', 'eot', 'ttf']); | ||
function extname(url) { | ||
let endOfPath = url.length; | ||
// Check for fragment | ||
const indexOfFragment = url.indexOf('#'); | ||
if (indexOfFragment !== -1) { | ||
endOfPath = indexOfFragment; | ||
} | ||
const indexOfQuery = url.indexOf('?'); | ||
if (indexOfQuery !== -1 && indexOfQuery < endOfPath) { | ||
endOfPath = indexOfQuery; | ||
} | ||
let startOfExt = endOfPath - 1; | ||
let code = 0; | ||
for (; startOfExt >= 0; startOfExt -= 1) { | ||
code = url.charCodeAt(startOfExt); | ||
if (((code >= 65 && code <= 90) || | ||
(code >= 97 && code <= 122) || | ||
(code >= 48 && code <= 57)) === false) { | ||
break; | ||
} | ||
} | ||
if (code !== 46 || startOfExt < 0 || endOfPath - startOfExt >= 10) { | ||
return ''; | ||
} | ||
return url.slice(startOfExt + 1, endOfPath); | ||
} | ||
const documents_1 = require("./src/extensions/documents"); | ||
const fonts_1 = require("./src/extensions/fonts"); | ||
const images_1 = require("./src/extensions/images"); | ||
const medias_1 = require("./src/extensions/medias"); | ||
const scripts_1 = require("./src/extensions/scripts"); | ||
const stylesheets_1 = require("./src/extensions/stylesheets"); | ||
const extname_1 = require("./src/extname"); | ||
function getRequestType(url) { | ||
const ext = extname(url); | ||
const ext = extname_1.extname(url); | ||
// Images | ||
if (IMAGE_EXTENSIONS.has(ext) || | ||
if (images_1.EXTENSIONS.has(ext) || | ||
url.startsWith('data:image/') || | ||
@@ -82,16 +19,30 @@ url.startsWith('https://frog.wix.com/bt')) { | ||
// Medias | ||
if (MEDIA_EXTENSIONS.has(ext) || | ||
if (medias_1.EXTENSIONS.has(ext) || | ||
url.startsWith('data:audio/') || | ||
url.startsWith('data:video/')) { | ||
return 'image'; | ||
return 'media'; | ||
} | ||
// Stylesheets | ||
if (STYLE_EXTENSIONS.has(ext) || url.startsWith('data:text/css')) { | ||
if (stylesheets_1.EXTENSIONS.has(ext) || url.startsWith('data:text/css')) { | ||
return 'stylesheet'; | ||
} | ||
// Scripts | ||
if (SCRIPT_EXTENSIONS.has(ext) || | ||
url.startsWith('data:application/javascript') || | ||
url.startsWith('data:text/javascript') || | ||
url.startsWith('data:application/x-javascript') || | ||
if (scripts_1.EXTENSIONS.has(ext) || | ||
(url.startsWith('data:') && | ||
(url.startsWith('data:application/ecmascript') || | ||
url.startsWith('data:application/javascript') || | ||
url.startsWith('data:application/x-ecmascript') || | ||
url.startsWith('data:application/x-javascript') || | ||
url.startsWith('data:text/ecmascript') || | ||
url.startsWith('data:text/javascript') || | ||
url.startsWith('data:text/javascript1.0') || | ||
url.startsWith('data:text/javascript1.1') || | ||
url.startsWith('data:text/javascript1.2') || | ||
url.startsWith('data:text/javascript1.3') || | ||
url.startsWith('data:text/javascript1.4') || | ||
url.startsWith('data:text/javascript1.5') || | ||
url.startsWith('data:text/jscript') || | ||
url.startsWith('data:text/livescript') || | ||
url.startsWith('data:text/x-ecmascript') || | ||
url.startsWith('data:text/x-javascript'))) || | ||
url.startsWith('https://maps.googleapis.com/maps/api/js') || | ||
@@ -102,4 +53,5 @@ url.startsWith('https://www.googletagmanager.com/gtag/js')) { | ||
// Documents | ||
if (DOCUMENT_EXTENSIONS.has(ext) || | ||
if (documents_1.EXTENSIONS.has(ext) || | ||
url.startsWith('data:text/html') || | ||
url.startsWith('data:application/xhtml') || | ||
url.startsWith('https://www.youtube.com/embed/') || | ||
@@ -110,3 +62,3 @@ url === 'https://www.google.ie/gen_204') { | ||
// Fonts | ||
if (FONT_EXTENSIONS.has(ext) || url.startsWith('data:font/')) { | ||
if (fonts_1.EXTENSIONS.has(ext) || url.startsWith('data:font/')) { | ||
return 'font'; | ||
@@ -113,0 +65,0 @@ } |
@@ -1,71 +0,8 @@ | ||
const STYLE_EXTENSIONS = new Set(['css', 'scss']); | ||
const IMAGE_EXTENSIONS = new Set([ | ||
'bmp', | ||
'bmp', | ||
'dib', | ||
'eps', | ||
'gif', | ||
'heic', | ||
'heif', | ||
'ico', | ||
'j2k', | ||
'jfi', | ||
'jfif', | ||
'jif', | ||
'jp2', | ||
'jpe', | ||
'jpeg', | ||
'jpeg', | ||
'jpf', | ||
'jpg', | ||
'jpg', | ||
'jpm', | ||
'jpx', | ||
'mj2', | ||
'png', | ||
'svg', | ||
'svgz', | ||
'tif', | ||
'tiff', | ||
'webp', | ||
]); | ||
const MEDIA_EXTENSIONS = new Set([ | ||
'avi', | ||
'flv', | ||
'mp3', | ||
'mp4', | ||
'wav', | ||
'weba', | ||
'webm', | ||
'wmv', | ||
]); | ||
const SCRIPT_EXTENSIONS = new Set(['js', 'ts', 'jsx', 'esm']); | ||
const DOCUMENT_EXTENSIONS = new Set(['htm', 'html', 'xhtml']); | ||
const FONT_EXTENSIONS = new Set(['woff', 'woff2', 'eot', 'ttf']); | ||
function extname(url) { | ||
let endOfPath = url.length; | ||
// Check for fragment | ||
const indexOfFragment = url.indexOf('#'); | ||
if (indexOfFragment !== -1) { | ||
endOfPath = indexOfFragment; | ||
} | ||
const indexOfQuery = url.indexOf('?'); | ||
if (indexOfQuery !== -1 && indexOfQuery < endOfPath) { | ||
endOfPath = indexOfQuery; | ||
} | ||
let startOfExt = endOfPath - 1; | ||
let code = 0; | ||
for (; startOfExt >= 0; startOfExt -= 1) { | ||
code = url.charCodeAt(startOfExt); | ||
if (((code >= 65 && code <= 90) || | ||
(code >= 97 && code <= 122) || | ||
(code >= 48 && code <= 57)) === false) { | ||
break; | ||
} | ||
} | ||
if (code !== 46 || startOfExt < 0 || endOfPath - startOfExt >= 10) { | ||
return ''; | ||
} | ||
return url.slice(startOfExt + 1, endOfPath); | ||
} | ||
import { EXTENSIONS as DOCUMENT_EXTENSIONS } from './src/extensions/documents'; | ||
import { EXTENSIONS as FONT_EXTENSIONS } from './src/extensions/fonts'; | ||
import { EXTENSIONS as IMAGE_EXTENSIONS } from './src/extensions/images'; | ||
import { EXTENSIONS as MEDIA_EXTENSIONS } from './src/extensions/medias'; | ||
import { EXTENSIONS as SCRIPT_EXTENSIONS } from './src/extensions/scripts'; | ||
import { EXTENSIONS as STYLE_EXTENSIONS } from './src/extensions/stylesheets'; | ||
import { extname } from './src/extname'; | ||
export default function getRequestType(url) { | ||
@@ -83,3 +20,3 @@ const ext = extname(url); | ||
url.startsWith('data:video/')) { | ||
return 'image'; | ||
return 'media'; | ||
} | ||
@@ -92,5 +29,19 @@ // Stylesheets | ||
if (SCRIPT_EXTENSIONS.has(ext) || | ||
url.startsWith('data:application/javascript') || | ||
url.startsWith('data:text/javascript') || | ||
url.startsWith('data:application/x-javascript') || | ||
(url.startsWith('data:') && | ||
(url.startsWith('data:application/ecmascript') || | ||
url.startsWith('data:application/javascript') || | ||
url.startsWith('data:application/x-ecmascript') || | ||
url.startsWith('data:application/x-javascript') || | ||
url.startsWith('data:text/ecmascript') || | ||
url.startsWith('data:text/javascript') || | ||
url.startsWith('data:text/javascript1.0') || | ||
url.startsWith('data:text/javascript1.1') || | ||
url.startsWith('data:text/javascript1.2') || | ||
url.startsWith('data:text/javascript1.3') || | ||
url.startsWith('data:text/javascript1.4') || | ||
url.startsWith('data:text/javascript1.5') || | ||
url.startsWith('data:text/jscript') || | ||
url.startsWith('data:text/livescript') || | ||
url.startsWith('data:text/x-ecmascript') || | ||
url.startsWith('data:text/x-javascript'))) || | ||
url.startsWith('https://maps.googleapis.com/maps/api/js') || | ||
@@ -103,2 +54,3 @@ url.startsWith('https://www.googletagmanager.com/gtag/js')) { | ||
url.startsWith('data:text/html') || | ||
url.startsWith('data:application/xhtml') || | ||
url.startsWith('https://www.youtube.com/embed/') || | ||
@@ -105,0 +57,0 @@ url === 'https://www.google.ie/gen_204') { |
{ | ||
"name": "@remusao/guess-url-type", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Guess type of resource based on its URL", | ||
@@ -30,3 +30,3 @@ "author": "Rémi Berson <remi@cliqz.com>", | ||
"prepack": "yarn run bundle", | ||
"test": "nyc mocha ./dist/cjs/index.test.js" | ||
"test": "nyc mocha --config ../../.mocharc.js" | ||
}, | ||
@@ -43,2 +43,3 @@ "bugs": { | ||
"rimraf": "^3.0.0", | ||
"ts-node": "^8.8.1", | ||
"tslint": "^6.0.0", | ||
@@ -48,3 +49,3 @@ "tslint-config-prettier": "^1.18.0", | ||
}, | ||
"gitHead": "b0dae7f7dc445525ff5c81c8522db6401b9c6c40" | ||
"gitHead": "a41135d1e1a74367c7299b8b363f8dab44af5022" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
255433
60
504
10
1