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

mu-utiljs

v0.0.2

Published

Web前端 JavaScript 常用函数库

Downloads

7

Readme

JavaScript 常用函数库

MIT License

JavaScript 常用函数库,整合在 Web 项目中经常使用的函数和方法。

下载安装:

# 使用npm命令下载安装
$ npm i mu-utiljs

# 使用yarn命令下载安装
yarn add mu-utiljs

使用方法:

  • 通过 JS Module(模块)方式导入使用

    <!-- ES6模块导入使用 -->
    <script type="module">
      /**
       * 1、全部引入使用
       **/
      import * as mu from "mu-utiljs";
    
      // 在浏览器控制台中打印mu-utiljs的所有方法
      console.log(mu);
    
      // 深拷贝使用实例
      let obj = { key: "value" };
      const newObj = mu.deepCopy(obj);
    
      /**
       * 2、按需引入使用
       **/
      import { deepCopy, debounce, throttle } from "mu-utiljs";
    
      // 深拷贝使用实例
      let obj = { key: "value" };
      const newObj = deepCopy(obj);
    </script>
  • 通过 script 标签以 CDN 的形式引入使用

    <!-- 将mu-utiljs下载后,在html文件中引入本地脚本 -->
    <script src="./js/mu-utiljs"></script>
    <script>
      // 在浏览器控制台中打印mu-utiljs的所有方法
      console.log(mu);
    
      // 深拷贝使用实例
      let obj = { key: "value" };
      const newObj = mu.deepCopy(obj);
    </script>

支持情况:

  • deepCopy() 深拷贝

    对各种数据类型、对象的进行深度拷贝!

    /**
     * @param {Object|Array} par // 拷贝的对象
     * @returns Array or Object
     */
    
    let par = {} || [];
    mu.deepCopy(par); // 返回一个新的对象
  • debounce() 函数防抖

    函数被频繁调用时使用(触发事件后在 n 秒内函数只能执行一次,如果在 n 秒内又触发了事件,则会重新计算函数执行时间)!

    /**
     * @param {function} fn // 要进行防抖操作的函数
     * @param {number} delay = 300 // 间隔时间(默认300毫秒)
     * @returns function
     */
    
    mu.debounce(fn, delay);
  • throttle() 函数节流

    连续触发事件但是在 n 秒中只执行一次函数!

    /**
     * @param {function} fn // 要进行节流操作的函数
     * @param {number} delay = 300 // 间隔时间(默认300毫秒)
     * @returns function
     */
    
    mu.throttle(fn, delay);
  • getFileExt() 获取文件后缀名

    获取文件的后缀名!

    /**
     * @param {string} fileName // 要获取带后缀的文件名
     * @returns string
     */
    
    mu.getFileExt(fileName: string) => string;
  • getFileSize() 获取文件大小

    主要用于上传文件时(计算文件 单位大小)!

    /**
     * @param {string} fileSize // 要进行计算的文件大小
     * @returns string
     */
    
    mu.getFileSize(fileName: string) => string;
  • query() 获取url参数

    主要用于获取url参数 如 ?id=666&uid=888!

    /**
     * @param {string} key // 要进行计算的文件大小
     * @returns string
     */
    
    mu.query(key: string) => string;
  • Updating 。。。!