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-tooljs

v0.0.7

Published

Web前端开发,常用JavaScript工具库

Downloads

10

Readme

JavaScript 常用工具库

MIT License

Web 前端开发,常用 JavaScript 工具库,整合在 Web 项目开发过程中,经常使用的工具集合。

下载安装:

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

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

使用方法:

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

    <!-- ES6模块导入使用 -->
    <script type="module">
      /**
       * 1、引入使用
       **/
      import * as mu from "mu-tooljs";
    
      // 在浏览器控制台中打印mu-tooljs的所有方法
      console.log(mu);
    
      // 打印实例
      mu.print();
    
      /**
       * 2、按需引入
       **/
      import { print, cookie, download } from "mu-tooljs";
    
      // 打印实例
      print();
    </script>
  • 通过 script 标签以 CDN 的形式引入使用

    <!-- 将mu-tooljs下载后,在html文件中引入本地脚本 -->
    <script src="./js/mu-tooljs"></script>
    <script>
      // 在浏览器控制台中打印mu-tooljs的所有方法
      console.log(mu);
    
      // 打印实例
      mu.print();
    </script>

支持情况:

  • print() 页面打印

    在网页中指定某个元素、区域,从打印机中打印输出!

    /**
     * @param {String} id // 打印的区域元素的ID值
     * @returns {Undefined}
     */
    
    mu.print("box1"); // box1 是网页中指定要打印元素的id
    
    mu.print(); // 如果参数为空:则打印网页中的整个body元素的内容!
  • cookie 缓存管理

    主要对 document.cookie 进行了封装,提供了对 cookie 的 获取 get(),删除 del(),设置 set() 这 3 个方法。

    /**
     * @description 获取cookie!
     * @param {String} name
     * @returns String | " "
     */
    mu.cookie.get(name);
    
    /**
     * @description 删除cookie!
     * @param {String} name
     * @returns mu.cookie
     */
    mu.cookie.del(name);
    
    /**
     * @description 设置cookie!
     * @param {String} name
     * @param {String} valse
     * @param {toGMTString/toUTCString} time
     * @param {String} path
     * @param {String} domain
     * @returns mu.cookie
     */
    mu.cookie.set(name, valse);

    mu.cookie.set(name, value, time = 0, path = '', domain = ''),参数说明如下【注:如果浏览器屏蔽了 cookie 功能,将导致设置失败!】:

    | 属性名 | 属性值类型 | 属性值说明 | 是否必传 | | ------ | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | -------- | | name | String | 需设置 cookie 的名称 | 是 | | value | String | 需设置 cookie 的值 | 是 | | time | toGMTString/toUTCString | 过期时间,单位为 "天"【1 天 = new Date(+new Date() + (1 _ 24 + 8) _ 60 _ 60 _ 1000).toUTCString()】,默认为 0。传负数可删除此 cookie | 否 | | path | String | 设置路径,默认为当前网页路径 | 否 | | domain | String | 设置域,默认为当前网页所在域" / " | 否 |

  • download() 文件下载

    根据文件地址下载(如:图片、音频、视频、文档、压缩包等文件)!

    /**
     * @param {String} url // 下载文件地址
     * @param {String} name // 下载文件名称
     * @param {String} target?: _blank
     * @returns {Boolean}
     */
    
    let url = "http://www.xxx.com/xxx.mp3"; // 注:该文件地址为非跨域地址!
    let name = "下载文件名称";
    mu.download(url, name);
  • downloadByData() 文件流下载

    根据文件流下载!

    /**
     * @param {BlobPart} data 文件流
     * @param {String} name 设置下载文件名
     * @param {String} mime?:
     * @param {BlobPart} bom?:
     * @returns {Undefined}
     */
    
    let data = "文件流";
    let name = "下载文件名称";
    mu.downloadByData(data, name);
  • imgURLToBase64() 图片 转 Base64

    根据图片(imgURL)地址,将图片 转为 Base64 编码!

    /**
     * @name imgURLToBase64
     * @descriptio 图片(imgURL) 转 Base64
     * @param {String} imgURL
     * @param {String} mineType?:
     * @returns {Promise} Base64
     */
    
    let let imgURL = "http://www.xxx.com/xxx.jpg"; // 注:该文件地址为非跨域地址!
    mu.imgURLToBase64(imgURL);
  • base64ToBlob() Base64 转 Blob 对象

    根据 Base64 编码 转 Blob 对象 !

    /**
     * @name base64ToBlob
     * @descriptio Base64编码 转 Blob对象
     * @param {Base64} base64Buf
     * @returns {Blob}
     */
    
    let let baseCode = "Base64";
    mu.base64ToBlob(baseCode);
  • blobToBase64() Blob 对象 转 Base64

    根据 Blob 对象 转 Base64 编码!

    /**
     * @name blobToBase64
     * @descriptio Blob对象 转 Base64
     * @param {Blob} blob
     * @param {Function} callBack
     * @returns {Undefined}
     */
    
    let let blob = "Blob对象";
    mu.blobToBase64(blob, function(base64){
      console.log(base64);
    });
  • Updating 。。。!