build-url-ts
Advanced tools
Comparing version 5.0.7 to 5.0.8
@@ -1,79 +0,87 @@ | ||
function appendPath(path, builtUrl, lowerCase) { | ||
if (builtUrl[builtUrl.length - 1] === "/") { | ||
builtUrl = builtUrl.slice(0, -1); | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global['build-url'] = factory()); | ||
}(this, (function () { 'use strict'; | ||
function appendPath(path, builtUrl, lowerCase) { | ||
if (builtUrl[builtUrl.length - 1] === "/") { | ||
builtUrl = builtUrl.slice(0, -1); | ||
} | ||
var pathString = String(path).trim(); | ||
if (lowerCase) { | ||
pathString = pathString.toLowerCase(); | ||
} | ||
if (pathString.indexOf("/") === 0) { | ||
builtUrl += pathString; | ||
} | ||
else { | ||
builtUrl += "/" + pathString; | ||
} | ||
return builtUrl; | ||
} | ||
var pathString = String(path).trim(); | ||
if (lowerCase) { | ||
pathString = pathString.toLowerCase(); | ||
function buildHash(hash, lowerCase) { | ||
var hashString = "#" + String(hash).trim(); | ||
return lowerCase ? hashString.toLowerCase() : hashString; | ||
} | ||
if (pathString.indexOf("/") === 0) { | ||
builtUrl += pathString; | ||
} | ||
else { | ||
builtUrl += "/" + pathString; | ||
} | ||
return builtUrl; | ||
} | ||
function buildHash(hash, lowerCase) { | ||
var hashString = "#" + String(hash).trim(); | ||
return lowerCase ? hashString.toLowerCase() : hashString; | ||
} | ||
function buildQueryString(queryParams, lowerCase, disableCSV) { | ||
var queryString = []; | ||
var _loop_1 = function (key) { | ||
if (Object.prototype.hasOwnProperty.call(queryParams, key) && | ||
queryParams[key] !== void 0) { | ||
var param_1; | ||
if (disableCSV && | ||
Array.isArray(queryParams[key]) && | ||
queryParams[key].length) { | ||
queryParams[key].forEach(function (v) { | ||
param_1 = v !== 0 ? v || "" : 0; | ||
queryString.push(key + "=" + encodeURIComponent(String(param_1).trim())); | ||
}); | ||
} | ||
else { | ||
if (lowerCase) { | ||
param_1 = String(queryParams[key]).toLowerCase() || ""; | ||
function buildQueryString(queryParams, lowerCase, disableCSV) { | ||
var queryString = []; | ||
var _loop_1 = function (key) { | ||
if (Object.prototype.hasOwnProperty.call(queryParams, key) && | ||
queryParams[key] !== void 0) { | ||
var param_1; | ||
if (disableCSV && | ||
Array.isArray(queryParams[key]) && | ||
queryParams[key].length) { | ||
queryParams[key].forEach(function (v) { | ||
param_1 = v !== 0 ? v || "" : 0; | ||
queryString.push(key + "=" + encodeURIComponent(String(param_1).trim())); | ||
}); | ||
} | ||
else { | ||
param_1 = queryParams[key] !== 0 ? queryParams[key] || "" : 0; | ||
if (lowerCase) { | ||
param_1 = String(queryParams[key]).toLowerCase() || ""; | ||
} | ||
else { | ||
param_1 = queryParams[key] !== 0 ? queryParams[key] || "" : 0; | ||
} | ||
queryString.push(key + "=" + encodeURIComponent(String(param_1).trim())); | ||
} | ||
queryString.push(key + "=" + encodeURIComponent(String(param_1).trim())); | ||
} | ||
}; | ||
for (var key in queryParams) { | ||
_loop_1(key); | ||
} | ||
}; | ||
for (var key in queryParams) { | ||
_loop_1(key); | ||
return "?" + queryString.join("&"); | ||
} | ||
return "?" + queryString.join("&"); | ||
} | ||
function buildUrl(url, options) { | ||
var builtUrl; | ||
if (url === null) { | ||
builtUrl = ""; | ||
function buildUrl(url, options) { | ||
var builtUrl; | ||
if (url === null) { | ||
builtUrl = ""; | ||
} | ||
else if (typeof url === "object") { | ||
builtUrl = ""; | ||
options = url; | ||
} | ||
else { | ||
builtUrl = url; | ||
} | ||
if (options === null || options === void 0 ? void 0 : options.path) { | ||
builtUrl = appendPath(options.path, builtUrl, options.lowerCase); | ||
} | ||
if (options === null || options === void 0 ? void 0 : options.queryParams) { | ||
builtUrl += buildQueryString(options.queryParams, options.lowerCase, options.disableCSV); | ||
} | ||
if (options === null || options === void 0 ? void 0 : options.hash) { | ||
builtUrl += buildHash(options.hash, options.lowerCase); | ||
} | ||
return builtUrl; | ||
} | ||
else if (typeof url === "object") { | ||
builtUrl = ""; | ||
options = url; | ||
} | ||
else { | ||
builtUrl = url; | ||
} | ||
if (options === null || options === void 0 ? void 0 : options.path) { | ||
builtUrl = appendPath(options.path, builtUrl, options.lowerCase); | ||
} | ||
if (options === null || options === void 0 ? void 0 : options.queryParams) { | ||
builtUrl += buildQueryString(options.queryParams, options.lowerCase, options.disableCSV); | ||
} | ||
if (options === null || options === void 0 ? void 0 : options.hash) { | ||
builtUrl += buildHash(options.hash, options.lowerCase); | ||
} | ||
return builtUrl; | ||
} | ||
export default buildUrl; | ||
return buildUrl; | ||
}))); | ||
//# sourceMappingURL=build-url.js.map |
{ | ||
"name": "build-url-ts", | ||
"version": "5.0.7", | ||
"version": "5.0.8", | ||
"description": "A small library that builds a URL given its components", | ||
@@ -8,3 +8,3 @@ "main": "./dist/build-url.js", | ||
"scripts": { | ||
"build": "rollup -c ./rollup.config.js", | ||
"build": "NODE_ENV=production rollup -c ./rollup.config.js", | ||
"lint-js": "eslint src/**/*.ts", | ||
@@ -44,2 +44,5 @@ "prepublishOnly": "rollup -c ./rollup.config.js", | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^15.0.0", | ||
"@rollup/plugin-node-resolve": "^9.0.0", | ||
"@rollup/plugin-replace": "^2.3.3", | ||
"@rollup/plugin-typescript": "5.0.2", | ||
@@ -57,2 +60,3 @@ "@types/eslint": "7.2.2", | ||
"rollup": "2.26.8", | ||
"rollup-plugin-uglify": "^6.0.4", | ||
"ts-jest": "26.3.0", | ||
@@ -59,0 +63,0 @@ "tslib": "2.0.1", |
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
14098
102
19