0.1.5 • Published 4 years ago

@luohuidong/url v0.1.5

Weekly downloads
7
License
MIT
Repository
github
Last release
4 years ago

url

The url module provides utilities for URL resolution and parsing.

The structure of url

href structure

yarn add @luohuidong/url

Use npm:

npm i @luohuidong/url

Use yarn:

yarn add @luohuidong/url

How to use

import url from "url";

const parsedUrlObject = url.parse("https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash");

const formattedUrl = url.formatUrl({
  protocol: 'https',
  hostname: 'www.test.com',
  pathname: '/',
  query: {
    a: 1,
    b: 2
  },
  search: '?a=44&c=22'
})

API

parse

interface ParsedUrlObject {
  protocal: string;
  search: string;
  query: {
    [index: string]: string;
  };
};

let parse: (url: string) => ParsedUrlObject

format

interface UrlObject {
  protocol: string;
  hostname: string;
  port?: string;
  pathname: string;
  search?: string;
  query?: {
    [index: string]: string | number
  };
  hash?: string;
}

let format: (urlObj: UrlObject) => string;

example:

const formattedurl = url.format({
  protocol: 'https',
  hostname: 'luohuidong.cn',
  pathname: '/',
  query: {
    a: 'b',
    c: 'd'
  }
}))

// 'https://luohuidong.cn/?a=b&c=d'
0.1.4

4 years ago

0.1.5

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago