@livechat/url-utils
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -32,3 +32,2 @@ 'use strict'; | ||
var originRegexp = /[^:]+:\/\/[^(/|?)\s]+/; | ||
var getOrigin = function getOrigin(url) { | ||
@@ -40,3 +39,2 @@ var domain = url.match(originRegexp); | ||
var searchRegexp = /.*?\?([^#]+)/; | ||
var getSearch = function getSearch(url) { | ||
@@ -55,3 +53,2 @@ var match = url.match(searchRegexp); | ||
} | ||
var search = trimSearch(getSearch(urlOrSearch)); | ||
@@ -66,3 +63,2 @@ return search ? decodeQueryString(search) : {}; | ||
var pathnameRegexp = /^(?:https?:)?\/\/[^/]+\/([^?#]+)/; | ||
var getPathname = function getPathname(url) { | ||
@@ -84,7 +80,6 @@ var pathname = url.match(pathnameRegexp); | ||
}; | ||
var unsafeProtocol = new RegExp("^[\0-\x1F]*(" + intersperseWithTabOrNewline('javascript') + "|" + intersperseWithTabOrNewline('data') + "):", 'i'); // would be better to filter safe things | ||
var unsafeProtocol = new RegExp("^[\0-\x1F]*(" + intersperseWithTabOrNewline('javascript') + "|" + intersperseWithTabOrNewline('data') + "):", 'i'); | ||
// would be better to filter safe things | ||
// but people might paste in protocolless URLs | ||
// and we would filter them out | ||
var hasUnsafeProtocol = function hasUnsafeProtocol(url) { | ||
@@ -95,3 +90,2 @@ return unsafeProtocol.test(url); | ||
var protocolRegexp = /^((http(s)?:)?\/\/)/; | ||
var removeProtocol = function removeProtocol(url) { | ||
@@ -102,3 +96,2 @@ return url.replace(protocolRegexp, ''); | ||
var protocolRegexp$1 = /^((http(s)?:)?\/\/)/; | ||
var getProtocol = function getProtocol(url) { | ||
@@ -110,6 +103,5 @@ var match = url.match(protocolRegexp$1); | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
_extends = Object.assign ? Object.assign.bind() : function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
@@ -121,6 +113,4 @@ if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
@@ -133,3 +123,2 @@ } | ||
} | ||
var urlOrigin = getOrigin(url); | ||
@@ -146,9 +135,6 @@ var urlPath = getPathname(url); | ||
} | ||
var params = getQueryParams(url); | ||
if (dataUtils.isEmpty(params)) { | ||
return url; | ||
} | ||
if (Object.keys(params).every(function (paramKey) { | ||
@@ -159,21 +145,21 @@ return !paramsToRemove.includes(paramKey); | ||
} | ||
paramsToRemove.forEach(function (param) { | ||
return delete params[param]; | ||
}); | ||
var _url$split = url.split('?'), | ||
querylessURL = _url$split[0]; | ||
querylessURL = _url$split[0]; | ||
var extendedURL = extendURLByQueryParams(querylessURL, params); | ||
if (url.indexOf('#') > -1) { | ||
return extendedURL + "#" + url.split('#')[1]; | ||
} | ||
return extendedURL; | ||
}; | ||
var ensureSecureProtocol = function ensureSecureProtocol(url) { | ||
return "https://" + removeProtocol(url); | ||
}; | ||
exports.buildQueryString = buildQueryString; | ||
exports.decodeQueryString = decodeQueryString; | ||
exports.ensureSecureProtocol = ensureSecureProtocol; | ||
exports.extendURLByQueryParams = extendURLByQueryParams; | ||
@@ -180,0 +166,0 @@ exports.getHostname = getHostname; |
@@ -28,3 +28,2 @@ import { toPairs, fromPairs, isEmpty } from '@livechat/data-utils'; | ||
var originRegexp = /[^:]+:\/\/[^(/|?)\s]+/; | ||
var getOrigin = function getOrigin(url) { | ||
@@ -36,3 +35,2 @@ var domain = url.match(originRegexp); | ||
var searchRegexp = /.*?\?([^#]+)/; | ||
var getSearch = function getSearch(url) { | ||
@@ -51,3 +49,2 @@ var match = url.match(searchRegexp); | ||
} | ||
var search = trimSearch(getSearch(urlOrSearch)); | ||
@@ -62,3 +59,2 @@ return search ? decodeQueryString(search) : {}; | ||
var pathnameRegexp = /^(?:https?:)?\/\/[^/]+\/([^?#]+)/; | ||
var getPathname = function getPathname(url) { | ||
@@ -80,7 +76,6 @@ var pathname = url.match(pathnameRegexp); | ||
}; | ||
var unsafeProtocol = new RegExp("^[\0-\x1F]*(" + intersperseWithTabOrNewline('javascript') + "|" + intersperseWithTabOrNewline('data') + "):", 'i'); // would be better to filter safe things | ||
var unsafeProtocol = new RegExp("^[\0-\x1F]*(" + intersperseWithTabOrNewline('javascript') + "|" + intersperseWithTabOrNewline('data') + "):", 'i'); | ||
// would be better to filter safe things | ||
// but people might paste in protocolless URLs | ||
// and we would filter them out | ||
var hasUnsafeProtocol = function hasUnsafeProtocol(url) { | ||
@@ -91,3 +86,2 @@ return unsafeProtocol.test(url); | ||
var protocolRegexp = /^((http(s)?:)?\/\/)/; | ||
var removeProtocol = function removeProtocol(url) { | ||
@@ -98,3 +92,2 @@ return url.replace(protocolRegexp, ''); | ||
var protocolRegexp$1 = /^((http(s)?:)?\/\/)/; | ||
var getProtocol = function getProtocol(url) { | ||
@@ -106,6 +99,5 @@ var match = url.match(protocolRegexp$1); | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
_extends = Object.assign ? Object.assign.bind() : function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
@@ -117,6 +109,4 @@ if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
@@ -129,3 +119,2 @@ } | ||
} | ||
var urlOrigin = getOrigin(url); | ||
@@ -142,9 +131,6 @@ var urlPath = getPathname(url); | ||
} | ||
var params = getQueryParams(url); | ||
if (isEmpty(params)) { | ||
return url; | ||
} | ||
if (Object.keys(params).every(function (paramKey) { | ||
@@ -155,19 +141,18 @@ return !paramsToRemove.includes(paramKey); | ||
} | ||
paramsToRemove.forEach(function (param) { | ||
return delete params[param]; | ||
}); | ||
var _url$split = url.split('?'), | ||
querylessURL = _url$split[0]; | ||
querylessURL = _url$split[0]; | ||
var extendedURL = extendURLByQueryParams(querylessURL, params); | ||
if (url.indexOf('#') > -1) { | ||
return extendedURL + "#" + url.split('#')[1]; | ||
} | ||
return extendedURL; | ||
}; | ||
export { buildQueryString, decodeQueryString, extendURLByQueryParams, getHostname, getOrigin, getPathname, getProtocol, getQueryParam, getQueryParams, getSearch, hasUnsafeProtocol, removeProtocol, removeQueryParams, trimSearch }; | ||
var ensureSecureProtocol = function ensureSecureProtocol(url) { | ||
return "https://" + removeProtocol(url); | ||
}; | ||
export { buildQueryString, decodeQueryString, ensureSecureProtocol, extendURLByQueryParams, getHostname, getOrigin, getPathname, getProtocol, getQueryParam, getQueryParams, getSearch, hasUnsafeProtocol, removeProtocol, removeQueryParams, trimSearch }; |
{ | ||
"name": "@livechat/url-utils", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "URL utility functions", | ||
@@ -23,10 +23,10 @@ "contributors": [ | ||
"dependencies": { | ||
"@livechat/data-utils": "^0.2.16" | ||
"@livechat/data-utils": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.10.5", | ||
"@babel/core": "7.20.7", | ||
"@babel/plugin-proposal-class-properties": "^7.10.4", | ||
"@babel/plugin-syntax-dynamic-import": "^7.8.3", | ||
"@babel/preset-env": "^7.10.4", | ||
"@babel/preset-typescript": "^7.10.4", | ||
"@babel/preset-typescript": "^7.18.6", | ||
"@rollup/plugin-babel": "^5.2.1", | ||
@@ -39,3 +39,3 @@ "@rollup/plugin-node-resolve": "^9.0.0", | ||
"rollup": "^2.27.1", | ||
"typescript": "^3.9.7" | ||
"typescript": "4.9.4" | ||
}, | ||
@@ -42,0 +42,0 @@ "scripts": { |
@@ -15,2 +15,3 @@ export { default as buildQueryString } from './buildQueryString'; | ||
export { default as removeQueryParams } from './removeQueryParams'; | ||
export { default as ensureSecureProtocol } from './ensureSecureProtocol'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,4 +0,4 @@ | ||
export declare type MaybeStringValueObject = { | ||
export type MaybeStringValueObject = { | ||
[key: string]: string | void; | ||
}; | ||
//# sourceMappingURL=types.d.ts.map |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
14801
20
328
1
+ Added@livechat/data-utils@1.0.4(transitive)
- Removed@livechat/data-utils@0.2.17(transitive)
Updated@livechat/data-utils@^1.0.1