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

usetools

v1.1.2

Published

this is a commonly used tool set.

Downloads

4

Readme

这只是一个简单的nodejs 工具包

主要目的是便于不用重复的定义函数,直接调用

installtion

npm install --save usetools

使用示例

const tools = require('usetools');

### md5 示例
let sercet = tools.md5("hello world");


### base64_encode 示例
let base64str = tools.base64_encode("hello world");

### 像PHP中的函数一样的使用它
is_array()、empty()、mt_rand()等等 具体详情请查看api

API说明

.base64_encode(str,debug = false)

base64_encode base64加密字符串或对象,函数有两个参数,第一个参数是要加密的字符串,第二个参数是调试信息,如果出错可以传入true查看出错信息

.base64_decode(str,debug = false)

同base64_encode一样的用法

.mt_rand(min,max)

获取随机数(最小值,最大值)

.explode(separator,str)

字符串分割成数组 separator(分割符) str(待分割的字符串)

.implode(separator,arr)

数组拼接成字符串 separator(分割符) arr(待拼接的数组)

.is_array(arr)

是否为数组

.is_object(obj)

是否为对象

.is_string(str)

是否为字符串

.in_array(arr,val)

是否在数组里 val可以是字符串 、数字 、对象等

.is_phone(phone)

是否为正确的手机号码

.is_email(email)

是否为正确的邮箱

.is_idcard(idcard)

是否身份证号

.rand_str(len = 4,type = '')

生成随机字符串 (len 默认为4 type="number" 数字 ,type="letter" 小写字母 空为混合)

.empty(mixed)

是否为空 空返回真 否则返回假 (可以是字符串、对象、数组等)

.md5(str)

m5加密

.isset(val)

判断变量是否存在 可以是对象属性、全局变量、局部变量

.json_decode(strJson)

字符串转JSON对象

.json_encode(obj)

JSON对象转字符串

.date(format,time)

格式化时间戳函数 像PHP一样的date函数

.time(timer = false)

同php时间用法一样 返回也是秒级单位(如果传入真 毫秒级时间戳)

.get = function(url = '',timeout = 3000,encoding, header,buffer = false)

@description 以GET的方式发起远程请求( Promise 对象调用方式) @param {String} url 请求地址 @param {Number=} timeout 超时时间,单位为毫秒 @param {String} [encoding='utf-8'] 编码格式 @param {Object=} header 请求头对象 @param {Boolean=} [buffer=false] 是否返回二进制流buffer 数据返回 成功返回 (data,req,res) 失败返回(err)

.post = function(url, timeout = 3000, data = {}, encoding, header, reqEncoding, json,buffer = false)

@description 以POST的方式发起远程请求( Promise 对象调用方式) @param {String} url 请求地址 @param {Number=} timeout 超时时间,单位为毫秒 @param {Object=} data 请求发送的数据对象 @param {RequestCallback} callback 处理请求响应的回调方法,查看 {@link RequestCallback} @param {String} [encoding='utf-8'] 编码格式 @param {Object=} header 请求头对象 @param {String=} reqEncoding 请求数据的编码格式,如果是gbk,使用escape编码 @param {Boolean=} [json=false] 发送的是否json数据 @param {Boolean=} [buffer=false] 是否返回二进制流buffer 数据返回 成功返回 (data,req,res) 失败返回(err)

.strtotime()

同php时间用法一样 日期时间型转时间戳

更新日志

2018-05-25 修复implode() 函数的bug 2018-06-02 修复post() 函数的bug 2018-06-25 修复time() 函数的参数的绝对相等 2018-06-28 修复empty() 布尔值的检测 2018-07-12 修复in_array()的调试信息 2018-11-13 修复get() buffer流 2018-11-13 修复post() buffer流