# 打造自己的前端业务代码库

这是我很久以前写的文章,如果有什么不对的地方请指出,原文:https://ruizer.github.io/2019/04/30/front-end-util-code/

此项目仅供学习~

业务开发过程中,会经常用到数组对象分组千分符百分号深拷贝等常用函数,为避免不同项目多次复制粘贴的麻烦,这里统一封装,并发布到npm,以提高开发效率。

项目地址:rui-utils (opens new window),欢迎star (opens new window)。有什么问题或者建议可以在issues (opens new window)提问

# 安装使用

  1. 直接下载lib目录下的rui-utils.min.js (opens new window)使用,支持UMD通用模块规范
  2. 使用npm安装

# 浏览器:

  <script src="rui-utils.min.js"></script>
  <script>
      var thousand = rutils.thousandBitSeparator(20190430);
      // 20,190,430
  </script>
1
2
3
4
5

# npm:

$ npm install rui-utils
1

webpack、RequireJS等

// 完整引入
const rutils = require('rui-utils')
const thousand = rutils.thousandBitSeparator(20190430)
1
2
3

# API文档

# array

# getUnion (opens new window)    得到两个数组的并集, 两个数组的元素为数值或字符串

# getIntersection (opens new window)    得到两个数组的交集, 两个数组的元素为数值或字符串

# canvas

# windowToCanvas (opens new window)    窗口坐标换为canvas坐标

# class

# addClass (opens new window)    为元素添加class

# hasClass (opens new window)    判断元素是否有某个class

# removeClass (opens new window)    为元素移除class

# getCookie (opens new window)    根据name读取cookie

# removeCookie (opens new window)    根据name删除cookie

# setCookie (opens new window)    设置Cookie

# countTicks

# countTicks (opens new window)    从数组中取n个数据,并且相对平均

# date

# getFormatDate (opens new window)    格式化日期,返回YYYY-MM-DD 格式的字符串日期

# getLatestDays (opens new window)    获取最近range天date数据

# deepClone

# deepClone (opens new window)    深度克隆

# deepClone

# getJsAsync (opens new window)    异步获取js库

# letter

# camelCaseToKebabCase (opens new window)    驼峰转横杠写法

# kebabCaseToCamelCase (opens new window)    横杠转驼峰写法

# firstUpperCase (opens new window)    首字母大写

# fisrtLowerCase (opens new window)    首字母小写

# number

# formatNumber (opens new window)    如果传入的数值小于10,即位数只有1位,则在前面补充0

# numberPrecent (opens new window)    数字转换成百分比

# numberScale (opens new window)    小数点移位置

# ranNumber (opens new window)    获取指定位数的随机数

# thousandBitSeparator (opens new window)    千分符分割

# object

# groupBy (opens new window)    数组对象分组,按照对象字段分组

# url

# parseQueryString (opens new window)    url参数转对象

# stringfyQueryString (opens new window)    对象序列化

本文完, 感谢阅读。