Installations
npm install @rc-hooks/util
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>= 8.0.0
Node Version
8.11.1
NPM Version
lerna/3.16.4/node@v8.11.1+x64 (darwin)
Score
71.1
Supply Chain
89.6
Quality
81.4
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
validate.email 🚀
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Download Statistics
Total Downloads
20,464
Last Day
1
Last Week
3
Last Month
82
Last Year
1,558
Bundle Size
13.44 kB
Minified
4.13 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.1.81
Package Id
@rc-hooks/util@0.1.81
Unpacked Size
61.95 kB
Size
15.68 kB
File Count
75
NPM Version
lerna/3.16.4/node@v8.11.1+x64 (darwin)
Node Version
8.11.1
Total Downloads
Cumulative downloads
Total Downloads
20,464

No dependencies detected.
RcUtil - 工具函数、通用类型
这里包含了很多通用的小函数和通用的类型定义
guid
生成一个全局唯一的字符串,如果需要id在每一次请求的时候不变,需要要useMemo。
- 定义
function guid(): string
- 用法
1import React, {useMemo} from 'react' 2import {guid} from '@rc-hooks/util' 3 4function DemoComponent() { 5 6 const id = useMemo(() => guid(), []); 7 8 return ( 9 <div id={id}/> 10 ) 11}
type
获取一个变量的系统预设类型,不推荐使用此函数,因为他会影响typescript的类型推导。 对于基础类型建议使用typeof,对于系统类型,比如数组,用Array.isArray, 这样可以获取更好的typescript支持。
- 定义
function type(obj: any): string
- 用法
1import {type} from '@rc-hooks/util' 2 3type(1); // number 4type(''); // string 5type(Date.now()) // date
clone
克隆一个可以转换为json的对象,使用了内置的api。 使用JSON.stringify来实现的复制。
-
定义
function clone<T>(obj: T): T
-
泛型参数
- T 表示分组要克隆值的类型,通常不需要传递,利用TypeScript推导
-
用法
1import {clone} from '@rc-hooks/util' 2 3clone(1); // 1 4clone('abc'); // abc
deepClone
克隆任何对象,支持函数等非JSON类型
- 定义
function deepClone<T>(obj: T): T
- 泛型参数
- T 表示分组要克隆值的类型,通常不需要传递,利用TypeScript推导
- 用法
1import {deepClone} from '@rc-hooks/util' 2 3deepClone(1); // 1 4deepClone('abc'); // abc 5const fn = deepClone(() => 1); 6fn() // 1
UnionOmit
一个安全的交叉类型,UnionOmit会交叉两个类型,当名称有冲突的时,选取第一个,而不是报错。
- 定义
UnionOmit<T, K> = T & Omit<K, keyof T>
- 用法
1 2 import {UnionOmit} from '@rc-hooks/util' 3 4 interface Demo { 5 foo: string; 6 bar: string; 7 } 8 9 interface Other { 10 foo: number; 11 baz: string; 12 } 13 14 type DemoUnionOther = UnionOmit<Demo, Other> // {foo: sting, bar: string; baz: string} 15 type OtherUnionDemo = UnionOmit<Other, Demo> // {foo: number, bar: string; baz: string}

No vulnerabilities found.

No security vulnerabilities found.