es.shim

2.2.2 • Public • Published

downloads version

es.shim

es.shim 提供了部分新API, 以及一些常用的扩展方法。具体如下:

├── Obejct
   └── .empty(any)    // 判断对象是否为空对象
   └── .groupBy(arr, fn)    // 数组分组, 返回分组后的对象
   └── .hasOwn(any, key)    // 安全版的 Object.prototype.hasOwnProperty()
├── Obejct.prototype
   └── .toParams()    // 把对象转为 key1=value1&key2=value2 格式

├── Map
   └── .groupBy(any)    // 数组分组, 返回分组后的对象

├── Array.prototype
   ├── .flat(depth)    // 数组降维
   ├── .flatMap(fn)    // 等价于 map(fn) -> flat(1)
   ├── .at(index)    // 读取指定位置的元素, 负值则从后往前读
   ├── .findLast(fn)    // 查找匹配的最后一项
   ├── .findLastIndex(fn)    // 查找匹配的最后一项的索引值
   ├── .toSorted(fn)    // 数组排序, 返回一个副本(不改变原数组)
   ├── .toReversed(fn)    // 反转数组, 同样返回一个副本
   ├── .toSpliced(fn)    // 数组截取, 同样返回副本
   ├── .with(index, newValue)    // 创建一个副本,再修改副本中的元素, 返回副本 
   ├── .group(fn)    // 数组分组
   └── .groupToMap(fn)    // 数组分组, 返回Map对象

├── Date
   └── .isDate(any)    // 判断对象是否为 日期对象
├── Date.prototype
   ├── .getWeek()    // 获取当前是本月第几周
   ├── .getFullWeek()    // 获取当前是本年度第几周
   └── .format(formatStr)    // 把日期按指定格式转换

├── String.prototype
   ├── .splice(index, len, pad)    // 类似数组的splice方法
   ├── .htmlspecialchars()    // 字符串HTML安全转义
   ├── .tohtml()    // htmlspecialchars的还原
   ├── .xss()    // 字符串安全转义
   ├── .escape()    // js特殊字符的转义
   ├── .at(index)    // 读取指定位置的字符, 负值则从后往前读
   ├── .toJson()    // 将url参数转为对象
   ├── .lt(version)    // 判断是否小于目标版本号
   ├── .lte(version)    // 判断是否小于或等于目标版本号
   ├── .gt(version)    // 判断是否大于目标版本号
   ├── .gte(version)    // 判断是否大于或等于目标版本号
   └── .eq(version)    // 判断是否等于目标版本号, 1.0和1.0.0这里会返回true, 而用 == 或 ===, 无法得到正确的结果

├── Number
   ├── .parse(str)    // 将安全范围内的数字字符串转为数字类型
   └── .fromString(str)    // 将字符串转为数字类型

└── Promise
    └── .defer()    // 创建一个延迟的Promise对象

Readme

Keywords

none

Package Sidebar

Install

npm i es.shim

Weekly Downloads

174

Version

2.2.2

License

MIT

Unpacked Size

11 kB

Total Files

4

Last publish

Collaborators

  • yutent