1.0.6 • Published 3 years ago

yz-tools v1.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

安装方法

npm i -D yz-tools

使用方法

import { } from 'yz-tools'

1、16进制颜色转rgb格式 colorToRgb(str)

功能描述

将16进制颜色转换成grb格式。

参数说明

入参是否必填
String
说明

非字符串传入会不作处理直接返回

使用方法

// index.js

...
import { colorToRgb } from 'tools-hy'
colorToRgb('#fff') // rgb(255,255,255)
...

2、数组排序去重 arrSortRepeat(arr, ?key)

功能描述

对数组进行去重排续,支持「对象数组」和「简单数组」

参数说明

入参类型是否必填默认值
arrArray-
keyStringid
说明
  1. 支持简单数组去重排序
  2. 强校验arr数据类型
  3. 强校验key值类型,以及key值是否存在

使用方法

// index.js

...
import { arrSortRepeat } from 'tools-hy'
<!--简单数组-->
const arr1 = [2,2,3,4,1]
arrSortRepeat(arr1) // [1,2,3,4]

<!--对象数组-->
const arr2 = [{a:2,name:'222'},{a:1,name:'111'},{a:3,name:'333'},{a:2,name:'222'}]
arrSortRepeat(arr1) // 抛错提示key不存在
arrSortRepeat(arr1, 'a') // 正确返回结果
...

3、时间格式化 -- timeFormat(target, ?format)

功能描述

时间戳格式化 + 格式化时间转时间戳

参数说明

入参类型是否必填默认值
targetString 或 时间戳-
formatString见说明

说明

  1. 当传入值target是时间格式时,默认值为13。

例如:

timeFormat('2020-12-12') // 13位毫秒级的时间戳 1607702400000

format 可选值为 10。

例如:

timeFormat('2020-12-12', 10) //输出10位秒级时间戳(1607702400)

注意:只要format输入值不为10,都将输出13位毫秒级时间戳。

  1. 当传入值target是时间戳时,默认值为 'YYYY-MM-DD HH:mm:ss'。

例如:

timeFormat(1599580800000)   // "2020-09-09 00:00:00"
timeFormat(1599580800000, 'YYYY/MM/DD HH:mm:ss')  // "2020/09/09 00:00:00"
timeFormat(1599580800000, 'YYYY/MM/DD')   // "2020/09/09"
timeFormat(1599580800000, 'HH:mm:ss')   // "00:00:00"
timeFormat(1599580800000, 'YYYY年MM月DD日 HH时mm分ss秒')   // "2020年09月09日 00时00分00秒"

注意:此处的时间戳可以输入10位。

  1. 参数不符合要求会有抛错处理。

使用方法

// index.js
...

import {} from 'yz-tools'
timeFormat('2020-12-12') // 1607702400000
timeFormat(1599580800000) // 2020-09-09 00:00:00

...
1.0.6

3 years ago

1.0.5

3 years ago

1.0.2

3 years ago