0.0.24 • Published 9 days ago
@staryea/network-shared v0.0.24
@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);
0.0.23
9 days ago
0.0.24
9 days ago
0.0.21
11 days ago
0.0.22
11 days ago
0.0.20
14 days ago
0.0.19
22 days ago
0.0.18-beta.1
1 month ago
0.0.18
1 month ago
0.0.17-beta.1
1 month ago
0.0.15
2 months ago
0.0.16
2 months ago
0.0.10
2 months ago
0.0.11
2 months ago
0.0.12
2 months ago
0.0.13
2 months ago
0.0.14
2 months ago
0.0.9
2 months ago
0.0.8
6 months ago
0.0.7
6 months ago
0.0.6
6 months ago
0.0.5
6 months ago
0.0.4
6 months ago
0.0.1
7 months ago