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

leaf-lib

v1.4.9

Published

a small in size javascript library

Downloads

18

Readme

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()