@daysnap/utils
Version:
3,013 lines (1,778 loc) • 65.6 kB
Markdown
[@daysnap/utils](README.md) / Exports
# @daysnap/utils
## Table of contents
### Classes
- [Poller](classes/Poller.md)
- [Storage](classes/Storage.md)
### Interfaces
- [EventBusCallback](interfaces/EventBusCallback.md)
- [PollerOptions](interfaces/PollerOptions.md)
- [StorageManager](interfaces/StorageManager.md)
- [Trap](interfaces/Trap.md)
### Type Aliases
- [PollerTask](modules.md#pollertask)
### Variables
- [eventBus](modules.md#eventbus)
- [trap](modules.md#trap)
### Functions
- [ato](modules.md#ato)
- [atob](modules.md#atob)
- [base64ToBlob](modules.md#base64toblob)
- [blobToBase64](modules.md#blobtobase64)
- [btoa](modules.md#btoa)
- [cached](modules.md#cached)
- [camelCase](modules.md#camelcase)
- [canvasToBlob](modules.md#canvastoblob)
- [capitalize](modules.md#capitalize)
- [chooseMedia](modules.md#choosemedia)
- [clamp](modules.md#clamp)
- [clone](modules.md#clone)
- [cloneSimple](modules.md#clonesimple)
- [colorGenByHash](modules.md#colorgenbyhash)
- [compareVersion](modules.md#compareversion)
- [compressImage](modules.md#compressimage)
- [crToBr](modules.md#crtobr)
- [createFactory](modules.md#createfactory)
- [createLinearFunction](modules.md#createlinearfunction)
- [createTrapInstance](modules.md#createtrapinstance)
- [createWithLoading](modules.md#createwithloading)
- [crlfToBr](modules.md#crlftobr)
- [debounce](modules.md#debounce)
- [downloadFile](modules.md#downloadfile)
- [each](modules.md#each)
- [exitFullscreen](modules.md#exitfullscreen)
- [factory](modules.md#factory)
- [filterBankCardNo](modules.md#filterbankcardno)
- [filterCRLF](modules.md#filtercrlf)
- [filterEmoji](modules.md#filteremoji)
- [filterEmptyValue](modules.md#filteremptyvalue)
- [filterIdCard](modules.md#filteridcard)
- [filterName](modules.md#filtername)
- [filterPhone](modules.md#filterphone)
- [filterString](modules.md#filterstring)
- [formatAmount](modules.md#formatamount)
- [formatDate](modules.md#formatdate)
- [formatDateStr](modules.md#formatdatestr)
- [formatDateToZN](modules.md#formatdatetozn)
- [formatFileSize](modules.md#formatfilesize)
- [formatGapDate](modules.md#formatgapdate)
- [formatMessage](modules.md#formatmessage)
- [formatPathParams](modules.md#formatpathparams)
- [getBlobByUrl](modules.md#getblobbyurl)
- [getCache](modules.md#getcache)
- [getDateBoundsByMonths](modules.md#getdateboundsbymonths)
- [getDayMillisecond](modules.md#getdaymillisecond)
- [getDaysOfMonth](modules.md#getdaysofmonth)
- [getImageInfo](modules.md#getimageinfo)
- [getLocal](modules.md#getlocal)
- [getMonthBounds](modules.md#getmonthbounds)
- [getRandom](modules.md#getrandom)
- [getRandomColor](modules.md#getrandomcolor)
- [getRandomNumber](modules.md#getrandomnumber)
- [getRangeDate](modules.md#getrangedate)
- [getScrollTop](modules.md#getscrolltop)
- [getVideoInfo](modules.md#getvideoinfo)
- [getWeekBounds](modules.md#getweekbounds)
- [getWeekday](modules.md#getweekday)
- [inBrowser](modules.md#inbrowser)
- [insertLink](modules.md#insertlink)
- [insertScript](modules.md#insertscript)
- [insertStyle](modules.md#insertstyle)
- [isAmount](modules.md#isamount)
- [isAndroid](modules.md#isandroid)
- [isArray](modules.md#isarray)
- [isBoolean](modules.md#isboolean)
- [isChinese](modules.md#ischinese)
- [isDate](modules.md#isdate)
- [isEmail](modules.md#isemail)
- [isEmpty](modules.md#isempty)
- [isEmptyArray](modules.md#isemptyarray)
- [isEmptyObject](modules.md#isemptyobject)
- [isError](modules.md#iserror)
- [isFunction](modules.md#isfunction)
- [isIE](modules.md#isie)
- [isIOS](modules.md#isios)
- [isIdCard](modules.md#isidcard)
- [isJSONString](modules.md#isjsonstring)
- [isLan](modules.md#islan)
- [isLeapYear](modules.md#isleapyear)
- [isLicenseCode](modules.md#islicensecode)
- [isMobile](modules.md#ismobile)
- [isNativeFunction](modules.md#isnativefunction)
- [isNull](modules.md#isnull)
- [isNumber](modules.md#isnumber)
- [isObject](modules.md#isobject)
- [isPhone](modules.md#isphone)
- [isPromise](modules.md#ispromise)
- [isRegExp](modules.md#isregexp)
- [isString](modules.md#isstring)
- [isType](modules.md#istype)
- [isUndefined](modules.md#isundefined)
- [isUrl](modules.md#isurl)
- [isValidDate](modules.md#isvaliddate)
- [isWeChat](modules.md#iswechat)
- [isWeChatMiniProgram](modules.md#iswechatminiprogram)
- [isWeixin](modules.md#isweixin)
- [isWindow](modules.md#iswindow)
- [kebabCase](modules.md#kebabcase)
- [lfToBr](modules.md#lftobr)
- [listGenerator](modules.md#listgenerator)
- [makePhoneCall](modules.md#makephonecall)
- [mousewheel](modules.md#mousewheel)
- [nf](modules.md#nf)
- [normalizeDate](modules.md#normalizedate)
- [normalizePath](modules.md#normalizepath)
- [omit](modules.md#omit)
- [padding](modules.md#padding)
- [parseDate](modules.md#parsedate)
- [parseDecimalString](modules.md#parsedecimalstring)
- [parseError](modules.md#parseerror)
- [parseNumberString](modules.md#parsenumberstring)
- [parseObject](modules.md#parseobject)
- [parsePath](modules.md#parsepath)
- [parseQuery](modules.md#parsequery)
- [parseQueryString](modules.md#parsequerystring)
- [pascalCase](modules.md#pascalcase)
- [pick](modules.md#pick)
- [replaceCrlf](modules.md#replacecrlf)
- [requestFullScreen](modules.md#requestfullscreen)
- [reserve](modules.md#reserve)
- [rgbToHex](modules.md#rgbtohex)
- [round](modules.md#round)
- [roundUpToNearestInteger](modules.md#rounduptonearestinteger)
- [scrollToTop](modules.md#scrolltotop)
- [setScrollTop](modules.md#setscrolltop)
- [sleep](modules.md#sleep)
- [splitArray](modules.md#splitarray)
- [stringTrim](modules.md#stringtrim)
- [stringifyQuery](modules.md#stringifyquery)
- [stringifyQueryString](modules.md#stringifyquerystring)
- [throttle](modules.md#throttle)
- [throttleLeading](modules.md#throttleleading)
- [throttleTrailing](modules.md#throttletrailing)
- [toCDB](modules.md#tocdb)
- [toDBC](modules.md#todbc)
- [typeOf](modules.md#typeof)
- [withCache](modules.md#withcache)
- [withPreventConsecutiveClicks](modules.md#withpreventconsecutiveclicks)
## Type Aliases
### PollerTask
Ƭ **PollerTask**: (`poller`: [`Poller`](classes/Poller.md)) => `void` \| `Promise`<`void`\>
#### Type declaration
▸ (`poller`): `void` \| `Promise`<`void`\>
##### Parameters
| Name | Type |
| :------ | :------ |
| `poller` | [`Poller`](classes/Poller.md) |
##### Returns
`void` \| `Promise`<`void`\>
#### Defined in
[poller.ts:7](https://github.com/daysnap/utils/blob/fb8fac4/src/poller.ts#L7)
## Variables
### eventBus
• `Const` **eventBus**: `Object`
#### Type declaration
| Name | Type |
| :------ | :------ |
| `clear` | (`eventName?`: `string`) => `void` |
| `emit` | (`eventName`: `string`, ...`args`: `any`[]) => `void` |
| `off` | (`eventName`: `string`, `callback`: [`EventBusCallback`](interfaces/EventBusCallback.md)) => `void` |
| `on` | (`eventName`: `string`, `callback`: [`EventBusCallback`](interfaces/EventBusCallback.md)) => () => `void` |
#### Defined in
[eventBus.ts:38](https://github.com/daysnap/utils/blob/fb8fac4/src/eventBus.ts#L38)
___
### trap
• `Const` **trap**: [`Trap`](interfaces/Trap.md)
#### Defined in
[trap.ts:15](https://github.com/daysnap/utils/blob/fb8fac4/src/trap.ts#L15)
## Functions
### ato
▸ **ato**<`T`, `K`\>(`options`, `labelKey`): `Record`<`T`[`K`], `T`\>
数组转换称对象
const options = [
{label: '男', value: '1'}
{label: '女', value: '2'}
]
const res = ato(options, 'value')
res = { '1': {label: '男', value: '1'}, '2': {label: '女', value: '2'} }
const res = ato(options, 'value', 'label')
res = { '1': '男', '2': '女' }
#### Type parameters
| Name | Type |
| :------ | :------ |
| `T` | extends `Record`<`string`, `any`\> |
| `K` | extends `string` \| `number` \| `symbol` |
#### Parameters
| Name | Type |
| :------ | :------ |
| `options` | readonly `T`[] |
| `labelKey` | `K` |
#### Returns
`Record`<`T`[`K`], `T`\>
#### Defined in
[ato.ts:12](https://github.com/daysnap/utils/blob/fb8fac4/src/ato.ts#L12)
▸ **ato**<`T`, `K`, `V`\>(`options`, `labelKey`, `valueKey`): `Record`<`T`[`K`], `T`[`V`]\>
#### Type parameters
| Name | Type |
| :------ | :------ |
| `T` | extends `Record`<`string`, `any`\> |
| `K` | extends `string` \| `number` \| `symbol` |
| `V` | extends `string` \| `number` \| `symbol` |
#### Parameters
| Name | Type |
| :------ | :------ |
| `options` | readonly `T`[] |
| `labelKey` | `K` |
| `valueKey` | `V` |
#### Returns
`Record`<`T`[`K`], `T`[`V`]\>
#### Defined in
[ato.ts:16](https://github.com/daysnap/utils/blob/fb8fac4/src/ato.ts#L16)
___
### atob
▸ **atob**(`string`): `string`
#### Parameters
| Name | Type |
| :------ | :------ |
| `string` | `string` |
#### Returns
`string`
#### Defined in
[decode.ts:41](https://github.com/daysnap/utils/blob/fb8fac4/src/decode.ts#L41)
___
### base64ToBlob
▸ **base64ToBlob**(`base64`, `contentType?`): `Blob`
base64 转 blob
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `base64` | `string` | base64字符串 |
| `contentType?` | `string` | 文件类型 |
#### Returns
`Blob`
#### Defined in
[base64ToBlob.ts:6](https://github.com/daysnap/utils/blob/fb8fac4/src/base64ToBlob.ts#L6)
___
### blobToBase64
▸ **blobToBase64**(`blob`): `Promise`<`string` \| `ArrayBuffer`\>
blob 转 base64
#### Parameters
| Name | Type |
| :------ | :------ |
| `blob` | `Blob` |
#### Returns
`Promise`<`string` \| `ArrayBuffer`\>
#### Defined in
[blobToBase64.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/blobToBase64.ts#L4)
___
### btoa
▸ **btoa**(`string`): `string`
#### Parameters
| Name | Type |
| :------ | :------ |
| `string` | `string` |
#### Returns
`string`
#### Defined in
[decode.ts:8](https://github.com/daysnap/utils/blob/fb8fac4/src/decode.ts#L8)
___
### cached
▸ **cached**<`T`\>(`fn`): (...`args`: `Parameters`<`T`\>) => `ReturnType`<`T`\>
缓存、记忆函数,缓存函数的运算结果
需注意缓存的函数得是纯函数
#### Type parameters
| Name | Type |
| :------ | :------ |
| `T` | extends (...`args`: `any`[]) => `any` |
#### Parameters
| Name | Type |
| :------ | :------ |
| `fn` | `T` |
#### Returns
`fn`
▸ (`...args`): `ReturnType`<`T`\>
##### Parameters
| Name | Type |
| :------ | :------ |
| `...args` | `Parameters`<`T`\> |
##### Returns
`ReturnType`<`T`\>
#### Defined in
[cached.ts:5](https://github.com/daysnap/utils/blob/fb8fac4/src/cached.ts#L5)
___
### camelCase
▸ **camelCase**(`str`): `string`
驼峰
camelCase('hello-world') => helloWorld
#### Parameters
| Name | Type |
| :------ | :------ |
| `str` | `string` |
#### Returns
`string`
#### Defined in
[camelCase.ts:5](https://github.com/daysnap/utils/blob/fb8fac4/src/camelCase.ts#L5)
___
### canvasToBlob
▸ **canvasToBlob**(`canvas`, `type?`, `quality?`): `Promise`<`Blob`\>
canvas 转 blob 文件
#### Parameters
| Name | Type |
| :------ | :------ |
| `canvas` | `HTMLCanvasElement` |
| `type?` | `string` |
| `quality?` | `any` |
#### Returns
`Promise`<`Blob`\>
#### Defined in
[canvasToBlob.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/canvasToBlob.ts#L4)
___
### capitalize
▸ **capitalize**(`str`): `string`
首字母大写
capitalize('hello world') => Hello world
#### Parameters
| Name | Type |
| :------ | :------ |
| `str` | `string` |
#### Returns
`string`
#### Defined in
[capitalize.ts:5](https://github.com/daysnap/utils/blob/fb8fac4/src/capitalize.ts#L5)
___
### chooseMedia
▸ **chooseMedia**(`options?`): `Promise`<`File`[]\>
创建 input 触发选择文件
因为 iOS 必须把 input 元素添加到 document 才会获取到文件,所以这里做了兼容处理
#### Parameters
| Name | Type |
| :------ | :------ |
| `options` | `Object` |
| `options.accept?` | `string` |
| `options.multiple?` | `boolean` |
#### Returns
`Promise`<`File`[]\>
#### Defined in
[chooseMedia.ts:5](https://github.com/daysnap/utils/blob/fb8fac4/src/chooseMedia.ts#L5)
___
### clamp
▸ **clamp**(`min`, `val`, `max`): `number`
首选值超出最小值,返回最小值;首选值超出最大值,返回最大值;其余返回首选值
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `min` | `number` | 最小值 |
| `val` | `number` | - |
| `max` | `number` | 最大值 |
#### Returns
`number`
#### Defined in
[clamp.ts:7](https://github.com/daysnap/utils/blob/fb8fac4/src/clamp.ts#L7)
___
### clone
▸ **clone**<`T`\>(`source`): `T`
深拷贝
#### Type parameters
| Name | Type |
| :------ | :------ |
| `T` | extends `Record`<`string`, `any`\> |
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `source` | `T` | 需要转换的值 |
#### Returns
`T`
#### Defined in
[clone.ts:8](https://github.com/daysnap/utils/blob/fb8fac4/src/clone.ts#L8)
___
### cloneSimple
▸ **cloneSimple**<`T`\>(`source`): `T`
拷贝对象
#### Type parameters
| Name |
| :------ |
| `T` |
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `source` | `T` | 需要转换的值 需要注意 当值为 undefined、function、symbol 会在转换过程中被忽略 |
#### Returns
`T`
#### Defined in
[cloneSimple.ts:7](https://github.com/daysnap/utils/blob/fb8fac4/src/cloneSimple.ts#L7)
___
### colorGenByHash
▸ **colorGenByHash**(`str`): `string`
根据字符串hash值生成颜色值
#### Parameters
| Name | Type |
| :------ | :------ |
| `str` | `string` |
#### Returns
`string`
#### Defined in
[createHexColorByHash.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/createHexColorByHash.ts#L4)
___
### compareVersion
▸ **compareVersion**(`nv`, `v`): ``-1`` \| ``0`` \| ``1``
比对版本
-1 => nv < v
0 => nv === v
1 => nv > v
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `nv` | `string` | 新版本 |
| `v` | `string` | 版本 |
#### Returns
``-1`` \| ``0`` \| ``1``
#### Defined in
[compareVersion.ts:9](https://github.com/daysnap/utils/blob/fb8fac4/src/compareVersion.ts#L9)
___
### compressImage
▸ **compressImage**(`image`, `mw`): `Promise`<`HTMLCanvasElement`\>
利用 canvas 压缩图片
#### Parameters
| Name | Type |
| :------ | :------ |
| `image` | `HTMLImageElement` |
| `mw` | `number` |
#### Returns
`Promise`<`HTMLCanvasElement`\>
#### Defined in
[compressImage.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/compressImage.ts#L4)
___
### crToBr
▸ **crToBr**(`v`): `string`
\r to <br/>
#### Parameters
| Name | Type |
| :------ | :------ |
| `v` | `string` |
#### Returns
`string`
#### Defined in
[crToBr.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/crToBr.ts#L4)
___
### createFactory
▸ **createFactory**<`T`\>(`initial`): readonly [(`value`: `T`) => `T`, () => `T`]
创建工厂函数
#### Type parameters
| Name |
| :------ |
| `T` |
#### Parameters
| Name | Type |
| :------ | :------ |
| `initial` | `T` |
#### Returns
readonly [(`value`: `T`) => `T`, () => `T`]
#### Defined in
[createFactory.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/createFactory.ts#L4)
___
### createLinearFunction
▸ **createLinearFunction**(`x1`, `x2`, `y1`, `y2`): (`x`: `number`) => `number`
创建一个线性函数
主要用于动画值计算
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `x1` | `number` | 坐标轴 x1 |
| `x2` | `number` | 坐标轴 x2 |
| `y1` | `number` | 坐标轴 y1 |
| `y2` | `number` | 坐标轴 y2 |
#### Returns
`fn`
▸ (`x`): `number`
##### Parameters
| Name | Type |
| :------ | :------ |
| `x` | `number` |
##### Returns
`number`
#### Defined in
[createLinearFunction.ts:9](https://github.com/daysnap/utils/blob/fb8fac4/src/createLinearFunction.ts#L9)
___
### createTrapInstance
▸ **createTrapInstance**<`T`\>(`id`): `Object`
#### Type parameters
| Name | Type |
| :------ | :------ |
| `T` | `any` |
#### Parameters
| Name | Type |
| :------ | :------ |
| `id` | `string` |
#### Returns
`Object`
| Name | Type |
| :------ | :------ |
| `create` | (`cb`: (`data`: `T`) => `void`) => `void` |
| `delete` | () => `void` |
| `trigger` | (`data?`: `T`) => `void` |
#### Defined in
[trap.ts:49](https://github.com/daysnap/utils/blob/fb8fac4/src/trap.ts#L49)
___
### createWithLoading
▸ **createWithLoading**<`O`\>(`showLoading`, `defaultOptions?`): <T\>(`fn`: `T`, `options`: `WithFalse`<`O`\>) => (...`params`: [...Parameters<T\>[], WithFalse<O\>?]) => `Promise`<`Awaited`<`ReturnType`<`T`\>\>\>
loading 生成器
const withLoading = createWithLoading(() => showLoading())
const fn = withLoading(async () => { // ... })
fn() 执行的时候就会执行showLoading
#### Type parameters
| Name | Type |
| :------ | :------ |
| `O` | `any` |
#### Parameters
| Name | Type |
| :------ | :------ |
| `showLoading` | (`options`: `O`) => `Loose`<{ `close`: () => `any` }\> |
| `defaultOptions?` | `O` |
#### Returns
`fn`
▸ <`T`\>(`fn`, `options?`): (...`params`: [...Parameters<T\>[], WithFalse<O\>?]) => `Promise`<`Awaited`<`ReturnType`<`T`\>\>\>
##### Type parameters
| Name | Type |
| :------ | :------ |
| `T` | extends (...`args`: `any`[]) => `Promise`<`any`\> |
##### Parameters
| Name | Type |
| :------ | :------ |
| `fn` | `T` |
| `options` | `WithFalse`<`O`\> |
##### Returns
`fn`
▸ (`...params`): `Promise`<`Awaited`<`ReturnType`<`T`\>\>\>
##### Parameters
| Name | Type |
| :------ | :------ |
| `...params` | [...Parameters<T\>[], WithFalse<O\>?] |
##### Returns
`Promise`<`Awaited`<`ReturnType`<`T`\>\>\>
#### Defined in
[createWithLoading.ts:11](https://github.com/daysnap/utils/blob/fb8fac4/src/createWithLoading.ts#L11)
___
### crlfToBr
▸ **crlfToBr**(`v`): `string`
\r \n to <br/>
#### Parameters
| Name | Type |
| :------ | :------ |
| `v` | `string` |
#### Returns
`string`
#### Defined in
[crlfToBr.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/crlfToBr.ts#L4)
___
### debounce
▸ **debounce**<`T`\>(`fn`, `ms`): (`this`: `unknown`, ...`args`: `Parameters`<`T`\>) => `void`
防抖函数
事件频繁触发,只会执行最后一次
#### Type parameters
| Name | Type |
| :------ | :------ |
| `T` | extends (...`args`: `any`[]) => `any` |
#### Parameters
| Name | Type |
| :------ | :------ |
| `fn` | `T` |
| `ms` | `number` |
#### Returns
`fn`
▸ (`this`, `...args`): `void`
##### Parameters
| Name | Type |
| :------ | :------ |
| `this` | `unknown` |
| `...args` | `Parameters`<`T`\> |
##### Returns
`void`
#### Defined in
[debounce.ts:5](https://github.com/daysnap/utils/blob/fb8fac4/src/debounce.ts#L5)
___
### downloadFile
▸ **downloadFile**(`data`, `options?`): `void`
通过 a 标签下载文件
#### Parameters
| Name | Type |
| :------ | :------ |
| `data` | `string` \| `Blob` \| `MediaSource` |
| `options?` | `Object` |
| `options.fileName?` | `string` |
#### Returns
`void`
#### Defined in
[downloadFile.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/downloadFile.ts#L4)
___
### each
▸ **each**<`T`\>(`data`, `callback`): `void`
支持遍历数组和对象
#### Type parameters
| Name |
| :------ |
| `T` |
#### Parameters
| Name | Type |
| :------ | :------ |
| `data` | `T`[] |
| `callback` | (`item`: `T`, `index`: `number`) => `void` |
#### Returns
`void`
#### Defined in
[each.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/each.ts#L4)
▸ **each**<`T`\>(`data`, `callback`): `void`
#### Type parameters
| Name |
| :------ |
| `T` |
#### Parameters
| Name | Type |
| :------ | :------ |
| `data` | `Record`<`string`, `T`\> |
| `callback` | (`item`: `T`, `key`: `string`) => `void` |
#### Returns
`void`
#### Defined in
[each.ts:8](https://github.com/daysnap/utils/blob/fb8fac4/src/each.ts#L8)
___
### exitFullscreen
▸ **exitFullscreen**(): `Promise`<`any`\>
退出全屏
成功则 resolve , 如果不支持退出全屏或退出失败则 rejected
[MDN Reference](https://developer.mozilla.org/zh-CN/docs/Web/API/Document/exitFullscreen)
#### Returns
`Promise`<`any`\>
#### Defined in
[exitFullscreen.ts:6](https://github.com/daysnap/utils/blob/fb8fac4/src/exitFullscreen.ts#L6)
___
### factory
▸ **factory**(`type`): `Object`
#### Parameters
| Name | Type |
| :------ | :------ |
| `type` | ``"sessionStorage"`` \| ``"localStorage"`` |
#### Returns
`Object`
| Name | Type |
| :------ | :------ |
| `clear` | () => `void` |
| `generate` | <T\>(`key`: `string`) => { `getItem`: (`defaultVal?`: `Partial`<`T`\>) => `T` ; `removeItem`: () => `void` ; `setItem`: (`val`: `T`) => `T` ; `updateItem`: (`val`: `Partial`<`T`\>) => `T` } |
| `getItem` | <T\>(`key`: `string`, `defaultVal`: ``null`` \| `Partial`<`T`\>) => `T` |
| `removeItem` | (`key`: `string`) => `void` |
| `setItem` | <T\>(`key`: `string`, `val`: `T`) => `T` |
| `updateItem` | <T\>(`key`: `string`, `val`: `Partial`<`T`\>) => `T` |
#### Defined in
[storage/factory.ts:11](https://github.com/daysnap/utils/blob/fb8fac4/src/storage/factory.ts#L11)
___
### filterBankCardNo
▸ **filterBankCardNo**(`val`): `string`
过滤银行卡号
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `string` |
#### Returns
`string`
#### Defined in
[filterBankCardNo.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/filterBankCardNo.ts#L4)
___
### filterCRLF
▸ **filterCRLF**(`v`): `string`
替换字符串里面的回车换行符
**`Deprecated`**
请使用
**`See`**
[crlfToBr](modules.md#crlftobr).
#### Parameters
| Name | Type |
| :------ | :------ |
| `v` | `string` |
#### Returns
`string`
#### Defined in
[crlfToBr.ts:12](https://github.com/daysnap/utils/blob/fb8fac4/src/crlfToBr.ts#L12)
___
### filterEmoji
▸ **filterEmoji**(`val`): `string`
过滤emoji
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `string` |
#### Returns
`string`
#### Defined in
[filterEmoji.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/filterEmoji.ts#L4)
___
### filterEmptyValue
▸ **filterEmptyValue**(`obj`, `expand?`): `Record`<`string`, `any`\>
过滤对象的 undefined null '' 属性,返回一个新对象
#### Parameters
| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `obj` | `Record`<`string`, `any`\> | `undefined` | 需要过滤的对象 |
| `expand` | `boolean` \| (`key`: `string`, `value`: `any`) => `boolean` | `false` | 如果是传的是布尔类型 true, 则还会过滤空数组、空对象的情况 |
#### Returns
`Record`<`string`, `any`\>
#### Defined in
[filterEmptyValue.ts:12](https://github.com/daysnap/utils/blob/fb8fac4/src/filterEmptyValue.ts#L12)
___
### filterIdCard
▸ **filterIdCard**(`val`): `string`
身份证号码加 *
430421202312121234 => 430421********1234
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `string` |
#### Returns
`string`
#### Defined in
[filterIdCard.ts:5](https://github.com/daysnap/utils/blob/fb8fac4/src/filterIdCard.ts#L5)
___
### filterName
▸ **filterName**(`val`): `string`
过滤姓名
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `string` |
#### Returns
`string`
#### Defined in
[filterName.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/filterName.ts#L4)
___
### filterPhone
▸ **filterPhone**(`val`, `sep?`): `string`
手机号加 *
filterPhone('13177778888') => 131****8888
filterPhone('13177778888', ' ') => 131 **** 8888
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `val` | `string` | `undefined` |
| `sep` | `string` | `''` |
#### Returns
`string`
#### Defined in
[filterPhone.ts:6](https://github.com/daysnap/utils/blob/fb8fac4/src/filterPhone.ts#L6)
___
### filterString
▸ **filterString**(`val`, `sep?`, `start?`, `end?`): `string`
过滤字符串
const str = filterString('13188888888', '*', 3, 7)
str = '131****8888'
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `val` | `string` | `undefined` |
| `sep` | `string` | `'*'` |
| `start` | `number` | `0` |
| `end?` | `number` | `undefined` |
#### Returns
`string`
#### Defined in
[filterString.ts:6](https://github.com/daysnap/utils/blob/fb8fac4/src/filterString.ts#L6)
___
### formatAmount
▸ **formatAmount**(`s`, `radix?`): `string`
格式化金额,默认元
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `s` | `string` \| `number` | `undefined` |
| `radix` | `number` | `1` |
#### Returns
`string`
#### Defined in
[formatAmount.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/formatAmount.ts#L4)
___
### formatDate
▸ **formatDate**(`val?`, `fmt?`): `string`
格式化日期
默认的当前日期 yyyy-MM-dd hh:mm:ss
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `val` | `string` \| `number` \| `Date` | `undefined` |
| `fmt` | `string` | `'yyyy-MM-dd hh:mm:ss'` |
#### Returns
`string`
#### Defined in
[formatDate.ts:7](https://github.com/daysnap/utils/blob/fb8fac4/src/formatDate.ts#L7)
___
### formatDateStr
▸ **formatDateStr**(`v`): `Date`
str 转换成 date
fix iOS 日期时间格式如果是 - 就会报错的问题
**`Deprecated`**
请使用
**`See`**
[normalizeDate](modules.md#normalizedate).
#### Parameters
| Name | Type |
| :------ | :------ |
| `v` | `string` |
#### Returns
`Date`
#### Defined in
[formatDateStr.ts:6](https://github.com/daysnap/utils/blob/fb8fac4/src/formatDateStr.ts#L6)
___
### formatDateToZN
▸ **formatDateToZN**(`v`): `string`
#### Parameters
| Name | Type |
| :------ | :------ |
| `v` | `string` \| `number` \| `Date` |
#### Returns
`string`
#### Defined in
[formartDateToZN.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/formartDateToZN.ts#L4)
___
### formatFileSize
▸ **formatFileSize**(`bytes`, `decimals?`): `string`
格式化字节大小
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `bytes` | `number` | `undefined` |
| `decimals` | `number` | `2` |
#### Returns
`string`
#### Defined in
[formatFileSize.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/formatFileSize.ts#L4)
___
### formatGapDate
▸ **formatGapDate**(`val`, `gap?`): `string`
yyyyMMdd -> yyyy-MM-dd
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `val` | `string` \| `number` | `undefined` |
| `gap` | `string` | `'-'` |
#### Returns
`string`
#### Defined in
[formatGapDate.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/formatGapDate.ts#L4)
___
### formatMessage
▸ **formatMessage**(`message`, `keys?`): `string`
格式化消息
formatMessage({ a: '123', b: { ba: '456' } }, ['a']) => '123'
formatMessage({ a: '123', b: { ba: '456' } }, ['b.ba']) => '456'
#### Parameters
| Name | Type |
| :------ | :------ |
| `message` | `unknown` |
| `keys` | `string`[] |
#### Returns
`string`
#### Defined in
[formatMessage.ts:11](https://github.com/daysnap/utils/blob/fb8fac4/src/formatMessage.ts#L11)
___
### formatPathParams
▸ **formatPathParams**(`path`, `params?`): `Object`
格式化字符串参数,一般用来处理 api path params
const url = 'api/v1/user/{id}'
const { path, rest } = formatPathParams(url, { id: 123, xxx: 1 })
path = 'api/v1/user/123'
rest = { xxx: 1 }
#### Parameters
| Name | Type |
| :------ | :------ |
| `path` | `string` |
| `params` | `Record`<`string`, `any`\> |
#### Returns
`Object`
| Name | Type |
| :------ | :------ |
| `path` | `string` |
| `rest` | {} |
#### Defined in
[formatPathParams.ts:8](https://github.com/daysnap/utils/blob/fb8fac4/src/formatPathParams.ts#L8)
___
### getBlobByUrl
▸ **getBlobByUrl**(`url`): `Promise`<`Blob`\>
根据在线 url 返回 blob
#### Parameters
| Name | Type |
| :------ | :------ |
| `url` | `string` |
#### Returns
`Promise`<`Blob`\>
#### Defined in
[getBlobByUrl.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/getBlobByUrl.ts#L4)
___
### getCache
▸ **getCache**(): `Object`
#### Returns
`Object`
| Name | Type |
| :------ | :------ |
| `clear` | () => `void` |
| `generate` | <T\>(`key`: `string`) => { `getItem`: (`defaultVal?`: `Partial`<`T`\>) => `T` ; `removeItem`: () => `void` ; `setItem`: (`val`: `T`) => `T` ; `updateItem`: (`val`: `Partial`<`T`\>) => `T` } |
| `getItem` | <T\>(`key`: `string`, `defaultVal`: ``null`` \| `Partial`<`T`\>) => `T` |
| `removeItem` | (`key`: `string`) => `void` |
| `setItem` | <T\>(`key`: `string`, `val`: `T`) => `T` |
| `updateItem` | <T\>(`key`: `string`, `val`: `Partial`<`T`\>) => `T` |
#### Defined in
[storage/index.ts:10](https://github.com/daysnap/utils/blob/fb8fac4/src/storage/index.ts#L10)
___
### getDateBoundsByMonths
▸ **getDateBoundsByMonths**(`monthsCount`, `date`): [`Date`, `Date`]
获取月份开始时间、结束时间
#### Parameters
| Name | Type |
| :------ | :------ |
| `monthsCount` | `number` |
| `date` | `string` \| `number` \| `Date` |
#### Returns
[`Date`, `Date`]
#### Defined in
[getDateBoundsByMonths.ts:8](https://github.com/daysnap/utils/blob/fb8fac4/src/getDateBoundsByMonths.ts#L8)
▸ **getDateBoundsByMonths**(`monthsCount`, `date`, `fmt`): [`string`, `string`]
#### Parameters
| Name | Type |
| :------ | :------ |
| `monthsCount` | `number` |
| `date` | `string` \| `number` \| `Date` |
| `fmt` | `string` |
#### Returns
[`string`, `string`]
#### Defined in
[getDateBoundsByMonths.ts:12](https://github.com/daysnap/utils/blob/fb8fac4/src/getDateBoundsByMonths.ts#L12)
___
### getDayMillisecond
▸ **getDayMillisecond**(`day?`): `number`
获取多少天的毫秒数 默认获取1天的
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `day` | `number` | `1` |
#### Returns
`number`
#### Defined in
[getDayMillisecond.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/getDayMillisecond.ts#L4)
___
### getDaysOfMonth
▸ **getDaysOfMonth**(`year`, `month`): `number`
获取一个月当中的天数
#### Parameters
| Name | Type |
| :------ | :------ |
| `year` | `number` |
| `month` | `number` |
#### Returns
`number`
#### Defined in
[getDaysOfMonth.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/getDaysOfMonth.ts#L4)
___
### getImageInfo
▸ **getImageInfo**(`src`, `attrs?`): `Promise`<`HTMLImageElement`\>
获取图片信息
#### Parameters
| Name | Type |
| :------ | :------ |
| `src` | `string` |
| `attrs` | `Record`<`string`, `any`\> |
#### Returns
`Promise`<`HTMLImageElement`\>
#### Defined in
[getImageInfo.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/getImageInfo.ts#L4)
___
### getLocal
▸ **getLocal**(): `Object`
#### Returns
`Object`
| Name | Type |
| :------ | :------ |
| `clear` | () => `void` |
| `generate` | <T\>(`key`: `string`) => { `getItem`: (`defaultVal?`: `Partial`<`T`\>) => `T` ; `removeItem`: () => `void` ; `setItem`: (`val`: `T`) => `T` ; `updateItem`: (`val`: `Partial`<`T`\>) => `T` } |
| `getItem` | <T\>(`key`: `string`, `defaultVal`: ``null`` \| `Partial`<`T`\>) => `T` |
| `removeItem` | (`key`: `string`) => `void` |
| `setItem` | <T\>(`key`: `string`, `val`: `T`) => `T` |
| `updateItem` | <T\>(`key`: `string`, `val`: `Partial`<`T`\>) => `T` |
#### Defined in
[storage/index.ts:10](https://github.com/daysnap/utils/blob/fb8fac4/src/storage/index.ts#L10)
___
### getMonthBounds
▸ **getMonthBounds**(`value`): [`Date`, `Date`]
获取月份的开始时间和结束时间
#### Parameters
| Name | Type |
| :------ | :------ |
| `value` | `string` \| `number` \| `Date` |
#### Returns
[`Date`, `Date`]
#### Defined in
[getMonthBounds.ts:7](https://github.com/daysnap/utils/blob/fb8fac4/src/getMonthBounds.ts#L7)
▸ **getMonthBounds**(`value`, `fmt`): [`string`, `string`]
#### Parameters
| Name | Type |
| :------ | :------ |
| `value` | `string` \| `number` \| `Date` |
| `fmt` | `string` |
#### Returns
[`string`, `string`]
#### Defined in
[getMonthBounds.ts:8](https://github.com/daysnap/utils/blob/fb8fac4/src/getMonthBounds.ts#L8)
___
### getRandom
▸ **getRandom**(`length`, `alphabet?`): `string`
生成一个随机字符串
#### Parameters
| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `length` | `number` | `undefined` | 生成随机字符串的长度 |
| `alphabet` | `string` | `'1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'` | 字母表 |
#### Returns
`string`
#### Defined in
[getRandom.ts:7](https://github.com/daysnap/utils/blob/fb8fac4/src/getRandom.ts#L7)
___
### getRandomColor
▸ **getRandomColor**(): `string`
随机颜色
#### Returns
`string`
#### Defined in
[getRandomColor.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/getRandomColor.ts#L4)
___
### getRandomNumber
▸ **getRandomNumber**(`length`): `string`
生成一个随机数字
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `length` | `number` | 生成一个随机数字的长度 |
#### Returns
`string`
#### Defined in
[getRandomNumber.ts:7](https://github.com/daysnap/utils/blob/fb8fac4/src/getRandomNumber.ts#L7)
___
### getRangeDate
▸ **getRangeDate**(`sv`, `ev`): `Date`[]
获取一个时间段的日期
#### Parameters
| Name | Type |
| :------ | :------ |
| `sv` | `string` \| `number` \| `Date` |
| `ev` | `string` \| `number` \| `Date` |
#### Returns
`Date`[]
#### Defined in
[getRangeDate.ts:7](https://github.com/daysnap/utils/blob/fb8fac4/src/getRangeDate.ts#L7)
▸ **getRangeDate**(`sv`, `ev`, `fmt`): `string`[]
#### Parameters
| Name | Type |
| :------ | :------ |
| `sv` | `string` \| `number` \| `Date` |
| `ev` | `string` \| `number` \| `Date` |
| `fmt` | `string` |
#### Returns
`string`[]
#### Defined in
[getRangeDate.ts:11](https://github.com/daysnap/utils/blob/fb8fac4/src/getRangeDate.ts#L11)
___
### getScrollTop
▸ **getScrollTop**(): `number`
获取 scrollTop
#### Returns
`number`
#### Defined in
[getScrollTop.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/getScrollTop.ts#L4)
___
### getVideoInfo
▸ **getVideoInfo**(`src`): `Promise`<`HTMLVideoElement`\>
获取 video 信息
#### Parameters
| Name | Type |
| :------ | :------ |
| `src` | `string` |
#### Returns
`Promise`<`HTMLVideoElement`\>
#### Defined in
[getVideoInfo.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/getVideoInfo.ts#L4)
___
### getWeekBounds
▸ **getWeekBounds**(`value`, `sundayIsFirstDay`): [`Date`, `Date`]
获取一周的开始时间和结束时间
#### Parameters
| Name | Type |
| :------ | :------ |
| `value` | `string` \| `number` \| `Date` |
| `sundayIsFirstDay` | `boolean` |
#### Returns
[`Date`, `Date`]
#### Defined in
[getWeekBounds.ts:7](https://github.com/daysnap/utils/blob/fb8fac4/src/getWeekBounds.ts#L7)
▸ **getWeekBounds**(`value`, `sundayIsFirstDay`, `fmt`): [`string`, `string`]
#### Parameters
| Name | Type |
| :------ | :------ |
| `value` | `string` \| `number` \| `Date` |
| `sundayIsFirstDay` | `boolean` |
| `fmt` | `string` |
#### Returns
[`string`, `string`]
#### Defined in
[getWeekBounds.ts:11](https://github.com/daysnap/utils/blob/fb8fac4/src/getWeekBounds.ts#L11)
___
### getWeekday
▸ **getWeekday**(`value?`, `prefix?`): `string`
获取星期几
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `value` | `string` \| `number` \| `Date` | `undefined` |
| `prefix` | `string` | `'周'` |
#### Returns
`string`
#### Defined in
[getWeekday.ts:6](https://github.com/daysnap/utils/blob/fb8fac4/src/getWeekday.ts#L6)
___
### inBrowser
▸ **inBrowser**(): `boolean`
判断是否是浏览器环境
#### Returns
`boolean`
#### Defined in
[inBrowser.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/inBrowser.ts#L4)
___
### insertLink
▸ **insertLink**(`href`): `Promise`<`HTMLLinkElement`\>
插入 link
#### Parameters
| Name | Type |
| :------ | :------ |
| `href` | `string` |
#### Returns
`Promise`<`HTMLLinkElement`\>
#### Defined in
[insertLink.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/insertLink.ts#L4)
▸ **insertLink**(`href`, `callback`): `void`
#### Parameters
| Name | Type |
| :------ | :------ |
| `href` | `string` |
| `callback` | (`err`: `unknown`, `el`: `HTMLLinkElement`) => `void` |
#### Returns
`void`
#### Defined in
[insertLink.ts:5](https://github.com/daysnap/utils/blob/fb8fac4/src/insertLink.ts#L5)
___
### insertScript
▸ **insertScript**(`src`): `Promise`<`HTMLScriptElement`\>
插入外部 script 标签
#### Parameters
| Name | Type |
| :------ | :------ |
| `src` | `string` |
#### Returns
`Promise`<`HTMLScriptElement`\>
#### Defined in
[insertScript.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/insertScript.ts#L4)
▸ **insertScript**(`src`, `callback`): `void`
#### Parameters
| Name | Type |
| :------ | :------ |
| `src` | `string` |
| `callback` | (`err`: `unknown`, `el`: `HTMLScriptElement`) => `void` |
#### Returns
`void`
#### Defined in
[insertScript.ts:5](https://github.com/daysnap/utils/blob/fb8fac4/src/insertScript.ts#L5)
___
### insertStyle
▸ **insertStyle**(`content`): `HTMLStyleElement`
插入样式
#### Parameters
| Name | Type |
| :------ | :------ |
| `content` | `string` |
#### Returns
`HTMLStyleElement`
#### Defined in
[insertStyle.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/insertStyle.ts#L4)
___
### isAmount
▸ **isAmount**(`val`): `boolean`
判断是否是合法金额
只能是数字,小数点后只能保留两位或一位
isAmount(0) => true
isAmount('01') => false
isAmount('1.') => true
isAmount('1.1') => true
isAmount('1.12') => true
isAmount('1.123') => false
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `string` |
#### Returns
`boolean`
#### Defined in
[isAmount.ts:11](https://github.com/daysnap/utils/blob/fb8fac4/src/isAmount.ts#L11)
___
### isAndroid
▸ **isAndroid**(): `boolean`
校验是否是安卓
#### Returns
`boolean`
#### Defined in
[isAndroid.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/isAndroid.ts#L4)
___
### isArray
▸ **isArray**(`val`): val is any[]
判断是否是数组
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `val` | `unknown` | 待判断值 |
#### Returns
val is any[]
是否
#### Defined in
[isArray.ts:6](https://github.com/daysnap/utils/blob/fb8fac4/src/isArray.ts#L6)
___
### isBoolean
▸ **isBoolean**(`val`): val is boolean
判断是否是布尔值
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `val` | `unknown` | 需要判断的值 |
#### Returns
val is boolean
#### Defined in
[isBoolean.ts:5](https://github.com/daysnap/utils/blob/fb8fac4/src/isBoolean.ts#L5)
___
### isChinese
▸ **isChinese**(`val`): `boolean`
判断是否是中文
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `string` |
#### Returns
`boolean`
#### Defined in
[isChinese.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/isChinese.ts#L4)
___
### isDate
▸ **isDate**(`val`): val is Date
判断是否日期 Date
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `unknown` |
#### Returns
val is Date
#### Defined in
[isDate.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/isDate.ts#L4)
___
### isEmail
▸ **isEmail**(`val`): `boolean`
校验是否是邮箱
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `string` |
#### Returns
`boolean`
#### Defined in
[isEmail.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/isEmail.ts#L4)
___
### isEmpty
▸ **isEmpty**(`val`): `boolean`
校验是否为空 ''、undefined、null
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `unknown` |
#### Returns
`boolean`
#### Defined in
[isEmpty.ts:6](https://github.com/daysnap/utils/blob/fb8fac4/src/isEmpty.ts#L6)
___
### isEmptyArray
▸ **isEmptyArray**(`val`): `boolean`
判断是否是空数组
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `unknown` |
#### Returns
`boolean`
#### Defined in
[isEmptyArray.ts:6](https://github.com/daysnap/utils/blob/fb8fac4/src/isEmptyArray.ts#L6)
___
### isEmptyObject
▸ **isEmptyObject**(`val`): `boolean`
判断是否是空对象
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `val` | `object` | 对象 |
#### Returns
`boolean`
#### Defined in
[isEmptyObject.ts:5](https://github.com/daysnap/utils/blob/fb8fac4/src/isEmptyObject.ts#L5)
___
### isError
▸ **isError**(`val`): val is Error
校验是否是 error
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `unknown` |
#### Returns
val is Error
#### Defined in
[isError.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/isError.ts#L4)
___
### isFunction
▸ **isFunction**(`val`): val is Function
校验是否是函数
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `unknown` |
#### Returns
val is Function
#### Defined in
[isFunction.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/isFunction.ts#L4)
___
### isIE
▸ **isIE**(): ``false`` \| `number`
判断浏览器是否是 ie
如果是 ie 则会返回对应 ie 版本
如果不是则返回false
#### Returns
``false`` \| `number`
#### Defined in
[isIE.ts:6](https://github.com/daysnap/utils/blob/fb8fac4/src/isIE.ts#L6)
___
### isIOS
▸ **isIOS**(): `boolean`
校验是否是ios
#### Returns
`boolean`
#### Defined in
[isIOS.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/isIOS.ts#L4)
___
### isIdCard
▸ **isIdCard**(`val`): `boolean`
校验是否是身份证
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `string` |
#### Returns
`boolean`
#### Defined in
[isIdCard.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/isIdCard.ts#L4)
___
### isJSONString
▸ **isJSONString**(`v`): `boolean`
是否是JSON 字符串
#### Parameters
| Name | Type |
| :------ | :------ |
| `v` | `string` |
#### Returns
`boolean`
#### Defined in
[isJSONString.ts:7](https://github.com/daysnap/utils/blob/fb8fac4/src/isJSONString.ts#L7)
___
### isLan
▸ **isLan**(`ip`): `boolean`
判断 ip 是否是局域网 ip,仅支持 ipv4
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `ip` | `string` | ipv4 地址 |
#### Returns
`boolean`
#### Defined in
[isLan.ts:5](https://github.com/daysnap/utils/blob/fb8fac4/src/isLan.ts#L5)
___
### isLeapYear
▸ **isLeapYear**(`year`): `boolean`
判断是否是闰年
规则:四年一闰,百年不闰,四百年再闰
#### Parameters
| Name | Type |
| :------ | :------ |
| `year` | `number` |
#### Returns
`boolean`
#### Defined in
[isLeapYear.ts:5](https://github.com/daysnap/utils/blob/fb8fac4/src/isLeapYear.ts#L5)
___
### isLicenseCode
▸ **isLicenseCode**(`v`): `boolean`
校验是否是车牌号
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `v` | `string` | 车牌号 |
#### Returns
`boolean`
#### Defined in
[isLicenseCode.ts:5](https://github.com/daysnap/utils/blob/fb8fac4/src/isLicenseCode.ts#L5)
___
### isMobile
▸ **isMobile**(): `boolean`
校验设备是否是手机
#### Returns
`boolean`
#### Defined in
[isMobile.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/isMobile.ts#L4)
___
### isNativeFunction
▸ **isNativeFunction**(`val`): `boolean`
判断是不是内置函数
内置函数toString后的主体代码块为 [native code]
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `unknown` |
#### Returns
`boolean`
#### Defined in
[isNativeFunction.ts:7](https://github.com/daysnap/utils/blob/fb8fac4/src/isNativeFunction.ts#L7)
___
### isNull
▸ **isNull**(`val`): val is null
校验是否是 null
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `unknown` |
#### Returns
val is null
#### Defined in
[isNull.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/isNull.ts#L4)
___
### isNumber
▸ **isNumber**(`val`): val is number
判断是否是数字
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `val` | `unknown` | 需要判断的值 |
#### Returns
val is number
#### Defined in
[isNumber.ts:5](https://github.com/daysnap/utils/blob/fb8fac4/src/isNumber.ts#L5)
___
### isObject
▸ **isObject**(`val`): val is Record<string, any\>
校验是否是对象
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `unknown` |
#### Returns
val is Record<string, any\>
#### Defined in
[isObject.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/isObject.ts#L4)
___
### isPhone
▸ **isPhone**(`val`): `boolean`
校验是否是手机号码
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `string` |
#### Returns
`boolean`
#### Defined in
[isPhone.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/isPhone.ts#L4)
___
### isPromise
▸ **isPromise**<`T`\>(`val`): val is Promise<T\>
校验是否是 promise
#### Type parameters
| Name | Type |
| :------ | :------ |
| `T` | `any` |
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `unknown` |
#### Returns
val is Promise<T\>
#### Defined in
[isPromise.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/isPromise.ts#L4)
___
### isRegExp
▸ **isRegExp**(`val`): val is RegExp
校验是否是正则表达式
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `unknown` |
#### Returns
val is RegExp
#### Defined in
[isRegExp.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/isRegExp.ts#L4)
___
### isString
▸ **isString**(`val`): val is string
校验是否是字符串
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `unknown` |
#### Returns
val is string
#### Defined in
[isString.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/isString.ts#L4)
___
### isType
▸ **isType**<`T`\>(`val`, `checker`): val is T
联合类型判断成其中某种类型
#### Type parameters
| Name | Type |
| :------ | :------ |
| `T` | `any` |
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `unknown` |
| `checker` | (`v`: `any`) => `boolean` |
#### Returns
val is T
#### Defined in
[isType.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/isType.ts#L4)
___
### isUndefined
▸ **isUndefined**(`val`): val is undefined
校验是否是 undefined
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `unknown` |
#### Returns
val is undefined
#### Defined in
[isUndefined.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/isUndefined.ts#L4)
___
### isUrl
▸ **isUrl**(`val`): `boolean`
判断是否是链接
#### Parameters
| Name | Type |
| :------ | :------ |
| `val` | `string` |
#### Returns
`boolean`
#### Defined in
isUrl.ts:4
___
### isValidDate
▸ **isValidDate**(`v`): `boolean`
验证是否有效日期
#### Parameters
| Name | Type |
| :------ | :------ |
| `v` | `string` \| `number` \| `Date` |
#### Returns
`boolean`
#### Defined in
[isValidDate.ts:6](https://github.com/daysnap/utils/blob/fb8fac4/src/isValidDate.ts#L6)
___
### isWeChat
▸ **isWeChat**(): `boolean`
判断是否是微信浏览器
#### Returns
`boolean`
#### Defined in
[isWeChat.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/isWeChat.ts#L4)
___
### isWeChatMiniProgram
▸ **isWeChatMiniProgram**(): `boolean`
判断是否是微信小程序web-view环境
https://developers.weixin.qq.com/miniprogram/dev/component/web-view.html
#### Returns
`boolean`
#### Defined in
[isWeChatMiniProgram.ts:5](https://github.com/daysnap/utils/blob/fb8fac4/src/isWeChatMiniProgram.ts#L5)
___
### isWeixin
▸ **isWeixin**(): `boolean`
判断是否是微信浏览器
**`Deprecated`**
请使用
**`See`**
[isWeChat](modules.md#iswechat).
#### Returns
`boolean`
#### Defined in
[isWeChat.ts:12](https://github.com/daysnap/utils/blob/fb8fac4/src/isWeChat.ts#L12)
___
### isWindow
▸ **isWindow**(`val`): val is Window
判断是否是 window 对象
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `val` | `unknown` | 需要判断的值 |
#### Returns
val is Window
#### Defined in
[isWindow.ts:5](https://github.com/daysnap/utils/blob/fb8fac4/src/isWindow.ts#L5)
___
### kebabCase
▸ **kebabCase**(`key`): `string`
说明
kebabCase('helloWorld') => hello-world
#### Parameters
| Name | Type |
| :------ | :------ |
| `key` | `string` |
#### Returns
`string`
#### Defined in
[kebabCase.ts:5](https://github.com/daysnap/utils/blob/fb8fac4/src/kebabCase.ts#L5)
___
### lfToBr
▸ **lfToBr**(`v`): `string`
\n to <br/>
#### Parameters
| Name | Type |
| :------ | :------ |
| `v` | `string` |
#### Returns
`string`
#### Defined in
[lfToBr.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/lfToBr.ts#L4)
___
### listGenerator
▸ **listGenerator**(`length`): `number`[]
list 生成器,快速生成数据
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `length` | `number` | 个数 |
#### Returns
`number`[]
#### Defined in
[listGenerator.ts:5](https://github.com/daysnap/utils/blob/fb8fac4/src/listGenerator.ts#L5)
▸ **listGenerator**<`T`\>(`length`, `fn`): `T`[]
#### Type parameters
| Name | Type |
| :------ | :------ |
| `T` | `any` |
#### Parameters
| Name | Type |
| :------ | :------ |
| `length` | `number` |
| `fn` | (`index`: `number`) => `T` |
#### Returns
`T`[]
#### Defined in
[listGenerator.ts:6](https://github.com/daysnap/utils/blob/fb8fac4/src/listGenerator.ts#L6)
___
### makePhoneCall
▸ **makePhoneCall**(`phoneNumber`): `void`
#### Parameters
| Name | Type |
| :------ | :------ |
| `phoneNumber` | `string` \| `number` |
#### Returns
`void`
#### Defined in
[makePhoneCall.ts:1](https://github.com/daysnap/utils/blob/fb8fac4/src/makePhoneCall.ts#L1)
___
### mousewheel
▸ **mousewheel**(`scrolling`, `options?`): `Object`
#### Parameters
| Name | Type |
| :------ | :------ |
| `scrolling` | `MousewheelScrolling` |
| `options?` | `MousewheelOptions` |
#### Returns
`Object`
| Name | Type |
| :------ | :------ |
| `listener` | (`e`: `any`) => `undefined` \| ``false`` |
#### Defined in
[mousewheel.ts:22](https://github.com/daysnap/utils/blob/fb8fac4/src/mousewheel.ts#L22)
___
### nf
▸ **nf**(): `void`
空函数
#### Returns
`void`
#### Defined in
[nf.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/nf.ts#L4)
___
### normalizeDate
▸ **normalizeDate**(`value`): `Date`
格式化日期
fix iOS 日期时间格式如果类似是 2020-12-12 12:12:12 就会报错的问题
2020/12/12 12:12:12 这种就是通用的
#### Parameters
| Name | Type |
| :------ | :------ |
| `value` | `string` \| `number` \| `Date` |
#### Returns
`Date`
#### Defined in
[normalizeDate.ts:8](https://github.com/daysnap/utils/blob/fb8fac4/src/normalizeDate.ts#L8)
___
### normalizePath
▸ **normalizePath**(`path`): `string`
格式化处理路径 平台兼容
#### Parameters
| Name | Type |
| :------ | :------ |
| `path` | `string` |
#### Returns
`string`
#### Defined in
[normalizePath.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/normalizePath.ts#L4)
___
### omit
▸ **omit**<`T`, `K`\>(`obj`, `fields?`): `Omit`<`T`, `K`\>
排除对象里的某些属性,返回剩下的对象,浅拷贝
#### Type parameters
| Name | Type |
| :------ | :------ |
| `T` | extends `object` |
| `K` | extends `string` \| `number` \| `symbol` |
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `obj` | `T` | `undefined` |
| `fields` | `K`[] | `[]` |
#### Returns
`Omit`<`T`, `K`\>
#### Defined in
[omit.ts:4](https://github.com/daysnap/utils/blob/fb8fac4/src/omit.ts#L4)
___
### padding
▸ **padding**(`message`, `before?`, `after?`): `string`
增添空格
#### Parameters
| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `message` | `string` | `undefined` | 文字信息 |
| `before` | `number` | `1` | 前空格个数 |
| `after` | `number` | `1` | 后空格个数 |
#### Returns
`string`
#### Defined in
[padding.ts:7](https://github.com/daysnap/utils/blob/fb8fac4/src/padding.ts#L7)
___
### parseDate
▸ **parseDate**(`v`): `Date`
解析成Date
**`Deprecated`**
请使用 normalizeDate() 方法
#### Parameters
| Name | Type |
| :------ | :-----