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

jbc

v1.1.1

Published

javascript base core

Downloads

23

Readme

README

说明

大家好,欢迎使用jbc,使用过程中如有任何问题都可以直接反馈到我的邮箱

jbc

javascript base core 基础方法库

安装

# install
npm install jbc
或者
npm i jbc
  • 安装后在main.js中添加引用,jbc库在window下开放了jbc入口
import jbc from 'jbc'
或
import 'jbc'
  • 安装完毕,举个栗子获取uuid
console.log(jbc.uuid());

新增或调整

  • 完善dateFormat 方法 更名dateFormatAny

全局变量和方法

//基础类1
uuid(len)    //自定义位数唯一标识符 len 长度
error(str)  //抛出一个包含指定字符串信息的异常。
isFunction(obj)  //判断指定参数是否是一个函数。
isArray(arr)    //判断指定参数是否是一个数组。
isWindow(obj)   //判断指定参数是否是一个窗口。
isNum(num)  //判断指定参数是否是一个数字值。
isEmptyObject(obj)  //判断指定参数是否是一个空对象。
isNull(val)     //判断指定值是否为空。bool、function类型直接返回
strLength(str)  //返回字符串字节长度 汉字两个字节
isPlainObject(obj)  //判断指定参数是否是一个纯粹的对象。
type(obj)   //确定JavaScript内置对象的类型,并返回小写形式的类型名称。
globalEval(data)    //全局性地执行一段JavaScript代码。
nodeName(elem,name) //用于检查DOM元素的节点名称(即属性nodeName)与指定的值是否相等,检查时忽略大小写。
each(obj, callback, args)   //遍历指定的对象和数组
trim(txt)   //去字符串左右空格
fomatFloat(num, pos)    //格式化浮点类型数字 num 原数据 pos 保留几位小数
isIP(str)   //判断是否为IP地址 是返回true
extend(a,b) //拓展方法  1.一个参数时将对象的内容合并到目标对象 2.如果两个参数都是对象就合并对象,并覆盖第一个对象
now()   //返回当前时间距1970年1月1日午夜所经过的毫秒数。



//浏览器
browser                 // 浏览器成员变量
  userAgent             // 浏览器版本信息
  language              // 页面语言
  versions              // 浏览器版本成员变量
    maxthon()           // 遨游
    opera()             // opera
    firefox()           // 火狐浏览器
    chrome()            // Chrome浏览器
    safari()            // Safari浏览器
    ie()                // IE浏览器
    mobile()            // 是否为移动终端
    ios()               // ios终端
    android()           // android终端或者uc浏览器
    iPhone()            // 是否为iPhone或者QQHD浏览器
    iPad()              // 是否iPad
    webApp()            // 是否web应该程序,没有头部与底部
    weixin()            // 是否微信
    qq()                // 是否QQ
    wp()                // 是否windowsphone
  IE
    ie7()
    ie8()
    ie9()               // 判断是否为相应版本IE  返回bool类型
    ie10()
    ie11()              
  isPC()                // 判断pc机(补充方法)
  isH5browser()         // 是否为支持H5的浏览器
  IEVersion()           // 判断IE浏览器版本,返回7-11或100
//判断是否为安卓手机
$.browser.versions.android()

//字符串检查
checkStr(txt)           // 检查成员变量
  isNum                 // 是否字符串为整数
  isPhone               // 是否为手机号码
  isMail                // 是否为邮件
  isTel                 // 是否为电话号码
  isUserName            // 是否为字母开头并且不包含字符(一般账号)
  isPassWord            // 是否为数字、字母和字符混排
  isCN                  // 是否为中文
  isIDCard              // 是否为身份证
  isUrl                 // 是否为Url正式地址
  isImg                 // 是否为图片地址
  isImgBase64           // 是否为base64图片地址
//检查是否为手机号,返回bool类型
$.checkStr(txt).isPhone 

isInStr(substr, str)    //是否存在字符串中
checkLimitChars(str, array) //检查是否存在限制字符,用*和谐 str 要检查的字符 array 敏感数组
reStrNum(str)   //返回字符串中所有数字
reIntNum(num)   //返回整数,直接去除小数
reStrLetter(str) //返回字符串中的所有字母
reStrStart(str, start)  //判断是否以某个字符串开头  
reStrEnd(str, end)  //判断是否以某个字符串结尾
reSelectedStr(str, start, end)  //返回字符串str中特定start到end字符之间的所有内容 如果有多段则返回数组
strEllipsis(str, len, ismin)    //超出的字符串用省略号代替 ismin是否启用字节计算长度,默认false


//基础类2
request(paras)  //获取页面参数
debugLog    //快捷日志开关,默认为true,false时所有$.log()将不再工作
log(str)    //快捷日志方法,等价于console.log(str)
random(start, end)  //返回预定范围随机数 不包括开始和结束值
randomStr(str)  //随机字符串排列顺序
reMobileNum(num,size)   //换算移动端屏幕比数据 num要换算的尺寸,size设计稿尺寸,默认640
getTimeStamp()  //返回时间戳变种,异于now,可用作类似uuid唯一标识符使用,带有时间性质
//判断当前对象是否存在,存在直接返回,不存在返回null ,object当前对象,key键值,beObject不存在返回的对象
canUse(object, key, beObject)
dateFormatAny(date, fmt)   //格式化时间 date后台毫秒值时间,fmt 时间格式参数 默认值yyyy-MM-dd
strToDate(str)  //字符串时间转成Date标准时间
callback(fn, data)  //公共回调 fn回调函数 data回调数据
cookie(key,value)   //cookie写入、获取
cookie.remove(value)    //cookie删除


//数组方法
inArray(elem, arr, i)   //在数组中搜索指定的值,并返回其索引值。不存在返回-1
merge(first, second)    //合并两个数组,修改第一个参数的内容
grep(elems, callback, invert)   //使用指定的函数过滤数组中的元素,并返回过滤后的数组。
removalArray(arr)  //数组去重
aomArray(addArr, defArr, minArr)    //数组defArr操作,增删默认数组    minArr(boolean类型true去重)
randomArr(arr)     //随机数组排列顺序
randomArrBySize(arr, start, end)    //截取一定尺寸不参与随机
randomArrByLen(arr, len)    //随机抽取数组中一定长度的不重复数值,返回一个数组,不设置长度返回数组中一个随机值
makeArray(arr, results)     //将一个类数组对象转换为真正的数组对象。


//优化类
throttle(fn, delay, immediate) //节流  fn函数,delay间隔时间 默认300ms,immediate是否立即执行 默认true
debounce(fn, delay, immediate) //防抖  fn函数,delay间隔时间 默认16.6ms,immediate是否立即执行 默认true

//加载类
//resource 图片资源数组
//float 进度返回保留几位小数
//loadstart 加载开始
//progress 加载进度回调
//complete 加载完成回调
//errorimg 错误图片回调
loading(options)    //图片资源加载方法
$.loading({
    resource:["img1","img2"],
    progress: function (e) {
        console.log("进度:" + e);
    }
});


//模块加载
isInclude(url)  //是否引入了某个JS或CSS,url js或css地址
//id 外部js的id  //默认t3js
//url 地址
//callback 加载完毕回调
loadJs(options) //加载外部js
//加载外部css
//id 外部css的id  //默认t3css
//url 地址
//callback 加载完毕回调
loadCss(options)
$.loadJs({
    url:"",
    callback:function(){
        console.log("加载完成");
    }
});

回到顶部