@staryea/network-shared
TypeScript icon, indicating that this package has built-in type declarations

0.0.33 • Public • Published

@staryea/network-shared

工具包

安装

with pnpm

pnpm add @staryea/network-shared

with yarn

yarn add @staryea/network-shared

with npm

npm install @staryea/network-shared

apis

getQueryString

获取 url 中的参数

字段名 类型 描述 必传
query string 要获取的参数名
href string |null 地址

类型

declare const getQueryString: (query: string, href?: string) => string | null;

示例

import { getQueryString } from '@staryea/network-shared';
const url = 'http://example.com/?test=123&foo=bar';
const query = getQueryString('test');
console.log(query);
// 123

debounce

防抖

字段名 类型 描述 必传
func (...args: any[]) => any 需要防抖的函数
duration number 毫秒
immediate boolean 是否立即执行

类型

declare const debounce: <F extends (...args: any[]) => any>(
    func: F,
    duration?: number,
    immediate?: boolean
) => (...args: Parameters<F>) => ReturnType<F>;

示例

import { debounce } from '@staryea/network-shared';
const fn = debounce(() => {
    console.log('debounce');
}, 300);
fn();

throttle

节流

字段名 类型 描述 必传
func (...args: any[]) => any 节流函数
duration number 毫秒

类型

declare const throttle: <F extends (...args: any[]) => any>(func: F, duration?: number) => (...args: Parameters<F>) => ReturnType<F>;

示例

import { throttle } from '@staryea/network-shared';
const fn = throttle(() => {
    console.log('throttle');
}, 1000);
fn();

deepCopy

深拷贝

字段名 类型 描述 必传
data Array | Record<string | symbol, any> 要拷贝的数据

类型

declare const deepCopy: <T extends Array<T> | Record<string | symbol, any>>(data: T) => T;

示例

import { deepCopy } from '@staryea/network-shared';
const obj = { a: 1, b: 2 };
const copyObj = deepCopy(obj);
console.log(copyObj);

Readme

Keywords

Package Sidebar

Install

npm i @staryea/network-shared

Weekly Downloads

154

Version

0.0.33

License

MIT

Unpacked Size

108 kB

Total Files

92

Last publish

Collaborators

  • staryea-jiangwy