1.4.9 • Published 1 year ago
leaf-lib v1.4.9
leaf-lib
一个轻量级的 javascript 库。
安装
# npm
npm install leaf-lib
# yarn
yarn add leaf-lib
快速上手
在你的 html 文件中通过 script 标签引入项目根目录下的 leaf.min.js 文件,这时全局会暴露一个 leaf 对象。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="./leaf.min.js"></script>
</head>
<body>
<script>
console.log(leaf)
</script>
</body>
</html>
使用
// esModule
import * as leaf from "leaf-lib"
// commonJs
const leaf = require("leaf-lib")
// 你也可以采用解构赋值的方式进行引入,例如:
import { debounce } from "leaf-lib"
or
const { debounce } = require("leaf-lib")
方法列表
calcDaysByMonth(year: number, month: number): number
calcRangeDate(startDate: {year: number, month: number, date: number}, endDate: {year: number, month: number, date: number}): Array<{year: number, month: number, date: number}>
classes(...args: Array<Object | string>): string
cleanData(data: Object, dataFormat: Array): Object
copyText(text: string): Promise
debounce(fn: Function, delay: number): Function
deepClone(value: any): any
findMaxValue(arr: number[]): number
findMinValue(arr: number[]): number
getNowTime(type: "datetime" | "date" | "month" | "year"): Object
getTimeInfo(timestamp: number | string): Object
getVariableType(value: any): string
imageCompress(file: Object, config: Object): string | Object
initPromiseFunc(fn: Function): Function
isEmptyObject(value: Object): boolean
isObject(value: any): boolean
kebab2Pascal(text: string): string
memoryCalc(size: number, unit: string, targetUnit: string): string
memoryFormat(size: number, unit: string): string
queryParse(value: string): Object
queryStringify(value: Object): string
random(...args: number[]): number
styleStrToObject(styleStr: string): Object
throttle(fn: Function, delay: number): Function
uid(): string
使用 eventBus
import { eventBus } from "leaf-lib"
// 监听事件
eventBus.on("test", (data) => {
console.log(`这是一次${data}`)
})
// 触发事件
eventBus.emit("test", "测试")
// 取消单个事件的监听
eventBus.off("test")
// 取消所有事件的监听
eventBus.clear()
移动端适配(rem)
import { remAdapter } from "leaf-lib"
// 接收一个number类型参数(divide)
// 不传默认为100,即代表1rem等于1/100屏幕宽度
remAdapter()
1.4.6
1 year ago
1.4.5
1 year ago
1.4.4
1 year ago
1.4.3
1 year ago
1.4.2
1 year ago
1.4.9
1 year ago
1.4.8
1 year ago
1.2.0
2 years ago
1.4.1
1 year ago
1.2.3
1 year ago
1.4.0
1 year ago
1.3.1
1 year ago
1.2.2
2 years ago
1.3.0
1 year ago
1.2.1
2 years ago
1.1.16
2 years ago
1.1.15
2 years ago
1.1.14
2 years ago
1.1.17
2 years ago
1.1.13
2 years ago
1.1.12
2 years ago
1.1.11
2 years ago
1.1.10
2 years ago
1.1.9
2 years ago
1.1.8
2 years ago
1.1.7
2 years ago
1.1.6
2 years ago
1.1.5
2 years ago
1.1.4
2 years ago
1.1.3
2 years ago
1.1.2
2 years ago
1.1.1
2 years ago
1.1.0
2 years ago
1.0.17
2 years ago
1.0.16
2 years ago
1.0.15
2 years ago
1.0.14
2 years ago
1.0.13
2 years ago
1.0.12
2 years ago
1.0.11
2 years ago
1.0.10
2 years ago
1.0.9
2 years ago
1.0.8
2 years ago
1.0.7
2 years ago
1.0.6
2 years ago
1.0.5
2 years ago
1.0.4
2 years ago
1.0.3
2 years ago
1.0.2
2 years ago
1.0.1
2 years ago
1.0.0
2 years ago