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

max-js-utils

v1.0.8

Published

max-js-utils 是一个包含常用工具函数的 JavaScript 库,提供了浅克隆、深克隆、随机数生成等功能。

Downloads

523

Readme

mUtils

mUtils 是一个包含常用工具函数的 JavaScript 库。它提供了浅拷贝、深拷贝、随机字符串、随机数等功能,旨在帮助开发者高效实现常见操作。支持 Vue 2 和 Vue 3 的插件安装。

安装

你可以通过 npm 或 yarn 安装 mUtils

npm install max-js-utils
yarn add max-js-utils

Usage(使用)

1.Vue 插件安装

Vue 3

在 Vue 3 项目中,你可以像这样使用 mUtils 插件:

import { createApp } from 'vue';
import App from './App.vue';
import mUtilsPlugin from 'mUtils';

const app = createApp(App);

// 使用插件
app.use(mUtilsPlugin);

app.mount('#app');

Vue 2

在 Vue 2 项目中,使用方法类似:

import Vue from 'vue';
import App from './App.vue';
import mUtilsPlugin from 'mUtils';

Vue.use(mUtilsPlugin);

new Vue({
  render: h => h(App),
}).$mount('#app');

2. 使用工具函数

在 Vue 组件中,你可以通过 this.$mUtils 来访问所有工具函数:

// 在 Vue 组件中调用工具函数
export default {
  mounted() {
    // 生成随机字符串
    console.log(this.$mUtils.randomString(10));
    
    // 获取指定范围内的随机数
    console.log(this.$mUtils.randomRange(5, 15));
    
    // 获取数组中的随机元素
    console.log(this.$mUtils.randomNum([1, 2, 3, 4, 5]));
  }
};

3. 单独导入工具函数

如果你只需要单独使用某个工具函数,而不是通过插件的形式,你可以直接导入特定的函数:

import { randomString, randomRange, randomNum } from 'mUtils';

// 使用随机字符串函数
console.log(randomString(10));

// 使用随机数函数
console.log(randomRange(5, 15));

// 使用数组随机元素函数
console.log(randomNum([1, 2, 3, 4, 5]));

4. 自定义挂载名称

import {allTools} from "mUtils";

const install = (app) => {
    // 判断是否为 Vue 3
    const isVue3 = !!app?.config?.globalProperties;

    // 在 Vue 3 中挂载工具函数
    if (isVue3) {
        app.config.globalProperties.$yourUtilsName = allTools;
    } else {
        // 在 Vue 2 中挂载工具函数
        app.prototype.$yourUtilsName = allTools;
    }
}

app.use({install})

Contact me(联系我)

mail: [email protected]

贡献

欢迎贡献代码!如果你有任何问题或建议,欢迎创建 issue 或 pull request。

许可证

MIT © Max