JSPM

  • Created
  • Published
  • Downloads 2110
  • Score
    100M100P100Q110494F
  • License MIT

Package Exports

  • ut2
  • ut2/es/index.js
  • ut2/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ut2) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ut2

一个现代 JavaScript 实用工具库。点击查看在线文档

npm Build and Deploy Docs codecov Static Badge npm GitHub

比较

与其他工具库对比(lodashunderscore

  • 基于 ES2015+ 标准,无需原生支持的方法(forEachfilterObject.keysObject.entries ……)。
  • 使用 TypeScript 实现,提供类型定义。
  • 导出 escjsumd 模块格式,支持不同开发环境使用。

兼容性

兼容现代浏览器 FirefoxChromeSafariOpera,以及 Node.js >= 10

如果要兼容 IE 系列浏览器,需要提供相应的 Polyfill 支持,建议使用 @babel/preset-env 设置对应的 targets

使用

esnode 开发环境

安装依赖

npm install ut2
yarn add ut2
pnpm add ut2

浏览器原生开发环境

如果你的项目使用的是原生方式开发,可以在浏览器中使用 script 标签直接引入文件,并使用全局变量 ut2

npm 包的 ut2/dist 目录下提供了 UMDut2.js 以及 ut2.min.js。你也可以通过 UNPKG 下载到本地进行使用。或者直接使用 UNPKG 线上版本 注意版本

示例

所有方法都在 ut2 模块中。

import { debounce } from 'ut2';

const debounced = debounce(() => {
  // do something
}, 300);

API

下列方法全部在 ut2 模块直接导出,分类只是为了可读性。你可以点击查看在线文档,了解更多信息。

import { throttle, chunk, max } from 'ut2'