1.0.0 • Published 7 months ago

@shencom/utils-url v1.0.0

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
7 months ago

@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'
1.0.0

7 months ago