0.0.12 • Published 2 years ago

nv-facutil-simple-url v0.0.12

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

nv-facutil-simple-url

  • nv-facutil-simple-url
  • simple util of url, same as url.parse, more easy to use

install

  • npm install nv-facutil-simple-url

usage

const SURL = require("nv-facutil-simple-url");

 

example

var url = new SURL("https://name:passwd@www.ggl.com/a/b/c/?k1=v1&k0=v0#frag")
/*

> url.json()
{
  protocol: 'https',
  username: 'name',
  password: 'passwd',
  hostname: 'www.ggl.com',
  port: '',
  path: [ 'a', 'b', 'c' ],
  query: { k1: 'v1', k0: 'v0' },
  hash: 'frag'
}
>
*/

var url = new SURL({
  protocol: 'https',
  username: 'name',
  password: 'passwd',
  hostname: 'www.ggl.com',
  port: '',
  path: [ 'a', 'b', 'c' ],
  query: { k1: 'v1', k0: 'v0' },
  hash: 'frag'
})

/*
> url.dump()
'https://name:passwd@www.ggl.com/a/b/c?k1=v1&k0=v0#frag'
>
*/



> url.http()
undefined
> url.dump()
'http://name:passwd@www.ggl.com/a/b/c?k1=v1&k0=v0#frag'
>
> url.path
/a/b/c/
>
> url.path.prepend('A')
> url.dump()
'http://name:passwd@www.ggl.com/A/a/b/c?k1=v1&k0=v0#frag'
>
> url.path.rplc(3,'CCC')
undefined
> url.dump()
'http://name:passwd@www.ggl.com/A/a/b/CCC/B?k1=v1&k0=v0#frag'
> url
{
  protocol: 'http',
  username: 'name',
  password: 'passwd',
  hostname: 'www.ggl.com',
  port: '',
  path: [ 'A', 'a', 'b', 'CCC', 'B' ],
  query: { k1: 'v1', k0: 'v0' },
  hash: 'frag'
}
>

> url.port = 8080
8080
> url
{
  protocol: 'http',
  username: 'name',
  password: 'passwd',
  hostname: 'www.ggl.com',
  port: 8080,
  path: [ 'A', 'a', 'b', 'CCC', 'B' ],
  query: { k1: 'v1', k0: 'v0' },
  hash: 'frag'
}
> url.dump()
'http://name:passwd@www.ggl.com:8080/A/a/b/CCC/B?k1=v1&k0=v0#frag'
>
> url.https()
undefined
> url.port=""
''
> url.dump()
'https://name:passwd@www.ggl.com/A/a/b/CCC/B?k1=v1&k0=v0#frag'
> url
{
  protocol: 'https',
  username: 'name',
  password: 'passwd',
  hostname: 'www.ggl.com',
  port: '',
  path: [ 'A', 'a', 'b', 'CCC', 'B' ],
  query: { k1: 'v1', k0: 'v0' },
  hash: 'frag'
}
>
> url.path
/A/a/b/CCC/B/
> url.path.rm(1)
'a'
> url.dump()
'https://name:passwd@www.ggl.com/A/b/CCC/B?k1=v1&k0=v0#frag'
>

> url.unpw()
'name:passwd'
> url.rm_unpw()
undefined
> url.dump()
'https://www.ggl.com/A/b/CCC/B?k1=v1&k0=v0#frag'
>

METHODS

SURL

url.dump                  url.json
url.http                  url.https                 
               
url.protocol              
url.rm_unpw              url.unpw
url.username             url.password
url.hostname             url.port
url.path   
url.query
url.hash                

PATH

url.path.absize                url.path.append                url.path.dump
url.path.fst_                  url.path.iaft                  url.path.ibfr                  url.path.is_abs
url.path.is_rel                url.path.lst_                  url.path.lsti_                 url.path.pl_
url.path.prepend               url.path.relize                url.path.rm                    url.path.rplc
url.path.sp_                   url.path.which

API

LICENSE

  • ISC