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_toolbag

v1.1.1

Published

封装了一些前端开发中常用的工具函数。

Downloads

7

Readme

封装了一些前端开发中常用的工具函数。

install

npm i js_toolbag -S

use

import toolkit from 'js_toolbag'

API

  • toolkit.isArray(val)
    判断是否是数组

  • toolkit.isObject(val)
    判断是否是普通对象对象

  • toolkit.isCustomObject(val,desc)
    判断是否是特殊对象

// 判断p是否是Promise
toolkit.isCustomObject(p, 'Promise')  
  • toolkit.isNode()
    判断运行环境是否是nodejs

  • toolkit.getMobile()
    判断手机类型,返回'Ios','Android'或'unkonwn'

  • toolkit.formatDate(time, pattern)
    格式化时间,time可以是一个Date对象、时间戳或者一个合理的代表时间的字符串。pattern是想要格式化成的模型,可以是yyyy-MM-dd HH:mm:ssyyyy-MM-dd或者HH:mm:ss 等。

const time = toolkit.formatDate(1578309905716, 'yyyy-MM-dd HH:mm:ss'); 
// 2020-01-19 19:25:05
  • toolkit.getStrLength(str)
    获取字符串长度,非英文字符算两个

  • toolkit.forEach(obj, fn)
    遍历对象或数组

const arr = [1,2,3,4,1,2];
const obj = {name: 'zyh', age: 29}

toolkit.forEach(arr, (val, index) => {
  console.log(val)
})
toolkit.forEach(obj, (val, key)=>{
  console.log(key + ': ' + val)
})
  • toolkit.deduplicateArray(array)
    数组去重

  • toolkit.parseUrlQuery(key)
    获取url上的某个查询参数

  • deepClone(obj)
    深拷贝一个对象

  • flattenArray(arr)
    扁平化一个数组

let a = toolkit.flattenArray([1, [2, [3, 4]], 5, [7], 8, [[[9]]]]);
//a -> [ 1, 2, 3, 4, 5, 7, 8, 9 ]
  • isApp()
    是否在点评app环境

  • isIphoneX()
    是否是iphoneX系列