url-manipulator

1.0.2 • Public • Published

Url Manipulator - Set/Get/Remove/Count select parts in a url or create urls from scratch. Deal with domains, params, queries, values, ports, protocols.

  npm install url-manipulator

Set URL, Remove domain, Domain Length

var Url = require('url-manipulator');
url = new Url().setUrl("http://aki.google.com/code/bucket");
console.log(url.getUrl());
console.log(url.addDomainBefore("ty").getUrl());
console.log(url.domainLen());
console.log(url.removeDomain("aki").getUrl()); 
console.log(url.removeDomain("ty").getUrl()); 
console.log(url.tld()); 
console.log(url.sld()); 

Set Query, Get Query Value, Remove Query, Query Length

console.log(url.setQuery("per_page", 25).getUrl());
console.log(url.getQueryValue("per_page"));
console.log(url.queryLen());
console.log(url.removeQuery("per_page").getUrl());
console.log(url.setQuery("page", 1).getUrl());
console.log(url.setQuery("per_page", 10).getUrl());
console.log(url.removeQueryString().getUrl());

Add Param, Remove Param byName and byIndex, Param Length

console.log(url.addParam("code").getUrl());
console.log(url.removeParam("byName", "code").getUrl());
console.log(url.addParam("node").getUrl());
console.log(url.paramLen());
console.log(url.removeParam("byIndex", 0).getUrl());

Add Port, Remove Port

console.log(url.addPort(4000).getUrl());
console.log(url.removePort().getUrl());

Set Protocol

console.log(url.setProtocol('https').getUrl());
console.log(url.setProtocol('ftp').getUrl());

Create a Url from scratch

url = new Url();
console.log(url.addDomain('api').addDomain('google').addDomain('com').addParam('news').addParam('folder').setQuery("newsId", "432").setQuery("user", "theDeveloper").getUrl());

Dependents (0)

Package Sidebar

Install

npm i url-manipulator

Weekly Downloads

1

Version

1.0.2

License

none

Last publish

Collaborators

  • latenightdeveloper