@arcteryx/js-url
Advanced tools
Comparing version 1.29.0-alpha.0 to 1.29.0-gamma.0
@@ -12,6 +12,5 @@ 'use strict'; | ||
function endsWith(str, pattern) { | ||
const d = str.length - pattern.length; | ||
return d >= 0 && str.lastIndexOf(pattern) === d; | ||
const d = str.length - pattern.length; | ||
return d >= 0 && str.lastIndexOf(pattern) === d; | ||
} | ||
/** | ||
@@ -24,55 +23,41 @@ * @brief Converts the product model to match the new PDP model URL. | ||
function modelConversionForNewPDP(model) { | ||
let newModel = model; | ||
if (model.indexOf(".") > 0) { | ||
newModel = model.replace(/\./g, "-"); | ||
} | ||
if (endsWith(newModel, "-W")) { | ||
newModel = newModel.substr(0, newModel.lastIndexOf("-W")); | ||
} else if (endsWith(newModel, "-w")) { | ||
newModel = newModel.substr(0, newModel.lastIndexOf("-w")); | ||
} | ||
return newModel; | ||
let newModel = model; | ||
if (model.indexOf(".") > 0) { | ||
newModel = model.replace(/\./g, "-"); | ||
} | ||
if (endsWith(newModel, "-W")) { | ||
newModel = newModel.substr(0, newModel.lastIndexOf("-W")); | ||
} | ||
else if (endsWith(newModel, "-w")) { | ||
newModel = newModel.substr(0, newModel.lastIndexOf("-w")); | ||
} | ||
return newModel; | ||
} | ||
function querySt(ji, or) { | ||
let hu = or ? or : window.location.search.substring(1), | ||
gy = hu.split("&"), | ||
ft, | ||
i; | ||
for (i = 0; i < gy.length; i++) { | ||
ft = gy[i].split("="); | ||
if (ft[0].toLowerCase() === ji.toLowerCase()) { | ||
return ft[1]; | ||
let hu = or ? or : window.location.search.substring(1), gy = hu.split("&"), ft, i; | ||
for (i = 0; i < gy.length; i++) { | ||
ft = gy[i].split("="); | ||
if (ft[0].toLowerCase() === ji.toLowerCase()) { | ||
return ft[1]; | ||
} | ||
} | ||
} | ||
return ""; | ||
return ""; | ||
} | ||
function removeQueryStringParameter(url, key) { | ||
let newUrl = url, | ||
urlparts = url.split("?"); | ||
if (urlparts.length >= 2) { | ||
const prefix = `${encodeURIComponent(key)}=`; | ||
const pars = urlparts[1].split(/[&;]/g); | ||
// Reverse iteration as may be destructive | ||
for (let i = pars.length; i-- > 0; ) { | ||
// Idiom for string.startsWith | ||
if (pars[i].lastIndexOf(prefix, 0) !== -1) { | ||
pars.splice(i, 1); | ||
} | ||
let newUrl = url, urlparts = url.split("?"); | ||
if (urlparts.length >= 2) { | ||
const prefix = `${encodeURIComponent(key)}=`; | ||
const pars = urlparts[1].split(/[&;]/g); | ||
// Reverse iteration as may be destructive | ||
for (let i = pars.length; i-- > 0;) { | ||
// Idiom for string.startsWith | ||
if (pars[i].lastIndexOf(prefix, 0) !== -1) { | ||
pars.splice(i, 1); | ||
} | ||
} | ||
newUrl = urlparts[0] + (pars.length > 0 ? `?${pars.join("&")}` : ""); | ||
return newUrl; | ||
} | ||
newUrl = urlparts[0] + (pars.length > 0 ? `?${pars.join("&")}` : ""); | ||
return newUrl; | ||
} | ||
return newUrl; | ||
} | ||
/* | ||
@@ -86,28 +71,24 @@ * Converts a simple object to query parameters | ||
function toQueryParams(obj) { | ||
const url = Object.keys(obj) | ||
.map(x => { | ||
if (Array.isArray(obj[x])) { | ||
return obj[x].map(i => `${encodeURIComponent(x)}=${encodeURIComponent(i)}`).join("&"); | ||
} | ||
return `${encodeURIComponent(x)}=${encodeURIComponent(obj[x])}`; | ||
const url = Object.keys(obj) | ||
.map(x => { | ||
if (Array.isArray(obj[x])) { | ||
return obj[x].map(i => `${encodeURIComponent(x)}=${encodeURIComponent(i)}`).join("&"); | ||
} | ||
return `${encodeURIComponent(x)}=${encodeURIComponent(obj[x])}`; | ||
}) | ||
.join("&"); | ||
return url; | ||
.join("&"); | ||
return url; | ||
} | ||
function updateQueryStringParameter(uri, key, value) { | ||
const re = new RegExp(`([?&])${key}=.*?(&|$)`, "i"); | ||
const separator = uri.indexOf("?") > -1 ? "&" : "?"; | ||
if (uri.match(re)) { | ||
return uri.replace(re, `$1${key}=${value}$2`); | ||
} | ||
// If adding country to url, add it before search | ||
if (uri.match("search=")) { | ||
const arr = uri.split("&"); | ||
return `${arr[0] + separator + key}=${value}&${arr[1]}`; | ||
} | ||
return `${uri + separator + key}=${value}`; | ||
const re = new RegExp(`([?&])${key}=.*?(&|$)`, "i"); | ||
const separator = uri.indexOf("?") > -1 ? "&" : "?"; | ||
if (uri.match(re)) { | ||
return uri.replace(re, `$1${key}=${value}$2`); | ||
} | ||
// If adding country to url, add it before search | ||
if (uri.match("search=")) { | ||
const arr = uri.split("&"); | ||
return `${arr[0] + separator + key}=${value}&${arr[1]}`; | ||
} | ||
return `${uri + separator + key}=${value}`; | ||
} | ||
@@ -114,0 +95,0 @@ |
@@ -8,6 +8,5 @@ /** | ||
function endsWith(str, pattern) { | ||
const d = str.length - pattern.length; | ||
return d >= 0 && str.lastIndexOf(pattern) === d; | ||
const d = str.length - pattern.length; | ||
return d >= 0 && str.lastIndexOf(pattern) === d; | ||
} | ||
/** | ||
@@ -20,55 +19,41 @@ * @brief Converts the product model to match the new PDP model URL. | ||
function modelConversionForNewPDP(model) { | ||
let newModel = model; | ||
if (model.indexOf(".") > 0) { | ||
newModel = model.replace(/\./g, "-"); | ||
} | ||
if (endsWith(newModel, "-W")) { | ||
newModel = newModel.substr(0, newModel.lastIndexOf("-W")); | ||
} else if (endsWith(newModel, "-w")) { | ||
newModel = newModel.substr(0, newModel.lastIndexOf("-w")); | ||
} | ||
return newModel; | ||
let newModel = model; | ||
if (model.indexOf(".") > 0) { | ||
newModel = model.replace(/\./g, "-"); | ||
} | ||
if (endsWith(newModel, "-W")) { | ||
newModel = newModel.substr(0, newModel.lastIndexOf("-W")); | ||
} | ||
else if (endsWith(newModel, "-w")) { | ||
newModel = newModel.substr(0, newModel.lastIndexOf("-w")); | ||
} | ||
return newModel; | ||
} | ||
function querySt(ji, or) { | ||
let hu = or ? or : window.location.search.substring(1), | ||
gy = hu.split("&"), | ||
ft, | ||
i; | ||
for (i = 0; i < gy.length; i++) { | ||
ft = gy[i].split("="); | ||
if (ft[0].toLowerCase() === ji.toLowerCase()) { | ||
return ft[1]; | ||
let hu = or ? or : window.location.search.substring(1), gy = hu.split("&"), ft, i; | ||
for (i = 0; i < gy.length; i++) { | ||
ft = gy[i].split("="); | ||
if (ft[0].toLowerCase() === ji.toLowerCase()) { | ||
return ft[1]; | ||
} | ||
} | ||
} | ||
return ""; | ||
return ""; | ||
} | ||
function removeQueryStringParameter(url, key) { | ||
let newUrl = url, | ||
urlparts = url.split("?"); | ||
if (urlparts.length >= 2) { | ||
const prefix = `${encodeURIComponent(key)}=`; | ||
const pars = urlparts[1].split(/[&;]/g); | ||
// Reverse iteration as may be destructive | ||
for (let i = pars.length; i-- > 0; ) { | ||
// Idiom for string.startsWith | ||
if (pars[i].lastIndexOf(prefix, 0) !== -1) { | ||
pars.splice(i, 1); | ||
} | ||
let newUrl = url, urlparts = url.split("?"); | ||
if (urlparts.length >= 2) { | ||
const prefix = `${encodeURIComponent(key)}=`; | ||
const pars = urlparts[1].split(/[&;]/g); | ||
// Reverse iteration as may be destructive | ||
for (let i = pars.length; i-- > 0;) { | ||
// Idiom for string.startsWith | ||
if (pars[i].lastIndexOf(prefix, 0) !== -1) { | ||
pars.splice(i, 1); | ||
} | ||
} | ||
newUrl = urlparts[0] + (pars.length > 0 ? `?${pars.join("&")}` : ""); | ||
return newUrl; | ||
} | ||
newUrl = urlparts[0] + (pars.length > 0 ? `?${pars.join("&")}` : ""); | ||
return newUrl; | ||
} | ||
return newUrl; | ||
} | ||
/* | ||
@@ -82,28 +67,24 @@ * Converts a simple object to query parameters | ||
function toQueryParams(obj) { | ||
const url = Object.keys(obj) | ||
.map(x => { | ||
if (Array.isArray(obj[x])) { | ||
return obj[x].map(i => `${encodeURIComponent(x)}=${encodeURIComponent(i)}`).join("&"); | ||
} | ||
return `${encodeURIComponent(x)}=${encodeURIComponent(obj[x])}`; | ||
const url = Object.keys(obj) | ||
.map(x => { | ||
if (Array.isArray(obj[x])) { | ||
return obj[x].map(i => `${encodeURIComponent(x)}=${encodeURIComponent(i)}`).join("&"); | ||
} | ||
return `${encodeURIComponent(x)}=${encodeURIComponent(obj[x])}`; | ||
}) | ||
.join("&"); | ||
return url; | ||
.join("&"); | ||
return url; | ||
} | ||
function updateQueryStringParameter(uri, key, value) { | ||
const re = new RegExp(`([?&])${key}=.*?(&|$)`, "i"); | ||
const separator = uri.indexOf("?") > -1 ? "&" : "?"; | ||
if (uri.match(re)) { | ||
return uri.replace(re, `$1${key}=${value}$2`); | ||
} | ||
// If adding country to url, add it before search | ||
if (uri.match("search=")) { | ||
const arr = uri.split("&"); | ||
return `${arr[0] + separator + key}=${value}&${arr[1]}`; | ||
} | ||
return `${uri + separator + key}=${value}`; | ||
const re = new RegExp(`([?&])${key}=.*?(&|$)`, "i"); | ||
const separator = uri.indexOf("?") > -1 ? "&" : "?"; | ||
if (uri.match(re)) { | ||
return uri.replace(re, `$1${key}=${value}$2`); | ||
} | ||
// If adding country to url, add it before search | ||
if (uri.match("search=")) { | ||
const arr = uri.split("&"); | ||
return `${arr[0] + separator + key}=${value}&${arr[1]}`; | ||
} | ||
return `${uri + separator + key}=${value}`; | ||
} | ||
@@ -110,0 +91,0 @@ |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, (function () { | ||
var current = global.ARCTERYX && global.ARCTERYX.jsurl; | ||
var exports = (global.ARCTERYX = global.ARCTERYX || {}, global.ARCTERYX.jsurl = {}); | ||
factory(exports); | ||
exports.noConflict = function () { global.ARCTERYX.jsurl = current; return exports; }; | ||
})()); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, (function () { | ||
var current = global.ARCTERYX && global.ARCTERYX.jsurl; | ||
var exports = (global.ARCTERYX = global.ARCTERYX || {}, global.ARCTERYX.jsurl = {}); | ||
factory(exports); | ||
exports.noConflict = function () { global.ARCTERYX.jsurl = current; return exports; }; | ||
})()); | ||
})(this, (function (exports) { 'use strict'; | ||
/** | ||
* @brief Function to check if String ends with a given pattern. Workaround for IE not supporting endsWith | ||
* @param str | ||
* @param pattern | ||
* @returns {boolean} | ||
*/ | ||
function endsWith(str, pattern) { | ||
const d = str.length - pattern.length; | ||
return d >= 0 && str.lastIndexOf(pattern) === d; | ||
} | ||
/** | ||
* @brief Converts the product model to match the new PDP model URL. | ||
* Specifically for womens products ending -w or products with periods in them (e.g. B.A.C hat) | ||
* @param model | ||
* @returns {String} convertedModel | ||
*/ | ||
function modelConversionForNewPDP(model) { | ||
let newModel = model; | ||
if (model.indexOf(".") > 0) { | ||
newModel = model.replace(/\./g, "-"); | ||
/** | ||
* @brief Function to check if String ends with a given pattern. Workaround for IE not supporting endsWith | ||
* @param str | ||
* @param pattern | ||
* @returns {boolean} | ||
*/ | ||
function endsWith(str, pattern) { | ||
const d = str.length - pattern.length; | ||
return d >= 0 && str.lastIndexOf(pattern) === d; | ||
} | ||
if (endsWith(newModel, "-W")) { | ||
newModel = newModel.substr(0, newModel.lastIndexOf("-W")); | ||
} else if (endsWith(newModel, "-w")) { | ||
newModel = newModel.substr(0, newModel.lastIndexOf("-w")); | ||
/** | ||
* @brief Converts the product model to match the new PDP model URL. | ||
* Specifically for womens products ending -w or products with periods in them (e.g. B.A.C hat) | ||
* @param model | ||
* @returns {String} convertedModel | ||
*/ | ||
function modelConversionForNewPDP(model) { | ||
let newModel = model; | ||
if (model.indexOf(".") > 0) { | ||
newModel = model.replace(/\./g, "-"); | ||
} | ||
if (endsWith(newModel, "-W")) { | ||
newModel = newModel.substr(0, newModel.lastIndexOf("-W")); | ||
} | ||
else if (endsWith(newModel, "-w")) { | ||
newModel = newModel.substr(0, newModel.lastIndexOf("-w")); | ||
} | ||
return newModel; | ||
} | ||
return newModel; | ||
} | ||
function querySt(ji, or) { | ||
let hu = or ? or : window.location.search.substring(1), | ||
gy = hu.split("&"), | ||
ft, | ||
i; | ||
for (i = 0; i < gy.length; i++) { | ||
ft = gy[i].split("="); | ||
if (ft[0].toLowerCase() === ji.toLowerCase()) { | ||
return ft[1]; | ||
} | ||
function querySt(ji, or) { | ||
let hu = or ? or : window.location.search.substring(1), gy = hu.split("&"), ft, i; | ||
for (i = 0; i < gy.length; i++) { | ||
ft = gy[i].split("="); | ||
if (ft[0].toLowerCase() === ji.toLowerCase()) { | ||
return ft[1]; | ||
} | ||
} | ||
return ""; | ||
} | ||
return ""; | ||
} | ||
function removeQueryStringParameter(url, key) { | ||
let newUrl = url, | ||
urlparts = url.split("?"); | ||
if (urlparts.length >= 2) { | ||
const prefix = `${encodeURIComponent(key)}=`; | ||
const pars = urlparts[1].split(/[&;]/g); | ||
// Reverse iteration as may be destructive | ||
for (let i = pars.length; i-- > 0; ) { | ||
// Idiom for string.startsWith | ||
if (pars[i].lastIndexOf(prefix, 0) !== -1) { | ||
pars.splice(i, 1); | ||
function removeQueryStringParameter(url, key) { | ||
let newUrl = url, urlparts = url.split("?"); | ||
if (urlparts.length >= 2) { | ||
const prefix = `${encodeURIComponent(key)}=`; | ||
const pars = urlparts[1].split(/[&;]/g); | ||
// Reverse iteration as may be destructive | ||
for (let i = pars.length; i-- > 0;) { | ||
// Idiom for string.startsWith | ||
if (pars[i].lastIndexOf(prefix, 0) !== -1) { | ||
pars.splice(i, 1); | ||
} | ||
} | ||
newUrl = urlparts[0] + (pars.length > 0 ? `?${pars.join("&")}` : ""); | ||
return newUrl; | ||
} | ||
} | ||
newUrl = urlparts[0] + (pars.length > 0 ? `?${pars.join("&")}` : ""); | ||
return newUrl; | ||
return newUrl; | ||
} | ||
return newUrl; | ||
} | ||
/* | ||
* Converts a simple object to query parameters | ||
* | ||
* @param Object | ||
* @returns String with key/value pairs query string formatted | ||
* | ||
*/ | ||
function toQueryParams(obj) { | ||
const url = Object.keys(obj) | ||
.map(x => { | ||
if (Array.isArray(obj[x])) { | ||
return obj[x].map(i => `${encodeURIComponent(x)}=${encodeURIComponent(i)}`).join("&"); | ||
/* | ||
* Converts a simple object to query parameters | ||
* | ||
* @param Object | ||
* @returns String with key/value pairs query string formatted | ||
* | ||
*/ | ||
function toQueryParams(obj) { | ||
const url = Object.keys(obj) | ||
.map(x => { | ||
if (Array.isArray(obj[x])) { | ||
return obj[x].map(i => `${encodeURIComponent(x)}=${encodeURIComponent(i)}`).join("&"); | ||
} | ||
return `${encodeURIComponent(x)}=${encodeURIComponent(obj[x])}`; | ||
}) | ||
.join("&"); | ||
return url; | ||
} | ||
function updateQueryStringParameter(uri, key, value) { | ||
const re = new RegExp(`([?&])${key}=.*?(&|$)`, "i"); | ||
const separator = uri.indexOf("?") > -1 ? "&" : "?"; | ||
if (uri.match(re)) { | ||
return uri.replace(re, `$1${key}=${value}$2`); | ||
} | ||
return `${encodeURIComponent(x)}=${encodeURIComponent(obj[x])}`; | ||
}) | ||
.join("&"); | ||
return url; | ||
} | ||
function updateQueryStringParameter(uri, key, value) { | ||
const re = new RegExp(`([?&])${key}=.*?(&|$)`, "i"); | ||
const separator = uri.indexOf("?") > -1 ? "&" : "?"; | ||
if (uri.match(re)) { | ||
return uri.replace(re, `$1${key}=${value}$2`); | ||
// If adding country to url, add it before search | ||
if (uri.match("search=")) { | ||
const arr = uri.split("&"); | ||
return `${arr[0] + separator + key}=${value}&${arr[1]}`; | ||
} | ||
return `${uri + separator + key}=${value}`; | ||
} | ||
// If adding country to url, add it before search | ||
if (uri.match("search=")) { | ||
const arr = uri.split("&"); | ||
return `${arr[0] + separator + key}=${value}&${arr[1]}`; | ||
} | ||
exports.endsWith = endsWith; | ||
exports.modelConversionForNewPDP = modelConversionForNewPDP; | ||
exports.querySt = querySt; | ||
exports.removeQueryStringParameter = removeQueryStringParameter; | ||
exports.toQueryParams = toQueryParams; | ||
exports.updateQueryStringParameter = updateQueryStringParameter; | ||
return `${uri + separator + key}=${value}`; | ||
} | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.endsWith = endsWith; | ||
exports.modelConversionForNewPDP = modelConversionForNewPDP; | ||
exports.querySt = querySt; | ||
exports.removeQueryStringParameter = removeQueryStringParameter; | ||
exports.toQueryParams = toQueryParams; | ||
exports.updateQueryStringParameter = updateQueryStringParameter; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
})); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@arcteryx/js-url", | ||
"version": "1.29.0-alpha.0", | ||
"version": "1.29.0-gamma.0", | ||
"source": "src/index.js", | ||
@@ -14,3 +14,3 @@ "main": "dist/cjs/index.js", | ||
"license": "ISC", | ||
"gitHead": "62220ec46c7009487fa7953207a575eac9c02bb5", | ||
"gitHead": "1a7a6e1474fd63c25d6c87ac76803343ea10145c", | ||
"files": [ | ||
@@ -17,0 +17,0 @@ "dist", |
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
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
36826
15
435