diff --git a/index.js b/index.js index 3a879d4..f8297f5 100644 --- a/index.js +++ b/index.js @@ -2,9 +2,7 @@ const DATA_URL_DEFAULT_MIME_TYPE = 'text/plain'; const DATA_URL_DEFAULT_CHARSET = 'us-ascii'; -const testParameter = (name, filters) => { - return filters.some(filter => filter instanceof RegExp ? filter.test(name) : filter === name); -}; +const testParameter = (name, filters) => filters.some(filter => filter instanceof RegExp ? filter.test(name) : filter === name); const normalizeDataURL = (urlString, {stripHash}) => { const match = /^data:(?[^,]*?),(?[^#]*?)(?:#(?.*))?$/.exec(urlString); @@ -43,7 +41,7 @@ const normalizeDataURL = (urlString, {stripHash}) => { .filter(Boolean); const normalizedMediaType = [ - ...attributes + ...attributes, ]; if (isBase64) { @@ -72,7 +70,7 @@ export default function normalizeUrl(urlString, options) { removeSingleSlash: true, removeDirectoryIndex: false, sortQueryParameters: true, - ...options + ...options, }; urlString = urlString.trim(); diff --git a/index.test-d.ts b/index.test-d.ts index f0175ff..536b93d 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -13,22 +13,22 @@ normalizeUrl('sindresorhus.com/about.html#contact', {stripHash: true}); normalizeUrl('https://sindresorhus.com', {stripProtocol: true}); normalizeUrl('http://www.sindresorhus.com', {stripWWW: false}); normalizeUrl('www.sindresorhus.com?foo=bar&ref=test_ref', { - removeQueryParameters: ['ref', /test/] + removeQueryParameters: ['ref', /test/], }); normalizeUrl('www.sindresorhus.com?foo=bar', { - removeQueryParameters: true + removeQueryParameters: true, }); normalizeUrl('www.sindresorhus.com?foo=bar&utm_medium=test&ref=test_ref', { - removeQueryParameters: false + removeQueryParameters: false, }); normalizeUrl('http://sindresorhus.com/', {removeTrailingSlash: false}); normalizeUrl('http://sindresorhus.com/', {removeSingleSlash: false}); normalizeUrl('www.sindresorhus.com/foo/default.php', { - removeDirectoryIndex: [/^default\.[a-z]+$/, 'foo'] + removeDirectoryIndex: [/^default\.[a-z]+$/, 'foo'], }); normalizeUrl('www.sindresorhus.com?b=two&a=one&c=three', { - sortQueryParameters: false + sortQueryParameters: false, }); normalizeUrl('www.sindresorhus.com/about#:~:text=hello', { - stripTextFragment: false + stripTextFragment: false, }); diff --git a/license b/license index e7af2f7..fa7ceba 100644 --- a/license +++ b/license @@ -1,6 +1,6 @@ MIT License -Copyright (c) Sindre Sorhus (sindresorhus.com) +Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/package.json b/package.json index 4326c5c..2a91d13 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "ava": "^3.15.0", "nyc": "^15.1.0", "tsd": "^0.17.0", - "xo": "^0.40.3" + "xo": "^0.41.0" }, "nyc": { "reporter": [ diff --git a/test.js b/test.js index bb950b3..d19b128 100644 --- a/test.js +++ b/test.js @@ -111,7 +111,7 @@ test('stripWWW option', t => { test('removeQueryParameters option', t => { const options = { stripWWW: false, - removeQueryParameters: [/^utm_\w+/i, 'ref'] + removeQueryParameters: [/^utm_\w+/i, 'ref'], }; t.is(normalizeUrl('www.sindresorhus.com?foo=bar&utm_medium=test'), 'http://sindresorhus.com/?foo=bar'); t.is(normalizeUrl('http://www.sindresorhus.com', options), 'http://www.sindresorhus.com'); @@ -122,7 +122,7 @@ test('removeQueryParameters option', t => { test('removeQueryParameters boolean `true` option', t => { const options = { stripWWW: false, - removeQueryParameters: true + removeQueryParameters: true, }; t.is(normalizeUrl('http://www.sindresorhus.com', options), 'http://www.sindresorhus.com'); @@ -133,7 +133,7 @@ test('removeQueryParameters boolean `true` option', t => { test('removeQueryParameters boolean `false` option', t => { const options = { stripWWW: false, - removeQueryParameters: false + removeQueryParameters: false, }; t.is(normalizeUrl('http://www.sindresorhus.com', options), 'http://www.sindresorhus.com'); @@ -153,7 +153,7 @@ test('forceHttp option with forceHttps', t => { t.throws(() => { normalizeUrl('https://www.sindresorhus.com', {forceHttp: true, forceHttps: true}); }, { - message: 'The `forceHttp` and `forceHttps` options cannot be used together' + message: 'The `forceHttp` and `forceHttps` options cannot be used together', }); }); @@ -231,7 +231,7 @@ test('removeDirectoryIndex option', t => { test('removeTrailingSlash and removeDirectoryIndex options)', t => { const options1 = { removeTrailingSlash: true, - removeDirectoryIndex: true + removeDirectoryIndex: true, }; t.is(normalizeUrl('http://sindresorhus.com/path/', options1), 'http://sindresorhus.com/path'); t.is(normalizeUrl('http://sindresorhus.com/path/index.html', options1), 'http://sindresorhus.com/path'); @@ -240,7 +240,7 @@ test('removeTrailingSlash and removeDirectoryIndex options)', t => { const options2 = { removeTrailingSlash: false, - removeDirectoryIndex: true + removeDirectoryIndex: true, }; t.is(normalizeUrl('http://sindresorhus.com/path/', options2), 'http://sindresorhus.com/path/'); t.is(normalizeUrl('http://sindresorhus.com/path/index.html', options2), 'http://sindresorhus.com/path/'); @@ -249,7 +249,7 @@ test('removeTrailingSlash and removeDirectoryIndex options)', t => { test('sortQueryParameters option', t => { const options1 = { - sortQueryParameters: true + sortQueryParameters: true, }; t.is(normalizeUrl('http://sindresorhus.com/?a=Z&b=Y&c=X&d=W', options1), 'http://sindresorhus.com/?a=Z&b=Y&c=X&d=W'); t.is(normalizeUrl('http://sindresorhus.com/?b=Y&c=X&a=Z&d=W', options1), 'http://sindresorhus.com/?a=Z&b=Y&c=X&d=W'); @@ -257,7 +257,7 @@ test('sortQueryParameters option', t => { t.is(normalizeUrl('http://sindresorhus.com/', options1), 'http://sindresorhus.com'); const options2 = { - sortQueryParameters: false + sortQueryParameters: false, }; t.is(normalizeUrl('http://sindresorhus.com/?a=Z&b=Y&c=X&d=W', options2), 'http://sindresorhus.com/?a=Z&b=Y&c=X&d=W'); t.is(normalizeUrl('http://sindresorhus.com/?b=Y&c=X&a=Z&d=W', options2), 'http://sindresorhus.com/?b=Y&c=X&a=Z&d=W'); @@ -269,19 +269,19 @@ test('invalid urls', t => { t.throws(() => { normalizeUrl('http://'); }, { - message: 'Invalid URL' + message: 'Invalid URL', }); t.throws(() => { normalizeUrl('/'); }, { - message: 'Invalid URL' + message: 'Invalid URL', }); t.throws(() => { normalizeUrl('/relative/path/'); }, { - message: 'Invalid URL' + message: 'Invalid URL', }); }); @@ -309,8 +309,10 @@ test('remove duplicate pathname slashes', t => { test('data URL', t => { // Invalid URL. - t.throws(() => normalizeUrl('data:'), { - message: 'Invalid URL: data:' + t.throws(() => { + normalizeUrl('data:'); + }, { + message: 'Invalid URL: data:', }); // Strip default MIME type @@ -357,7 +359,7 @@ test('data URL', t => { removeQueryParameters: [/^utm_\w+/i, 'ref'], sortQueryParameters: true, removeTrailingSlash: true, - removeDirectoryIndex: true + removeDirectoryIndex: true, }; t.is(normalizeUrl('data:,sindresorhus.com/', options), 'data:,sindresorhus.com/'); t.is(normalizeUrl('data:,sindresorhus.com/index.html', options), 'data:,sindresorhus.com/index.html'); @@ -375,7 +377,7 @@ test('view-source URL', t => { t.throws(() => { normalizeUrl('view-source:https://www.sindresorhus.com'); }, { - message: '`view-source:` is not supported as it is a non-standard protocol' + message: '`view-source:` is not supported as it is a non-standard protocol', }); });