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

igroot-util

v0.0.6

Published

前端常用工具函数

Downloads

4

Readme

igroot-util:前端常用工具函数集

getTreeDatas

何时使用

前后端交互时,前端获取到扁平化的数据,需要转化为igroot中的tree-table组件需要的树形结构数据时。

API

通过给 getTreeDatas 函数传入 扁平化数据数组 来使用

数组中每个对象的属性说明如下:

| 属性 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | id | 数据的唯一性标识 | Int | - | | pid | 数据的父节点的id | Int | - | | is_leaf | 该节点是否为叶子节点 | boolean | - |

示例

const datas = [
    {
        "id": "1131",
        "name": "a",
        "pid": "0",
        "is_leaf": false
    },
    {
        "id": "1132",
        "name": "b",
        "pid": "1131",
        "is_leaf": true
    },
    {
        "id": "1133",
        "name": "c",
        "pid": "1131",
        "is_leaf": true
    },
    {
        "id": "1135",
        "name": "ces",
        "pid": "0",
        "is_leaf": true
    }
]
getTreeDatas(datas)

结果得到

[
    { 
        id: '1131',
        name: 'a',
        pid: '0',
        is_leaf: false,
        children:
        [ 
            { 
                id: '1132', 
                name: 'b', 
                pid: '1131', 
                is_leaf: true 
            },{ 
                id: '1133', 
                name: 'c', 
                pid: '1131', 
                is_leaf: true 
            } 
        ]
    },
    { 
        id: '1135', 
        name: 'ces', 
        pid: '0', 
        is_leaf: true 
    }
]

parseUrlParams

何时使用

需要提取URL参数时。

API

通过给 parseUrlParams 函数传入 扁平化数据数组 来使用

函数参数的属性说明如下:

| 属性 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | url | 请求路径 | string | - |

示例

 const url = 'http://test-roster.i.trpcdn.net/staff-center?appId=21&callback=http://localhost:2017'

 parseUrlParams(url)

结果得到

 { appId: '21', callback: 'http://localhost:2017' }

isEmpty

何时使用

需要判断数据是否为空时。

API

通过给 isEmpty 函数传入 任何格式的数据 来使用

函数参数的属性说明如下:

| 属性 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | data | 需要判断是否为空的数据 | 不限 | - |

示例

const data1 = ''
isEmpty(data1)  //输入空字符串,返回true

const data2 = []
isEmpty(data2)  //输入空数组,返回true

const data3 = {}
isEmpty(data3)  //输入空对象,应该返回true

const data4 = { name: 'fyz' }
isEmpty(data4)  //输入非空对象,应该返回false

const data5 = ['fyz', 'fyh']
isEmpty(data5)  //输入非空数组,应该返回false

const data6 = 'fyz'
isEmpty(data6)  //输入非空字符串,应该返回false