@shencom/utils-url
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@shencom/utils-object

URL相关工具方法

Install

pnpm add @shencom/utils

# or

pnpm add @shencom/utils-url

Basic Usage

import { UrlParamsToObject } from '@shencom/utils';
// import { UrlParamsToObject } from '@shencom/utils-url';

Methods

UrlParamsToObject

  • 说明: url 参数转对象
  • 类型: (url?: string) => Record<string, string>
  • 参数:
    • url - 链接地址(默认: 当前地址)
  • 示例:
    // https://example.com
    UrlParamsToObject(); // {}
    
    // https://example.com?name=John&age=30
    UrlParamsToObject(); // {'name': 'John', 'age': '30'}
    
    // https://example.com/index.html?scid=123&aa=true#/detail?id=1
    UrlParamsToObject(); // {'scid': '123', 'aa': 'true'}

UrlParam

  • 说明: 获取 url 参数中指定的key
  • 类型: (key: string) => string | undefined
  • 参数:
    • key - 参数key
  • 示例:
    // https://example.com
    UrlParam(''); // undefined
    UrlParam('abc'); // undefined
    
    // https://example.com?name=John&age=30
    UrlParam('name'); // 'John'
    UrlParam('age'); // '30'
    
    // https://example.com/index.html?scid=123&aa=true#/detail?id=1
    UrlParam('scid'); // '123'
    UrlParam('aa'); // 'true'

Readme

Keywords

Package Sidebar

Install

npm i @shencom/utils-url

Weekly Downloads

2

Version

1.0.0

License

ISC

Unpacked Size

52.7 kB

Total Files

10

Last publish

Collaborators

  • shencom