npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

speedfix

v1.0.6

Published

一个简单js工具库

Downloads

8

Readme

speedfix

一个由ts构建的简单js函数库,目的是简化js数据操作。

Static Badge Static Badge

使用npm安装

npm install speedfix

引用

import speedfix from 'speedfix'

按需加载

import { isString } from 'speedfix/src/isString'

索引

数据判断

数组操作

对象操作

时间函数

字符串操作

缓存操作

二进制文件操作

正则匹配

文档

数据判断

  • checkType判断类型
speedfix.checkType(value)
  • isString判断是否为字符串类型

speedfix.isString(value)
  • isNumber判断是否为数字类型

speedfix.isNumber(value)
  • isBoolean判断是否为布尔类型

speedfix.isBoolean(value)
  • isArray判断是否为数组类型

speedfix.isArray(value)
  • isFunction判断是否为函数类型

speedfix.isFunction(value)
  • isObject判断是否为对象类型

speedfix.isObject(value)
  • isUndefined判断是否为undefined

speedfix.isUndefined(value)
  • isNull判断是否为null

speedfix.isNull(value)
  • isEmptyValue判断是否为空值

speedfix.isEmptyValue(value)
  • isEmptyObject判断是否为空对象

speedfix.isEmptyObject(value)
  • isEmptyList判断是否为空数组

speedfix.isEmptyList(value)

数组操作

  • listInsert数组插入

// 普通插入
speedfix.listInsert([1, 2, 3], [4, 5])
// [1,2,3,4,5]

// 依据下标插入
speedfix.listInsert([1, 2, 3], {a: 1}, 1)
// [1,{a: 1},2,3]

// 筛选对象插入(默认向后)
speedfix.listInsert([{a: 1,b: 1},{a: 2,b: 2}], {a:3,b:3}, {a: 1})
// [{a:1,b:1},{a:3,b:3},{a:2,b:2}]

// 选择插入方向(向前)
speedfix.listInsert([{a: 1,b: 1},{a: 2,b: 2}], {a:3,b:3}, {a: 2}, 'ahead')
// [{a:1,b:1},{a:3,b:3},{a:2,b:2}]
  • listRemove数组删除

// 根据下标指定数量删除
speedfix.listRemove([1,2,3,4], 0, 2)
// [3,4]

// 指定数据删除
speedfix.listRemove([1,2,3,4], [2,4])
// [1,3]

// 根据属性指定删除
speedfix.listRemove([{a: 1,b:2},{a:1,b:1,c:3}], {b:1,c:3})
// [{a: 1, b: 2}]
  • sort数组排序(支持复杂对象排序)

// 普通排序(默认大到小)
speedfix.sort([2, 4, 3, 6, 5, 8, 7, 9, 0])
// [9, 8, 7, 6, 5, 4, 3, 2, 0]

// 普通排序(小到大)
speedfix.sort([2, 4, 3, 6, 5, 8, 7, 9, 0], 'order')
// [0, 2, 3, 4, 5, 6, 7, 8, 9]

// 对象数组排序(默认大到小)
speedfix.sort([{ a: 1 }, { a: 4 }, { a: 2 }, { a: 3 }], 'a')
// [{ a: 4 }, { a: 3 }, { a: 2 }, { a: 1 }]

// 对象数组排序(小到大)
speedfix.sort([{ a: 1 }, { a: 4 }, { a: 2 }, { a: 3 }], 'order', 'a')
// [{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }]
  • listDeduplicate数组去重

// 普通去重
speedfix.listDeduplicate([1,2,3,3,4,5,6,6,7,7,8,8,8])
// [1,2,3,4,5,6,7,8]

// 对象数组去重(默认保留向前)
speedfix.listDeduplicate([{a:1,b:2},{a:1,b:3},{a:2,b:2,c:3}], 'a')
// [{a:1,b:2},{a:2,b:2,c:3}]

// 对象数组去重(保留向后)
speedfix.listDeduplicate([{a:1,b:2},{a:1,b:3},{a:2,b:2,c:3}], 'a', 'behind')
// [{a:1,b:3},{a:2,b:2,c:3}]
  • listGroup根据传入的对象数组和key进行分组

var arr = [
  {id: 1, year: 2018},
  {id: 2, year: 2017},
  {id: 3, year: 2016},
  {id: 4, year: 2017},
  {id: 5, year: 2018},
  {id: 6, year: 2017}
]
speedfix.listGroup({target: arr, key: 'year'})
// {
//   "2016": [
//     {"id": 3, "year": 2016}
//   ],
//   "2017": [
//     {"id": 2, "year": 2017},
//     {"id": 4, "year": 2017},
//     {"id": 6, "year": 2017}
//   ],
//   "2018": [
//     {"id": 1, "year": 2018},
//     {"id": 5, "year": 2018}
//   ]
// }
  • toArray伪数组转数组

speedfix.toArray(target)

对象操作

  • objectMerge合并对象并返回一个合并后的对象

// 合并(向后覆盖)
speedfix.objectMerge([{ a: 1 }, { a: 2, b: 2 }, { a: 3, c: 3 }])
// { a: 3, b: 2, c: 3 }

// 合并(向前覆盖)
speedfix.objectMerge([{ a: 1 }, { a: 2, b: 2 }, { a: 3, c: 3 }], 'ahead')
// { a: 1, b: 2, c: 3 }
  • objectCopy数组或对象的拷贝

// 浅拷贝
speedfix.objectCopy({ a: 1, b: 2, c: { aa: 11, bb: 22 } })

// 深拷贝
speedfix.objectCopy({ a: 1, b: 2, c: { aa: 11, bb: 22 } }, 'deep')
  • objectToQuery对象转query

speedfix.objectToQuery({ a: 1, b: 2, c: 3 })
// 'a=1&b=2&c=3'

// 自定义连接符
speedfix.objectToQuery({ a: 1, b: 2, c: 3 }, '@')
// 'a=1@b=2@c=3'

时间函数

  • toDate时间格式化函数

// yyyy: 年
// M: 月(不补0)
// MM: 月(补0)
// D: 天(不补0)
// DD: 天(补0)
// h: 12小时制小时(不补0)
// hh: 12小时制小时(补0)
// H: 24小时制小时(不补0)
// HH: 24小时制小时(补0)
// m: 分钟(不补0)
// mm: 分钟(补0)
// s: 秒(不补0)
// ss: 秒(补0)

// 默认格式
speedfix.toDate('2018-3-3')
// 2018-03-03 00:00:00

// 格式自定义
speedfix.toDate(1234567890, 'YY//MM!!DD hh::mm""ss')
// 1970//01!!15 14::56""07

字符串操作

  • toThousands千分位格式化

speedfix.toThousands('123123123')
// 123,123,123

speedfix.toThousands('123123123.123123')
// 123,123,123.123123
  • queryToObjectquery转对象

speedfix.queryToObject('a=1&b=2&c=3')
// { a: "1", b: "2", c: "3" }

// 自定义连接符
speedfix.queryToObject('a=1#b=2#c=3', '#')
// { a: "1", b: "2", c: "3" }

缓存操作

  • setCookie设置cookie

speedfix.setCookie('token', '1357924680', {'max-age': 40000})
  • getCookie获取cookie

speedfix.getCookie(key)
  • setStorage设置storage

speedfix.setStorage('id',[1,2,3], {
  expire: 10000,
  mode: 'session'
})
  • getStorage获取storage

speedfix.setStorage(key)

二进制文件操作

  • downloadBlob下载二进制流文件

speedfix.downloadBlob(data, MIME, fileName)

正则匹配

  • isEmail表单验证邮箱

speedfix.isEmail(val)
  • isPhoneNum表单验证手机号

speedfix.isPhoneNum(val)
  • isChinese表单验证汉字

speedfix.isChinese(str)