1.0.1-0.1 • Published 12 days ago

url-parse-modify v1.0.1-0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
12 days ago

Version npm

Npm install

npm i url-parse-modify

Import

import Url from 'url-parse-modify';

Parse url

const url = new Url('http://localhost:8080/3rd-Eden/path/to/resource?name=John&id=123#section2')
console.log(url.urlParse)

return:

{
  path: '/3rd-Eden/path/to/resource',
  hash: 'section2',
  protocol: 'http',
  origin: 'http://localhost',
  username: null,
  password: null,
  hostname: 'localhost',
  port: '8080',
  query: { name: 'John', id: '123' }
}
PropertyDescription
hashThe URL hash fragment, can be a string or null.
protocolThe URL protocol (e.g., "http" or "https"), or null.
originThe URL origin (e.g., "https://example.com"), or null.
usernameA username in the URL, can be a string or null.
passwordA password in the URL, can be a string or null.
hostnameThe URL hostname (e.g., "example.com"), or null.
portThe URL port (e.g., "8080"), can be a string or null.
queryAn object representing URL query parameters.
pathThe URL path, can be a string or null.

toString()

const url = new Url('http://localhost:8080/3rd-Eden/path/to/resource?name=John&id=123#section2')
console.log(url.toString())

//http://localhost:8080/3rd-Eden/path/to/resource?name=John&id=123#section2

get(key)

const url = new Url('http://localhost:8080/3rd-Eden/path/to/resource?name=John&id=123#section2')
const host = url.get('hostname')
console.log(host)
//localhost
KeyDescription
'hash'Represents the URL hash fragment.
'protocol'Represents the URL protocol (e.g., "http" or "https").
'origin'Represents the URL origin (e.g., "https://example.com").
'username'Represents a username in the URL.
'password'Represents a password in the URL.
'hostname'Represents the URL hostname (e.g., "example.com").
'port'Represents the URL port (e.g., "8080").
'query'Represents URL query parameters as an object.
'path'Represents the URL path.

set(key,value)

const url = new Url('http://localhost:8080/3rd-Eden/path/to/resource?name=John&id=123#section2')
url.set('hostname', 'google.com')
console.log(url.toString())
//http://google.com:8080/3rd-Eden/path/to/resource?name=John&id=123#section2
ParameterDescription
keyA string literal representing the property to be set. Valid options include: 'hash', 'protocol', 'origin', 'username', 'password', 'hostname', 'port', 'query', or 'path'.
valueThe value to set for the specified property. It can be either a string or an object(query) with string keys and any values.
const url = new Url('http://localhost:8080/3rd-Eden/path/to/resource?name=John&id=123#section2')
url.set('query', { name: 'rakib', id: '5345345435' })
console.log(url.toString())
//http://localhost:8080/3rd-Eden/path/to/resource?name=rakib&id=5345345435#section2
1.0.1-0.1

12 days ago

1.0.9

12 days ago

1.0.10

12 days ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago