npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dy-url-kit

v1.1.0

Published

This very module is designed to parse urls. By default the urls are normalized.

Downloads

7

Readme

URL 处理工具

npm version npm downloads bundle License

功能描述

这是一个 TypeScript 工具,用于解析 URL 信息。

安装

npm install dy-url-kit

示例代码

import { parseURL, parseURLProtocol } from 'dy-url-kit'

// 一、 parseURL
// 1. parseURL("https://github.com/Xdy1579883916/dy-url-kit#readme")
// 2. parseURL("//github.com/Xdy1579883916/dy-url-kit#readme")
// 3. parseURL("/Xdy1579883916/dy-url-kit#readme", "https://github.com/")

// console: 

// {
//   "href": "https://github.com/Xdy1579883916/dy-url-kit#readme",
//   "url": "https://github.com/Xdy1579883916/dy-url-kit",
//   "origin": "https://github.com",
//   "protocol": "https:",
//   "host": "github.com",
//   "port": "",
//   "pathname": "/Xdy1579883916/dy-url-kit",
//   "search": "",
//   "hash": "readme",
//   "params": {},
//   "file": "dy-url-kit",
//   "domain": "github.com"
// }


// 二、 parseURLProtocol

// 1. parseURLProtocol("//github.com/Xdy1579883916/dy-url-kit#readme", "http:")
// 2. parseURLProtocol("github.com/Xdy1579883916/dy-url-kit#readme", "http:")

// console: 

// 'http://github.com/Xdy1579883916/dy-url-kit#readme'

// 3. https default 
// parseURLProtocol("github.com/Xdy1579883916/dy-url-kit#readme")

// console: 
// 'https://github.com/Xdy1579883916/dy-url-kit#readme'

函数列表

parseURLProtocol

将 URL 转换为带有协议的完整 URL。

参数:

  • url (string): 需要解析的 URL 字符串。
  • protocol (string, 默认值 'https:'): 如果 URL 不包含协议,则添加此协议。

返回值:

  • 返回带有正确协议的 URL 字符串。

TParsesURLRes

定义了解析 URL 后返回的对象结构。

属性:

  • href: 完整的 URL。
  • url: 格式化后的 URL。
  • origin: URL 的起源,包括协议和主机名。
  • protocol: URL 的协议部分。
  • host: URL 的主机名。
  • port: URL 的端口号。
  • pathname: URL 的路径。
  • search: URL 的查询字符串。
  • hash: URL 的哈希部分。
  • params: 查询字符串解析后的参数对象。
  • file: URL 路径中的文件名。
  • domain: URL 的顶级域名。

parseURL

解析 URL 并返回详细的 URL 组件。

参数:

  • url (string): 需要解析的 URL 字符串。
  • baseOrigin (string | URL, 可选): 基础 URL,用于解析相对 URL。

返回值:

  • 返回一个 TParsesURLRes 类型的对象,包含 URL 的各个组件。

License

MIT License © 2024-PRESENT XiaDeYu