库函数

@Lib
url
解析url,获取协议、主机、端口、路径、文件名和query等数据
选项如果为true,将解析query数据
1. 引入
const fs = require('fs');
2. 使用
console.log(URL.parse('https://glpla.github.io/utils/wedding/p0.jpg?id=100&name=gl'));
Url {
  protocol: 'https:',
  slashes: true,
  auth: null,
  host: 'glpla.github.io',
  port: null,
  hostname: 'glpla.github.io',
  hash: null,
  search: '?id=100&name=gl',
  query: 'id=100&name=gl',
  pathname: '/utils/wedding/p0.jpg',
  path: '/utils/wedding/p0.jpg?id=100&name=gl',
  href: 'https://glpla.github.io/utils/wedding/p0.jpg?id=100&name=gl'
}
3. 解析query
console.log(URL.parse('https://glpla.github.io/utils/wedding/p0.jpg?id=100&name=gl', true));
Url {
  protocol: 'https:',
  slashes: true,
  auth: null,
  host: 'glpla.github.io',
  port: null,
  hostname: 'glpla.github.io',
  hash: null,
  search: '?id=100&name=gl',
  query: [Object: null prototype] { id: '100', name: 'gl' },
  pathname: '/utils/wedding/p0.jpg',
  path: '/utils/wedding/p0.jpg?id=100&name=gl',
  href: 'https://glpla.github.io/utils/wedding/p0.jpg?id=100&name=gl'
}