Comparing version 1.1.1 to 1.2.0
@@ -32,2 +32,20 @@ "use strict"; | ||
if (options != undefined) { | ||
const www = "www."; | ||
let hasWww = false; | ||
let protocol = ""; | ||
const protocolArr = ["http://", "https://"]; | ||
// Store protocol | ||
protocolArr.forEach(item => { | ||
if (mainUrl.startsWith(item)) { | ||
const regex = new RegExp(`^${item}`); | ||
mainUrl.replace(regex, ""); | ||
protocol = item; | ||
} | ||
}); | ||
// Handling www | ||
if (mainUrl.startsWith(www)) { | ||
const regex = new RegExp(www); | ||
mainUrl.replace(regex, ""); | ||
hasWww = true; | ||
} | ||
// Delete slash from mainUrl | ||
@@ -50,4 +68,6 @@ mainUrl = mainUrl.endsWith('/') ? mainUrl.replace(/\/$/, "") : mainUrl; | ||
} | ||
// March all elements | ||
const combinedUrl = hasWww ? protocol + www + mainUrl : protocol + mainUrl; | ||
// Create a new URL object from the modified mainUrl. | ||
const url = new URL(mainUrl); | ||
const url = new URL(combinedUrl); | ||
// If queryParams are provided, append them to the URL. | ||
@@ -54,0 +74,0 @@ if (options.queryParams != undefined) { |
{ | ||
"name": "linksmith", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Linksmith is a flexible and powerful TypeScript-based URL builder for Node.js and frontend projects. Designed for developers who need to construct clean and efficient URLs, linksmith allows seamless addition of subdomains, paths, and query parameters with a simple, intuitive API.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
![License](https://img.shields.io/badge/License-MIT-blue) | ||
![Version](https://img.shields.io/badge/Version-1.1.0-orange) | ||
![Version](https://img.shields.io/badge/Version-1.2.0-orange) | ||
@@ -23,2 +23,3 @@ # linksmith | ||
- **Query Parameters**: Effortlessly add query parameters. | ||
- **Port Management**: Add port of your URL. | ||
@@ -25,0 +26,0 @@ ## Installation |
@@ -36,6 +36,26 @@ /** | ||
// Check if options are provided and proceed with modifying the URL. | ||
if (options != undefined) { | ||
const www = "www." | ||
let hasWww = false | ||
let protocol = "" | ||
const protocolArr = ["http://", "https://"] | ||
// Store protocol | ||
protocolArr.forEach(item => { | ||
if (mainUrl.startsWith(item)) { | ||
const regex = new RegExp(`^${item}`) | ||
mainUrl.replace(regex, "") | ||
protocol = item | ||
} | ||
}) | ||
// Handling www | ||
if (mainUrl.startsWith(www)) { | ||
const regex = new RegExp(www) | ||
mainUrl.replace(regex, "") | ||
hasWww = true | ||
} | ||
// Delete slash from mainUrl | ||
@@ -65,4 +85,7 @@ mainUrl = mainUrl.endsWith('/') ? mainUrl.replace(/\/$/, "") : mainUrl | ||
// March all elements | ||
const combinedUrl = hasWww ? protocol + www + mainUrl : protocol + mainUrl | ||
// Create a new URL object from the modified mainUrl. | ||
const url = new URL(mainUrl); | ||
const url = new URL(combinedUrl); | ||
@@ -69,0 +92,0 @@ // If queryParams are provided, append them to the URL. |
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
13094
201
77