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

cosy-data

v1.0.4

Published

常用数据处理方法集成

Downloads

8

Readme

项目说明

常用数据处理方法集成

引入

import cosyData from 'cosy-data'

判断类

isPhone 判断是否是手机

cosyData.isPhone('13142241111') //true

isJSON 判断是否是json格式

cosyData.isJSON('{"a":1}')  //true

isNum 判断是否是数字

cosyData.isNum('') // false
cosyData.isNum(' ') //false
cosyData.isNum(null) //false
cosyData.isNum(1)//true

getDataType 获取数据类型

cosyData.getDataType('12') //String
cosyData.getDataType(12) //Number
cosyData.getDataType([]) //Array
cosyData.getDataType({}) //Object
cosyData.getDataType(true) //Boolean
cosyData.getDataType(null) //Null
cosyData.getDataType(undefined)//Undefined
cosyData.getDataType(new Date()) //Date
cosyData.getDataType(/[hbc]at/gi) //RegExp

数据处理类

deepCopy 数据深拷贝

/**
 * 深拷贝
 * */
let oldObj={
    a:1,
    b:2,
    c:[1,2,3]
}
let newObj = cosyData.deepCopy(oldObj);

oldObj.c.push(4);

//oldObj  {a:1,b:2,c:[1,2,3,4]}
//newObj  {a:1,b:2.c:[1,2,3]}

extend 对象合并

 /**
   * 对象合并
   * @param {*} o 被增加对象
   * @param {*} n 增加对象
 */
let aObj = {
    a:"1",
    b:"2"
}
let bObj = {
    c:"3",
    d:"4"
}

cosyData.extend(aObj,bObj);

console.log(aObj); //  {a:"1",b:"2",c:"3",d:"4"}

drData 无限极数据降维

/**
     * 降维数据
     * @param {*} res       Array       需要降维的数据
     * @param {*} key       Sting       被降维键名 
*/
let obj = {
    children:[
        {
            name:"1",
            children:[
                {
                    name:"2"
                }
            ]
        },
        {
            name:"3"
        }
    ]
}

let allArray = cosyData.drData(obj,"children"); //[{name:"1",children:[{name:"2"}]},{name:"2"},{name:"3"}]

formatDate 时间戳格式化

 /**
     * 时间戳转日期
     * @param {*} date        时间戳
     * @param {*} allType     返回数据类型     
     *                                   0:年-月-日           
     *                                   1:时:分              
     *                                   2:年-月-日 时:分:秒
     *                                   3: 时:分:秒
     *                                   4: {h,M,s,y,m,d}
     *                                   5: {hour,minute,second,nano}
     */
cosyData.formatDate(new Date(),0) //2020-11-11

getDayText 获取周字符串

/**
 *String 【0:周日-6周六】
 * */
cosyData.getDayText(0) //"周日"

unique 数组去重

cosyData.unique([0,0,1,1,2,3,4]) //[0,1,2,3,4]

getOutData 对象数据批量处理

/**
     * 提取提交数据
     * @param {*} res               Obj       需要筛选的原始数据对象
     * @param {*} resList           Array     ['xxx']提交字段list/
     *                                                 String:对应键值
     *                                                 Array[对应字段,生成字段]
     *                                                  Object {  
     *                                                    key:对应字段,
     *                                                    outKey:生成字段,
     *                                                    event:处理方法
     *                                                   }
     */
let startObj = {
    a:1
}
//深拷贝================
cosyData.getOutData(startObj.['a']) // {a:1} 

//快速字符处理==========
cosyData.getOutData(startObj.[
    ['a','outA']
]) 
// {outA:1}

//含处理逻辑============
cosyData.getOutData(startObj,[
    key:'a',
    outKey:'outA',
    event:res=>{
        return res + 1 
    }
]);
// {outA:2}

randomNum 生成随机数

/**
   * 生成随机数
   * @param {*} minNum 最小数
   * @param {*} maxNum 最大数
   */
  cosyData.randomNum(0,10); // 0-10之间随机数

randomNumFor 生成随机数数组

/**
   * 生成  范围内  一定数量随机数
   * @param {*} minNum 
   * @param {*} maxNum 
   * @param {*} numLength 
   */
  cosyData.randomNumFor(0,10,3) //[3,1,7]

getDataToObj 获取当前路由get传参

cosyData.getDataToObj();
//假设当前页面地址 http://www.xxx.com?a=10&&b=adg
//{a:"10",b:"adg"}