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

js-jf-utils

v1.0.1

Published

JavaScript功能

Downloads

18

Readme

@TOC


前言

封装一些常用的JavaScript功能,提高开发效率。


下载

npm install js-jf-utils

yarn add js-jf-utils

如果网络不好且没有cnpm可以试试这个(强烈建议不要使用cnpm和下列方式)

npm install js-jf-utils --registry=https://registry.npmmirror.com

方法

| 序号 | 方法名 | 描述 | | -- | :-- | :-- | | 01 | jsMjJsonString | JSON字符串 | | 02 | jsMjShallClone | 浅克隆 | | 03 | jsMjIndexOf | 查询字符 | | 04 | jsMjType | 数据类型 | | 05 | jsMjIsType | 判断数据类型 | | 06 | jsMjNullObject | 空对象 | | 07 | jsMjNullArray | 空数组 | | 08 | jsMjPureArray | 纯数组 | | 09 | jsMjArrayObject | 数组对象 | | 10 | jsMjParentNode | 根据id获取该节点的所有父节点id | | 11 | jsMjToStringt | 转换成字符串 | | 12 | jsMjCreateText | 通过十进制数值生成文字 | | 13 | jsMjCreateRandom | 生成随机数 | | 14 | jsMjUnique | 生成随机唯一值 | | 15 | jsMjToTree | 扁平数组转树形 | | 16 | jsMjToFlat | 树形JSON转为扁平数组 | | 17 | jsMjRandReco | 数组随机重组 | | 18 | jsMjCheckMobiPhon | 实时校验手机号 | | 19 | jsMjCheckCurr | 实时校验货币 | | 20 | jsMjCheckNumbLett | 实时校验大写、小写、数字 | | 21 | jsMjCheckNumbLettLine | 实时校验大写、小写、数字和横线 | | 22 | jsMjCheckNozh | 实时校验非汉字输入 | | 23 | jsMjCheckNumber | 实时校验非数字输入 |


使用

CDN

<!-- 导入 -->
<script src="xxx/js-mj-utils/index.js"></script>

<script>
    let { jsMjToStringt } = jsMjUtils;

    // 解构使用
    console.log(jsMjToStringt(['status', 'type'], {
        name: 'MJ',
        age: 25,
        status: 1,
        type: 0
    }));
    // {name: 'MJ', age: 25, status: '1', type: '0'}

    // 直接使用
    let result = jsMjParentNode(
        [
            {
                id: 'a1',
                parentId: undefined,
                name: 'MJ1',
                age: 25,
                status: 0,
                type: 2,
                children: [
                    {
                        id: 'b2',
                        parentId: 'a1',
                        name: 'MJ2',
                        age: 18,
                        status: 1,
                        type: 0,
                        children: []
                    }
                ]
            },
            {
                id: 'c3',
                parentId: undefined,
                name: 'MJ3',
                age: 20,
                status: 2,
                type: 1,
                children: [
                    {
                        id: 'd4',
                        parentId: 'c3',
                        name: 'MJ4',
                        age: 25,
                        status: 1,
                        type: 0,
                        children: [
                            {
                                id: 'e5',
                                parentId: 'd4',
                                name: 'MJ5',
                                age: 23,
                                status: 3,
                                type: 1,
                                children: [
                                    {
                                        id: 'f6',
                                        parentId: 'e5',
                                        name: 'MJ6',
                                        age: 23,
                                        status: 3,
                                        type: 1,
                                        children: [
                                            {
                                                id: 'g7',
                                                parentId: 'f6',
                                                name: 'MJ7',
                                                age: 30,
                                                status: 3,
                                                type: 1,
                                                children: []
                                            }
                                        ]
                                    },
                                    {
                                        id: 'h8',
                                        parentId: 'e5',
                                        name: 'MJ8',
                                        age: 23,
                                        status: 3,
                                        type: 1
                                    }
                                ]
                            },
                            {
                                id: 'i9',
                                parentId: 'd4',
                                name: 'MJ9',
                                age: 25,
                                status: 3,
                                type: 1,
                                children: []
                            }
                        ]
                    }
                ]
            }
        ],
        (item) => item.id === 'i9'
    );
    console.log('result: ', result);
    // ['i9', 'd4', 'c3']
</script>

vue

在main.js中引入 import 'js-mj-utils' 使用方式与CDN一致(建议直接使用,不要解构)