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

funclib-mp

v6.0.6

Published

A powerful javascript functions library!

Downloads

80

Readme

funclib.js

npm LICENSE MIT Build Status Coverage Status

语言 Language: English | 简体中文

一、简单介绍

Funclib: 让你高效优雅的完成业务代码!

funclib.js 是一个简单、易用、贴进业务逻辑的JavaScript函数库,以高效完成业务代码为目标,具有“通用、实用、易用、好用”等特点!类似于 underscore 和 lodash。 跟它们对比,funclib.js省去了很多js自带的或者不常用的方法,并且改进和拓展了很多方法的使用方式。

funclib.js还根据一些实际业务的逻辑的规律封装了很多前后端都实用的新方法, 让你提高代码质量和交付效率的同时,享受编程的乐趣!

funclib.js使用 Karma / Mocha 进行自动化单元测试, 使用 Travis-CI 进行持续集成。

文档地址:  https://www.funclib.net

二、快速开始

2.1 快速安装funclib

yarn: $ yarn add funclib npm: $ npm install funclib

2.2 在小程序中安装

yarn: $ yarn add funclib-mp npm: $ npm install funclib-mp

2.3 在JavaScript中使用

var fn = require('funclib');
// 在小程序中: var fn = require('funclib-mp');

var ps = [{name: 'Tom', age: 18}, {name: 'Bob', age: 22}];
fn.log(ps, 'Persons');

Output:

// =>
==================================================================
                       [10:33:55] Persons 
------------------------------------------------------------------
[
  {
    "name": "Tom",
    "age": 18
  },
  {
    "name": "Bob",
    "age": 22
  }
]
==================================================================

> // var bob = fn.find(ps, function(p) { return p.name === 'Bob'; });
> // var bob = fn.find(ps, {name: 'Bob'});
> var p = fn(ps).find({name: 'Bob'}).set('name', 'Lee').val();
> fn.log(p, 'Person');
// =>
==================================================================
                       [10:33:55] Person
------------------------------------------------------------------
{
  "name": "Lee",
  "age": 22
}
==================================================================

三、克隆项目

# 克隆funclib
$ git clone https://github.com/CN-Tower/funclib.js.git

# 安装依赖
$ npm install

# 开始
$ npm start

# 试运行
$ npm run usage

# 构建
$ npm run build

# 测试
$ npm run test

四、函数库方法

==================================================================
* [c]: Client side method 客户端方法
* [s]: Server side method 服务端方法
* [-]: Common method      服务端和客户端通用的方法
------------------------------------------------------------------
 ## Type
 * fn.typeOf                [-] 检查值的类型
 * fn.typeVal               [-] 获取期望类型的值
 * fn.isStr                 [-] 判断类型是否为:string
 * fn.isNum                 [-] 判断类型是否为:number
 * fn.isBol                 [-] 判断类型是否为:boolean
 * fn.isFun                 [-] 判断类型是否为:function
 * fn.isNul                 [-] 判断是否为:null
 * fn.isUdf                 [-] 判断类型是否为:undefined
 * fn.isErr                 [-] 判断类型是否为:Error
 * fn.isDat                 [-] 判断类型是否为:Date
 * fn.isReg                 [-] 判断类型是否为:RegExp
 * fn.isArr                 [-] 判断类型是否为:Array
 * fn.isObj                 [-] 判断是否为:正常Object
 ## Array
 * fn.array                 [-] 返回指定长度和默认值的数组
 * fn.range                 [-] 返回一个范围数组
 * fn.toArr                 [-] 值数组化
 * fn.indexOf               [-] 寻找值在数组中的索引
 * fn.find                  [-] 根据条件寻找值
 * fn.filter                [-] 根据条件取过滤值
 * fn.reject                [-] 根据条件过滤值
 * fn.contains              [-] 判断数组是否包含符合条件的值
 * fn.drop                  [-] 去掉空数组空对象及布尔化后为false的值
 * fn.flatten               [-] 把有结构的数组打散,减少层数
 * fn.pluck                 [-] 把结构中的字段取出合并到一个数组中
 * fn.uniq                  [-] 去重或根据字段去重
 * fn.each                  [-] 遍历数组或类数组, 同: fn.forEach
 * fn.forEach               [-] 遍历数组或类数组
 * fn.sortBy                [-] 返回对象数组根据字段排序后的副本
 ## Object
 * fn.len                   [-] 获取对象自有属性的个数
 * fn.has                   [-] 判断对象是否存在某自有属性
 * fn.get                   [-] 返回对象或子孙对象的属性,可判断类型
 * fn.set                   [-] 设置对象或子孙对象的属性
 * fn.keys                  [-] 返回对象的键值数组
 * fn.pick                  [-] 获取包含部分属性的对象副本
 * fn.omit                  [-] 获取省略部分属性的对象副本
 * fn.extend                [-] 给对象赋值,可指定字段
 * fn.forIn                 [-] 遍历对象的可数自有属性
 * fn.deepCopy              [-] 深拷贝数组或对象
 * fn.isEmpty               [-] 判断对象是否为空对象或数组
 * fn.isDeepEqual           [-] 判断数组或对象是否相等
 ## Math
 * fn.random                [-] 返回指定范围的随机数
 * fn.randomId                   [-] 返回指定长度的随机ID
 * fn.randomColor                [-] 返回一个随机色值
 ## Time
 * fn.interval              [-] 循环定时器
 * fn.timeout               [-] 延时定时器
 * fn.defer                 [-] 延迟执行函数
 * fn.time                  [-] 返回一个时间戳, 同:fn.timestamp
 * fn.timestamp             [-] 返回一个时间戳
 * fn.asUtcTime             [-] 转化为相同时间的UTC时间戳
 * fn.asXyzTime             [-] 转化为相同时间指定时差的时间戳
 * fn.fmtDate               [-] 获取格式化的时间字符串
 * fn.fmtUtcDate            [-] 获取格式化的UTC时间字符串
 * fn.fmtXyzDate            [-] 获取格式化指定时差的时间字符串
 ## String
 * fn.match                 [-] 字符串匹配
 * fn.pretty                [-] 转换成格式化字符串
 * fn.escape                [-] 编码HTML字符串
 * fn.unescape              [-] 解码HTML字符串
 * fn.capitalize            [-] 字符串首字母大写
 * fn.fmtCurrency           [-] 格式化显示货币
 * fn.maskString            [-] 编码字符串或其子串
 * fn.cutString             [-] 裁切字符串到指定长度
 * fn.parseQueryStr         [-] 解析Url参数成对象
 * fn.stringifyQueryStr     [-] 把对象编译成Url参数
 ## RegExp
 * fn.setPattern            [-] 设置一个正则表达式
 * fn.getPattern            [-] 获取一个通用的正则表达式
 * fn.testPattern           [-] 用一个或几个通用正则测试
 * fn.matchPattern          [-] 与一个或几个通用正则匹配
 ## Function
 * fn.rest                  [-] 获取函数的剩余参数
 * fn.throttle              [-] 节流函数
 * fn.debounce              [-] 防抖函数
 ## Loger
 * fn.chalk                 [s] 返回带颜色的字符串
 * fn.print              [c][s] 在控制台打印值
 * fn.log                [c][s] 在控制台打印格式化的值
 ## Tools
 * fn.rd                    [s] 读文件
 * fn.wt                    [s] 写文件
 * fn.cp                    [s] 复制文件夹和文件
 * fn.mv                    [s] 移动文件夹和文件
 * fn.rm                    [s] 删除文件夹和文件
 * fn.mk                    [s] 创建文件夹
 * fn.size                  [s] 获取文件的大小
 * fn.clear                 [s] 控制台清屏
 * fn.copyText              [c] 复制文本到粘贴板
 ## Progress
 * fn.progress              [s] 进度显示工具
 * fn.progress.stop         [s] 停止进度,结束后触发回调
 ## Tricks
 * fn.chain                 [-] 返回链接调用对象
 * fn().method              [-] 返回链接调用对象
 * fn.noConflict            [-] 释放fn变量占用权
 * fn.version               [-] 返回当前函数库版本
==================================================================

五、项目结构

funclib.js
├── node_modules/           ### You know the drill...
├── script                  ### 脚本
│   ├── build.js            # 构建脚本
│   ├── karma.conf.js       # Karma测试框架配置
│   ├── pre-build.js        # 构建配置脚本
│   └── test.js             # 测试配置脚本
├── src                     ### Source code
│   ├── funclib/            # 库的函数
│   ├── funclib.core.js     # 通用版
│   ├── funclib.js          # 未压缩版客户端版
│   ├── funclib.min.js      # 压缩版客户端版
│   ├── index.d.ts          # 定义文件
│   ├── index.js            # 服务端版
│   ├── package.json        # 库模块定义
│   └── README.md           # Read this FIRST :)
├── test                    ### 测试
│   ├── client-methods/     # 客户端版测试用例
│   ├── core-methods/       # 通用版测试用例
│   ├── server-methods/     # 服务端版测试用例
│   ├── fn-core.js          # 通用版测试文件
│   └── fn-index.js         # 服务端版测试文件
├── .coveralls.yml          # 测试覆盖率
├── .editorconfig           # Set coding style (indents, charset, etc.)
├── .gitignore              # You know the drill...
├── .travis.yml             # CI配置
├── LICENSE                 # 授权说明
├── package-lock.json       # NPM Lock
├── package.json            # 库配置
├── README.md               # Read this FIRST :)
├── tsconfig.json           # Typescript配置
├── usage.html              # 客户端试验
└── usage.js                # 服务端试验