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 🙏

© 2026 – Pkg Stats / Ryan Hefner

richang.js

v4.5.5

Published

richang js code.

Downloads

112

Readme

Richang.js

npm GitHub package version npm npm Coverage Status Build Status license

//      ___                       ___           ___           ___           ___           ___
//     /\  \                     /\__\         /\  \         /\  \         /\  \         /\__\
//    /::\  \       ___         /:/  /         \:\  \       /::\  \        \:\  \       /:/ _/_
//   /:/\:\__\     /\__\       /:/  /           \:\  \     /:/\:\  \        \:\  \     /:/ /\  \
//  /:/ /:/  /    /:/__/      /:/  /  ___   ___ /::\  \   /:/ /::\  \   _____\:\  \   /:/ /::\  \
// /:/_/:/__/___ /::\  \     /:/__/  /\__\ /\  /:/\:\__\ /:/_/:/\:\__\ /::::::::\__\ /:/__\/\:\__\
// \:\/:::::/  / \/\:\  \__  \:\  \ /:/  / \:\/:/  \/__/ \:\/:/  \/__/ \:\~~\~~\/__/ \:\  \ /:/  /
//  \::/~~/~~~~   ~~\:\/\__\  \:\  /:/  /   \::/__/       \::/__/       \:\  \        \:\  /:/  /
//   \:\~~\          \::/  /   \:\/:/  /     \:\  \        \:\  \        \:\  \        \:\/:/  /
//    \:\__\         /:/  /     \::/  /       \:\__\        \:\__\        \:\__\        \::/  /
//     \/__/         \/__/       \/__/         \/__/         \/__/         \/__/         \/__/
//
//
//                日常
//        +-------------------+
//        |   Richang  JSEX   |
//        +-------------------+

Install

npm i -S richang.js

不使用 Node 相关模块

// ES6 modules
import Richang from "richang.js"

// Node.js (CJS) modules
var Richang =  require ("richang.js")

// 载入纯 ES6 modules
import Richang from "richang.js/dist/RichangEs.js"

// 捆绑了所有 node_modules 依赖
import Richang from "richang.js/dist/RichangEs.bundle.js"

使用 Node 相关模块

// 依赖在 node_modules 中
var Richang =  require ("richang.js/dist/RichangNode.js")

// 捆绑了所有 node_modules 依赖(bable 目标 Node 1.2 的模块, transform-runtime)
var Richang =  require ("richang.js/dist/RichangNode.bundle.js")

// 如果项目没有使用 babel, 可能需要单独使用 babel-polyfill
require("babel-polyfill")
var Richang =  require ("richang.js/dist/RichangNode.bundle.js")

如果遇到 ReferenceError: regeneratorRuntime is not defined ,需要安装 npm i -S babel-polyfill ,并且在引入 Richang.js 前先引入 babel-polyfill

Members

Time : Object

时间日期操作相关模块

Kind: global variable

Time.genTimestamp([raw])

生成时间戳(当前时间的 32 进制)

Kind: static method of Time

| Param | Type | Description | | --- | --- | --- | | [raw] | Object | 获取原始格式,比如 1521602474428 |

Time.parseTimestamp(timestamp) ⇒ Date

解析一个时间戳返回 date

Kind: static method of Time

| Param | | --- | | timestamp |

byteToHex

Convert array of 16 byte values to UUID string format of the form: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX

Kind: global variable

Tool : Object

通用工具相关模块

Kind: global variable

Tool.genUUID_v4() ⇒ string

生成一个随机的 UUID

genUUID_v4() => 'f8061fba-842b-4cc5-9872-9348e2e06916'

Kind: static method of Tool

Tool.genUUID_v5(name, [namespace]) ⇒ *

根据一个名字和命名空间生成一个 UUID,这个 UUID 与名称+命名空间有一一对应,不随机 (与标准不同,这里命名空间可不用 UUID 而是任何字符串,我们会用默认 UUID 和给命名空间生成一个 UUID)

genUUID_v5("Gasoft_Mobiusbug.exe","BGLL") => '2cb20c42-026f-5d56-b33f-008e354ac8d3'

Kind: static method of Tool

| Param | Type | Description | | --- | --- | --- | | name | string | 名称 | | [namespace] | string | 命名空间, |

Tool.genSHA1(str) ⇒ *

用 sha1 生成一个字符串

genSHA1("nullice") => 51918a176c8e2b0af211a94c5478c58a54f239cd

Kind: static method of Tool

| Param | Type | | --- | --- | | str | string |

Tool.formatUUID(str) ⇒ string

把36位字符串转换成带横杠 UUID 的格式

formatUUID("e9411a6f1a2e22dd2244b78ee491c616") => "e9411a6f1a2e22dd2244b78ee491c616"

Kind: static method of Tool

| Param | Type | | --- | --- | | str | string |

Tool.checkUUID(uuid) ⇒ number

检查一个字符串是 UUID 的版本或者是否是 UUID,返回 UUID 的版本,如果为 0 则说明不是 UUID

Kind: static method of Tool

| Param | Type | Description | | --- | --- | --- | | uuid | string | uuid |

Tool.roll(max, min)

生成一个随机整数

Kind: static method of Tool

| Param | Type | Description | | --- | --- | --- | | max | number | 最大值 | | min | number | 最小值 |

Tool.rollString(length, [dict]) ⇒ string

生成一个随机字符串

Kind: static method of Tool

| Param | Type | Description | | --- | --- | --- | | length | number | 随机字符串长度 | | [dict] | string | 随机字符字典,默认为 a—Z0-9 |

NodeFile : Object

文件操作相关模块

Kind: global variable

NodeFile.getTempDirManager(name) ⇒ *

生成一个临时文件夹管理器,会在系统临时目录中创建一个指定名字的临时文件夹,和一个实例临时文件夹 可以用得到的 TempDirManager,申请临时文件名,和销毁临时文件夹

var tepmDM = getTempDirManager("siphonink") tepmDM.genTempFilePath(subDir) - 申请一个临时文件路径,可用提供一个子文件夹名 tepmDM.destroy() - 销毁临时目录 tepmDM.clear(day) - 清除 day 天前的实例临时文件夹

Kind: static method of NodeFile

| Param | | --- | | name |

NodeDebug : Object

Node 调试相关模块

Kind: global variable

NodeDebug.logRed(text)

在终端打出红色 log

Kind: static method of NodeDebug

| Param | | --- | | text |

NodeDebug.cRed(text) ⇒ string | *

把文本标记为红色

Kind: static method of NodeDebug

| Param | | --- | | text |

NodeDebug.logBlue(text)

在终端打出蓝色 log

Kind: static method of NodeDebug

| Param | | --- | | text |

NodeDebug.cBlue(text) ⇒ * | string

把文本标记为蓝色

Kind: static method of NodeDebug

| Param | | --- | | text |

NodeDebug.logGreen(text)

在终端打出绿色 log

Kind: static method of NodeDebug

| Param | | --- | | text |

NodeDebug.cGreen(text) ⇒ string | *

把文本标记为绿色

Kind: static method of NodeDebug

| Param | | --- | | text |

NodeDebug.logGray(text)

在终端打出灰色 log

Kind: static method of NodeDebug

| Param | | --- | | text |

NodeDebug.cGray(text) ⇒ string | *

把文本标记为灰色

Kind: static method of NodeDebug

| Param | | --- | | text |

NodeDebug.logYellow(text)

在终端打出黄色 log

Kind: static method of NodeDebug

| Param | | --- | | text |

NodeDebug.cYellow(text) ⇒ string | *

把文本标记为黄色

Kind: static method of NodeDebug

| Param | | --- | | text |

NodeDebug.logLableRed(text)

在终端打出红色标签 log

Kind: static method of NodeDebug

| Param | | --- | | text |

NodeDebug.logLableYellow(text)

在终端打出黄色标签 log

Kind: static method of NodeDebug

| Param | | --- | | text |

NodeDebug.logLableCyan(text)

在终端打出蓝绿色标签 log

Kind: static method of NodeDebug

| Param | | --- | | text |

NodeDebug.logLableGreen(text)

在终端打出绿色标签 log

Kind: static method of NodeDebug

| Param | | --- | | text |

NodeDebug.logLableWhite(text)

在终端打出白色色标签 log

Kind: static method of NodeDebug

| Param | | --- | | text |

NodeImage : Object

Node 图片相关模块

Kind: global variable

NodeImage.ARGB_BufferToPngFileBuffer

Kind: static class of NodeImage

new ARGB_BufferToPngFileBuffer(argbBuffer, channelCount, wh)

把 ARGB 格式的像素 buffer 转化为可直接写入文件的 PNG buffer

| Param | Type | Description | | --- | --- | --- | | argbBuffer | buffer | argb | | channelCount | number | 通道数量 1-4 | | wh | object | 高宽 {w, h} |

NodeImage.getPngData ⇒ Promise.<Buffer>

获取 PNG 图片文件的像素数据 Buffer

Kind: static property of NodeImage

| Param | Type | Description | | --- | --- | --- | | data | buffer | PNG 文件的 buffer |

NodeTool : Object

Node 通用工具

Kind: global variable

NodeTool.getMD5(inData) ⇒ * | PromiseLike.<ArrayBuffer>

获取数据的 MD5 值

getMD5("白色的空曲奇在发热") => 3b81233f69cc6dbf83899148b888f0db

Kind: static method of NodeTool

| Param | Type | Description | | --- | --- | --- | | inData | buffer | string | 输入的数据 |

NodeTool.getSHA256(inData) ⇒ * | PromiseLike.<ArrayBuffer>

获取数据的 getSHA256 值

getSHA256("白色的空曲奇在发热") => 5be124e39cb90f3144fba1a798ab3a8472c24a44c0f9efc305f76c1e34de848f

Kind: static method of NodeTool

| Param | Type | Description | | --- | --- | --- | | inData | buffer | string | 输入的数据 |

NodeTool.arrayBuffertoBuffer(arrayBuffer) ⇒ Buffer

ArrayBuffer to Buffer

Kind: static method of NodeTool

| Param | Type | | --- | --- | | arrayBuffer | arrayBuffer |

ConsoleCON : Object

控制台相关功能模块

Kind: global variable

ConsoleCON.CSS_POST

控制台颜色

用法: console.log("%c test", CSS_POST)

Kind: static property of ConsoleCON

ObjectOBJ : Object

对象操作相关操作

Kind: global variable

ObjectOBJ.isEmptyObject(obj) ⇒ boolean

对象是否为空

Kind: static method of ObjectOBJ

| Param | | --- | | obj |

ObjectOBJ.objectCopyToObject(ob1, ob2, func_allowCopy, func_rename, func_valueFiter, func_for)

复制对象。可控制要复制的属性,复制后的属性名,处理新属性值

Kind: static method of ObjectOBJ

| Param | Description | | --- | --- | | ob1 | 源对象 | | ob2 | 目标对象 | | func_allowCopy | 判断是否允许复制的函数,返回真允许复制 func_allowCopy(属性名,属性值)。可空 | | func_rename | 重命名复制到目标对象上的属性名, 返回新属性名 func_rename(属性名,属性值)。可空 | | func_valueFiter | 处理复制到目标对象上的属性值,返回处理后的属性值 func_rename(属性名,属性值)。可空 | | func_for | 每次循环执行的函数 func_for(ob1,ob2,x)。可空 |

ObjectOBJ.setObjectValueByNames(object, names, value)

根据属性名路径列表(names)对对象属性赋值

Kind: static method of ObjectOBJ

| Param | Description | | --- | --- | | object | 对象 | | names | 属性名路径列表,如 [position,enableAssigns,y] | | value | 值 |

ObjectOBJ.deleteObjectValueByNames(object, names)

根据属性名路径列表(names)对对象属性删除

Kind: static method of ObjectOBJ

| Param | Description | | --- | --- | | object | 对象 | | names | 属性名路径列表,如 [position,enableAssigns,y] |

ObjectOBJ.treeFind(objectArr, match, childrenKey, findAll, depthFirst) ⇒ array | null

在由对象数组组成的树中查找对象。如果查找全部结果会以数组返回,否则直接返回找到的对象。

tree = [ {id: 1, children: [{id: 4}]}, {id: 2}, ] findTree (tree, 4, "children", false, false) => {id: 4}

Kind: static method of ObjectOBJ

| Param | Type | Description | | --- | --- | --- | | objectArr | Array.<object> | 对象数组组成的树 | | match | function | 匹配器 - 如果是字符串则是匹配对象下的 id 键,也可提供一个匹配函数,匹配函数通过参数接收遍历到的对象,返回是否匹配的 boolen (ob)={retrun ob.name=="xxx">} | | childrenKey | string | 子树键名 - 通过这个名字在对象中找子树 | | findAll | boolean | 是否查找全部 | | depthFirst | boolean | 深度优先 - 默认是广度优先 |

ObjectOBJ.treeEach(objectArr, eachFunc, childrenKey, depthFirst) ⇒ Object

在由对象数组组成的树中遍历处理树的每个节点。

处理函数: eachFunc(单个对象, 遍历深度, 当层深度节点计数, 总节点计数, 当前子树, 当前子树位置) 在 eachFunc 中 return true 可以提前终止遍历。 当前子树[当前子树位置+1] 可获取下一个节点。 返回树的信息: { struct:[4,2,5], // 每层节点数 deep:3, // 树深度 total: 11 // 总节点数 }

Kind: static method of ObjectOBJ

| Param | Type | Description | | --- | --- | --- | | objectArr | Array.<object> | 对象数组组成的树 | | eachFunc | function | 处理函数 | | childrenKey | string | 子树键名 - 通过这个名字在对象中找子树 | | depthFirst | boolean | 深度优先 - 默认是广度优先 |

ObjectOBJ.pathEach(object, eachFunc, [checkCycle])

遍历对象每一个元素,可以获取对象键名组成的 path (["c","d","e"])

处理函数: eachFunc(当前元素, 当前 path, 当层深度 )

pathEach( { b:111, c:{d:{e:222}} })

Kind: static method of ObjectOBJ

| Param | Type | Description | | --- | --- | --- | | object | object | | | eachFunc | function | 处理函数 | | [checkCycle] | boolean | function | 是否检查循环引用,为 true 会跳过循环引用,还可以提供一个函数 checkCycleCallback(target, path, cyclePath) 来处理一些事 |

StringSTR : Object

字符串相关功能模块

Kind: global variable

StringSTR.left(str, offset) ⇒ *

取字符串左边 *依赖 stringSTR.right()

Kind: static method of StringSTR

| Param | Type | Description | | --- | --- | --- | | str | String | 原文 | | offset | Number | 偏移值 |

StringSTR.right(str, offset) ⇒ *

取字符串右边。 *依赖 stringSTR.left()

Kind: static method of StringSTR

| Param | Type | Description | | --- | --- | --- | | str | String | 原文 | | offset | Number | 偏移值 |

StringSTR.insert(str, start, offset, inStr) ⇒ *

插入文本到指定位置

Kind: static method of StringSTR

| Param | Type | Description | | --- | --- | --- | | str | String | 原文 | | start | Number | 开始位置 | | offset | Number | 偏移值 | | inStr | String | 要插入的文本 |

Rect : Object

矩形处理相关模块

Kind: global variable

Rect.rltb2xywh(boundsInfo) ⇒ Object

坐标转换 把 {right, left, top, bottom} 转化为 {x, y , w, h}

Kind: static method of Rect

| Param | | --- | | boundsInfo |

Rect.xywh2rltb(boundsInfo) ⇒ Object

坐标转换 把 {x, y , w, h} 转化为 {right, left, top, bottom}

Kind: static method of Rect

| Param | | --- | | boundsInfo |

Rect.paddingXywh(xywh, padding) ⇒ Object

给 xywh 添加内边距

paddingXywh(xywh, 5) paddingXywh(xywh, [3,4,5,10])

Kind: static method of Rect

| Param | | --- | | xywh | | padding |

Rect.getXywhsRange(xywhs) ⇒ Object

计算多个 xywh 矩形的边界

getXywhsRange([xywh])

Kind: static method of Rect

| Param | | --- | | xywhs |

Rect.moveXywhs(xywhs, xy)

整体移动多个 xywh 到某点,保留原 xywhs 相对位置。 会改变 xywhs 里每个 xywh 对象的 x,y 值。

Kind: static method of Rect

| Param | | --- | | xywhs | | xy |

Rect.xywhHasCover(xywhA, xywhB) ⇒ boolean

2 个 xywh 是否有重叠

Kind: static method of Rect

| Param | | --- | | xywhA | | xywhB |

TypeTYP : Object

类型相关模块

Kind: global variable

TypeTYP.getType(value) ⇒ *

得到指定值的数据类型。返回数据类型名称字符串,如 "boolean","object","string" 。

Kind: static method of TypeTYP

| Param | | --- | | value |

AarryArr : Object

数组相关功能模块

Kind: global variable

AarryArr.symDifference(a, b) ⇒ Array

对称差。(不支持对象数组)

a:[1,2,3] b:[1,2,4] a△b => [3,4]

Kind: static method of AarryArr

| Param | Type | | --- | --- | | a | Array | | b | Array |

AarryArr.symDifference_ObjectArray(a, b, key) ⇒ Array

对称差。对象数组。 a:[{key:1}, {key:2}] b:[{key:2}, {key:3}] a△b => [{key:1},{key:3}]

Kind: static method of AarryArr

| Param | Description | | --- | --- | | a | | | b | | | key | 对象关键属性 |

AarryArr.difference(a, b) ⇒ Array

差集。(不支持对象数组) a:[1,2,3] b:[1,2,4] a-b => [3]

Kind: static method of AarryArr

| Param | Type | | --- | --- | | a | Array | | b | Array |

AarryArr.union(a, b) ⇒ Array

并集。(不支持对象数组) a:[1,2,3] b:[1,2,4] a∪b => [1,2,3,4]

Kind: static method of AarryArr

| Param | Type | | --- | --- | | a | Array | | b | Array |

AarryArr.intersection() ⇒ Array

交集。(不支持对象数组) a:[1,2,3] b:[1,2,4] a∩b => [1,2]

Kind: static method of AarryArr

AarryArr.remove(arr, removeRule, isMutator) ⇒ *

从数组中移除元素,默认是非变异的。

Kind: static method of AarryArr

| Param | Type | Description | | --- | --- | --- | | arr | Array | | | removeRule | function | 可以给定值或者一个判断函数 function(x){ return x>3;} | | isMutator | Boolean | 变异模式,为真会改变原数组 |

AarryArr.hasMember(arr, memberValue, equalFunc) ⇒ boolean

数组是否拥有指定成员 arr:["A","B","C"] => hasMember(arr, "C") => true

Kind: static method of AarryArr

| Param | Type | Description | | --- | --- | --- | | arr | Array | | | memberValue | | 指定成员值 | | equalFunc | | 比较函数,boolean equalFunc( arr[i], memberValue)。可空。 |

AarryArr.getByKey(objectArr, key, keyValue, equalRule) ⇒ *

对象数组查找 从对象数组中提取出一个对象,根据对象的一个属性值。 arr: [{name:a},{name:b}] getByKey(arr,"name","b") => return {name:b}

Kind: static method of AarryArr

| Param | Type | Description | | --- | --- | --- | | objectArr | Array.<Object> | 对象数组 | | key | String | 关键属性 | | keyValue | | 欲提取的关键属性值 | | equalRule | | 值比较函数,可空 |

AarryArr.deleteByKey(objectArr, key, keyValue, equalRule) ⇒ *

对象数组删除 从对象数组中找到出一个对象元素,并删除这个元素。 arr: [{name:a},{name:b}] deleteByKey(arr,"name","b") => arr: [{name:a}]

Kind: static method of AarryArr

| Param | Type | Description | | --- | --- | --- | | objectArr | Array.<Object> | 对象数组 | | key | String | 关键属性 | | keyValue | | 欲提取的关键属性值 | | equalRule | | 值比较函数,可空 |

AarryArr.sortObjectArray(arr, key, bigFront)

排序对象数组

Kind: static method of AarryArr

| Param | Type | Description | | --- | --- | --- | | arr | | 数组 | | key | a:12 | 对象排序的键值,如 [, {a:33}] , key 为 "a" 则以 a 排序 | | bigFront | | 大值在前 |

Calc : Object

计算相关功能模块

Kind: global variable

FileFIL : Object

文件操作相关模块

Kind: global variable

FileFIL.filterFileName(name, fix) ⇒ *

去除一个字符串中不符合成为文件名的字符

Kind: static method of FileFIL

| Param | Description | | --- | --- | | name | | | fix | 非法字符替代 |

Cache : Object

缓存相关

Kind: global variable