Node learning-NodeJS API

NodeJS API

URL

url.parse(urlString[,parseQueryString[,slashesDenoteHost]])

Parameter description: If
urlString converted url
parseQueryString is true, the query attribute will become an object, the default is false
slashesDenoteHost if true, the default is false, consider the following example //for/bar, it will be converted to

{
    
    host:'foo',pathname:'/bar'}

Instead of

{
    
    pathname:'//foo/bar'
let url =require('url')
let query_url= url.parse('http://www/baidu.com/query?id=123')
let url_str=url.parse('//foo/bar',true,true)
console.log(url_str)
console.log(query_url)

url.format(URL[,options])

Return a custom serializable URL string

let url = require('url')
const myURL= new URL('https://www.bing.com/test#/demo?query=1')
let url_obj=url.format(myURL)
console.log(url_obj)

url.resolve(from,to)

Resolve the URL from the base path to the directory path by the browser parsing href

const url = require('url')
url.resolve('/one/two/three', 'four');         // '/one/two/four'
url.resolve('http://example.com/', '/one');    // 'http://example.com/one'
url.resolve('http://example.com/one', '/two'); // 'http://example.com/two'

querystring query string

querystring.escape(str)

Percent coding

let querystring = require('querystring')
let str = querystring.escape('百分比编码')

querystring.parse(str[,sep[,eq[,options]]])

Parse URL query string

let querystring = require('querystring')
let str = querystring.parse('w=%D6%D0%CE%C4&foo=bar')
console.log(str.w);
let querystring = require("querystring");
let str = querystring.parse("foo=bar&abc=xyz&abc=123")
console.log(str);
// [Object: null prototype] {
    
     foo: 'bar', abc: [ 'xyz', '123' ] }

querystring.stringify(obj[,sep[,eq[,options]]])

Object serialized into URL query string

querystring.stringify({
    
    foo:'bar',baz:['qux','quux'],corge:''})

querystring.unescape(str)

Perform URL percent-encoded character decoding on the given str

let querystring = require("querystring");
let str = querystring.unescape("%E7%99%BE%E5%88%86%E6%AF%94%E7%BC%96%E7%A0%81")
console.log(str); //百分比编码

Guess you like

Origin blog.csdn.net/weixin_53985543/article/details/115012481