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 🙏

© 2025 – Pkg Stats / Ryan Hefner

easybase

v1.1.0

Published

A set of very useful JavaScript common function libraries

Downloads

7

Readme

easybase

A set of very useful JavaScript common function libraries

Quick Start

npm install easybase --save
import {isWeixin, isAli, isJson} from 'easybase';
// or
import {isWeixin, isAli, isJson} from 'easybase/dist/is';

API

  • 数组去重
/**
 * @description 数组去重
 * @param arr
 * @returns {Array}
 */
unique(arr);
  • 数组扁平化
/**
  * @description 数组扁平化
  * @param arr
  * @returns {Array}
  */
flatArr(arr);
  • 设置cookie
/**
 * @description 设置cookie
 * @param name
 * @param value
 * @param expires
 * @param path
 */
setCookie(name, value, expires = 7, path= '/');
  • 获取指定的cookie
/**
 * @description 获取指定的cookie
 * @param name
 * @returns {*}
 */
getCookie(name);
  • 获取所有的cookie
/**
 * @description 获取所有的cookie
 * @returns {Object}
 */
getAllCookies();
  • 清除cookie
/**
 * @description 清楚某个cookie
 * @param name
 */
clearCookie(name);
  • 清除所有的cookie
/**
 * @ description 清除所有的cookie
 */
clearAllCookie();
  • 格式化日期
/**
 * @description 格式化日期
 * @param {Date} date
 * @param {String} format  {yyyy-MM-dd  yyyy/MM/dd}
 * @returns {String}
 */
formatDate(date, format);
  • 获取距离某天的某一天日期
/**
 *
 * @description 获取距离某天的某一天日期
 * @param {Date} date
 * @param {number} AddDayCount 整数往后负数往前
 * @returns {string}
 */
getDateStr(date,AddDayCount);
  • 获取距离endTime还有多少时间
/**
 * 获取距离endTime还有多少时间
 * @param EndTime
 */
getRTime(EndTime);
  • 获取浏览器的名称和版本
/**
 * @description 获取浏览器的名称和版本
 * @returns {string}
 */
getBrowser();
  • 获取设备类型
/**
 * @description 获取设备类型
 * @returns {String}
 */
detectOS();
// 如果是苹果电脑 返回 'Mac';如果是苹果手机,返回 'iPhone';
  • 获取屏幕宽高
/**
 * @description 获取屏幕宽高
 * @returns {string}
 */
getWH();
  • 获取设备所有信息
/**
 * @description 获取设备所有信息
 * @returns {Object}
 */
device();
  • 判断是否是微信
/**
 * @description 判断是否是微信
 * @returns {boolean}
 */
isWeixin();
  • 判断是否是支付宝
/**
 * @description 判断是否是支付宝
 * @returns {boolean}
 */
isAli();
  • 判断是否是安卓用户
/**
 * @description 判断是否是安卓用户
 * @returns {boolean}
 */
isAndroid();
  • 判断是否是IOS用户
/**
 * @description 判断是否是IOS用户
 * @returns {boolean}
 */
isIOS();
  • 判断是否是json对象
/**
 * @description 判断是否是json对象
 * @param obj
 * @returns {boolean}
 */
isJson(obj);
  • 判断是否是空对象
/**
 *  @description 判断是否是空对象;
 * @param obj
 * @returns {boolean}
 */
isEmptyObject(obj);
  • 判断是否是空字符串
/**
 * @description 判断是否是空字符串
 * @param str
 * @returns {boolean}
 */
isNull(str);
  • 判断是否为email
/**
 * @description 判断是否为email
 * @param str
 * @returns {boolean}
 */
isEmail(str);
  • 判断是否为手机号
/**
 *
 * @description 判断是否为手机号
 * @param  {String|Number} str
 * @return {Boolean}
 */
isPhone(str);
  • 判断是否为身份证号
/**
 *
 * @description  判断是否为身份证号
 * @param  {String|Number} str
 * @return {Boolean}
 */
isIdCard(str);
  • 判断是否为URL地址
/**
 *
 * @description 判断是否为URL地址
 * @param  {String} str
 * @return {Boolean}
 */
isUrl(str);
  • 判断浏览器是否支持webP格式图片
/**
 *
 * @description 判断浏览器是否支持webP格式图片
 * @return {Boolean}
 */
isSupportWebP();
  • 判断是否NaN
/**
 *
 * @desc   判断是否NaN
 * @param {Any} value
 * @return {Boolean}
 */
isNaN(value);
  • 判断是否函数
/**
 * @description 判断是否函数
 * @param fn
 * @returns {boolean}
 */
isFunction(fn);
  • 判断是否是数组
/**
 * @description 判断是否是数组
 * @param arr
 * @returns {boolean}
 */
isArray(arr);
  • 判断是否为中文
  /**
 * @description 判断是否为中文
 * @param str
 * @returns {boolean}
 */
  isCN(str);
  • 加法
/**
 * @description 加法
 * @param arg1
 * @param arg2
 * @returns {number}
 */
add(arg1, arg2);
  • 减法
/**
 * @description 减法
 * @param arg1
 * @param arg2
 * @returns {number}
 */
sub(arg1, arg2)
  • 乘法
/**
 * @description 乘法
 * @param arg1
 * @param arg2
 * @returns {number}
 */
mul(arg1, arg2);
  • 除法
/**
 * @description 除法
 * @param arg1
 * @param arg2
 * @returns {*}
 */
div(arg1, arg2)
  • 合并对象
/**
 * @description 合并对象
 * @param target
 * @returns {object}
 */
extend(...target);
  • 深克隆
/**
 * @description 深克隆
 * @param {Any} values
 */
deepClone(values);
  • 将JSON字符串转换为JSON对象
/**
 * @description 将JSON字符串转换为JSON对象;注意:必须是标准JSON格式;
 * @param str
 * @returns {object }
 */
parse(str);
  • 获取queryString指定的参数
/**
 * @description 获取queryString指定的参数
 * @param name
 * @constructor
 */
GetQueryString(name);
  • 获取queryString字符串转换为JSON对象
/**
 * @description 获取queryString字符串转换为JSON对象
 * @param {String} search 可选参数 无时自动获取浏览器后面的queryString
 * @returns {Object||{}}
 */
searchToJson();
  • json对象转换为search条件
/**
 * @description json对象转换为search条件;注意:只能是一层
 * @param json
 * @returns {string}
 */
JsonToSearch();
  • 去除字符串中的空格
/**
 * @description 去除字符串中的空格
 * @param str
 * @param {Number} type {0:去掉所有空格;1:去掉首位的空格;2:去掉左边的空格;3:去掉右边的额空格}
 * @returns {String}
 */
trim(str, type)
  • 现金额转大写
/**
 * @description  现金额转大写
 * @param  {Number} n
 * @return {String}
 */
digitUppercase(n);
  • 获取数据类型
/**
 * @description 获取数据类型
 * @param {Any} values
 */
getType(values);
// getType(new Date) => 'date'
// getType([0,1,2]) => 'array'