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

okutil

v1.4.7

Published

- 此 ui 库为公共组件库 - 发布在公司http://10.60.0.115源 - npm install okutil - 兼容到Chrome 49

Readme

教师空间 okUtil 公共库

  • 此 ui 库为公共组件库
  • 发布在公司http://10.60.0.115源
  • npm install okutil
  • 兼容到Chrome 49

array

  • import {array} from 'okUtil'
 /**
 * 数组根据数组项为object时的object中的key排序
 * @param {*必参} array 原数组
 * @param {*必参} key 符合条件object中的key
 * @param {*选参} ascend ascend参数代表升序,不传或传其他的自动升序
 */
sortByKey: function(array, key, ascend) {}
/**
 * 数组根据数组项为object时的object中的key为给定value的返回值
 * @param {*必参} array 原数组
 * @param {*必参} key 数组object项的key
 * @param {*必参} value 数组中object项的value
 * return 符合条件的{}
 */
findByPair: function(array, key, value) {}

cookie

  • import {cookie} from 'okUtil'
/**
 * 验证字符串是否合法的cookie键名
 *
 * @param {string} source 需要遍历的数组
 * @meta standard
 * @return {boolean} 是否合法的cookie键名
 */
 _isValidKey: function(key) {}

 /**
 * 获取cookie的值(未解码)
 * @param {string} key cookie的键名
 * @return {string|null} cookie值,获取不到时返回null
 */
getRaw: function(key) {}

/**
 * 获取cookie的值,用decodeURIComponent进行解码
 * @param {string} key cookie的键名
 * @return {string|null} cookie值,获取不到时返回null
 */
get: function(key) {}

/**
 * 设置cookie的值(未解码)
 * @param {string} key cookie的键名
 * @param {string} value cookie的值
 * @param {Object} [options] cookie的其他可选参数
 */
setRaw: function(key, value, options) {}

 /**
 * 设置cookie的值,用encodeURIComponent进行编码
 * @param {string} key cookie的键名
 * @param {string} value cookie的值
 * @param {Object} [options] cookie的其他可选参数
 * @config {Date|number} [expires] cookie过期时间,如果类型是数字的话, 单位是毫秒
 * @config {string} [domain] cookie域名
 * @config {string} [secure] cookie是否安全传输
 */
set: function(key, value, options) {}

// 删除cookie
del: function(key) {}

date

  • import {date} from 'okUtil'

 /*
  * 日期转化为自定义格式
  * @param {Date} date
  * @param {string} fmt
  * @return {String}
  */
format: function(date, format) {}
/*
  * 毫秒转化为时、分、秒
  * @param {Number} msd
  * @param {String} lang
  * @return {String}
  */
msToStr: function(msd) {}

number

  • import {number} from 'okUtil'
/**
     * 转为千分位
     * @param {*} val 必选
     * @param {*} param  可选分隔符
     * @returns 
     */
toCurrency: function(val, param) {}

/*
* 格式化文件大小
* @param {Number} bytes	字节数
* @param {Number} dot		省略至几位数
* @return {String}
*/
formatFileSize: function(bytes, dot) {}

 /*
* 修复Number.prototypetoFixed() 方法的精度问题
*  Number.prototype.toFixed.call(2.55, 1); // 2.5 错误
*  toFixed(2.55, 1); // 2.6  正确
*/
toFixed: function(number, n) {}

func

  • import {func} from 'okUtil'
/**
 * object (Object): 要检索的对象。
 * path (Array|string): 要获取属性的路径。
 * [defaultValue] (*): 如果解析值是 undefined ,这值会被返回。
 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
 * _.get(object, 'a[0].b.c');
 * // => 3
 * _.get(object, ['a', '0', 'b', 'c']);
 * // => 3
 * _.get(object, 'a.b.c', 'default');
 * // => 'default'
*/
get:function(object, path, [defaultValue])

// okUtil.type() 函数用于确定JavaScript内置对象的类型,并返回小写形式的类型名称。
// 如果对象是undefined或null,则返回相应的"undefined"或"null"
type: function(param) {}

isEmptyObject: function(obj) {}

isFunction: function(obj) {}

noop: function() {},
uuid: function() {}
/**
 * throttle 函数节流
 * @param fn
 * @param delay
 */
throttle: function(fn, delay) {}

/**
 * debounce 函数去抖
 * @param fn
 * @param delay
 * @param immediate 为true的时候立即执行一次,为false或不传的时候只有停止的时候才执行
 */
debounce: function(fn, delay,immediate) {}

deepCopy(obj) {}

storage

  • import {storage} from 'okUtil'
// 本地持久化存储

getItem: function(key) {}
removeItem: function(key) {}
setItem: function(key, value, expirationDay) {}
clearExpiration: function(key) {}
clear: function() {}

string

  • import {string} from 'okUtil'
/**
 * 获取目标字符串在gbk编码下的字节长度
 * @name baidu.string.getByteLength
 * @function
 * @grammar baidu.string.getByteLength(source)
 * @param {string} source 目标字符串
 * @remark
 * 获取字符在gbk编码下的字节长度, 实现原理是认为大于127的就一定是双字节。如果字符超出gbk编码范围, 则这个计算不准确
 * @meta standard
 * @see baidu.string.subByte
 *
 * @returns {number} 字节长度
 */
getByteLength: function(source) {}
/**
 * 对目标字符串按gbk编码截取字节长度
 * @name baidu.string.subByte
 * @function
 * @grammar baidu.string.subByte(source, length)
 * @param {string} source 目标字符串
 * @param {number} length 需要截取的字节长度
 * @param {string} [tail] 追加字符串,可选.
 * @remark
 * 截取过程中,遇到半个汉字时,向下取整。
 * @see baidu.string.getByteLength
 *
 * @returns {string} 字符串截取结果
 */
subByte: function(source, length, tail) {}
escape: function(str) {}

url

  • import {Url} from 'okUtil'
var url = new Url("q=URLUtils.searchParams&topic=api")
url.has(params)
url.get(params)
url.getAll(params)
url.append(key, value)
url.toString()
url.set(key, value)
url.delete(params)

NPM 化

按需加载设置

  • 借助 babel-plugin-import,我们可以只引入需要的组件,以达到减小项目体积的目的。
  • 首先,安装 babel-plugin-import:
  • $ npm install babel-plugin-import -D
  • 或者
  • $ yarn add babel-plugin-import -D
  • 然后,将 babel.config.js 修改为:
module.exports = {
  plugins: [
    [
      "import",
      {
        libraryName: 'okutil',
        libraryDirectory: "es"
      },
    ],
  ],
};