工具包
pnpm add @staryea/network-shared
yarn add @staryea/network-shared
npm install @staryea/network-shared
字段名 |
类型 |
描述 |
必传 |
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
字段名 |
类型 |
描述 |
必传 |
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();
字段名 |
类型 |
描述 |
必传 |
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();
字段名 |
类型 |
描述 |
必传 |
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);