1.1.0 • Published 4 years ago

cuckoo-function v1.1.0

Weekly downloads
4
License
ISC
Repository
github
Last release
4 years ago

cuckoo-function

  • 常用函数库

快速上手直通车

如何使用cuckoo-function

npm install cuckoo-function

import CuckooFunction  from 'cuckoo-function';
console.log(CuckooFunction.add(1,2)); 

函数汇总列表

  1. 数组操作
函数名称函数描述函数如何调用
unique数组去重CuckooFunction.unique(arr)
  1. 四则运算
函数名称函数描述函数如何调用
plus加法CuckooFunction.plus('0.001', '3243.32323')
subtraction减法CuckooFunction.subtraction('0.001', '3243.33')
multiplication乘法CuckooFunction.multiplication('0.001', '3')
division除法CuckooFunction.division('0.001', '3243.32323')
  1. 浏览器类
函数名称函数描述函数如何调用
getExplore获取浏览器版本信息CuckooFunction.getExplore()
  1. 日期类
函数名称函数描述函数如何调用
getPreDay获取昨天CuckooFunction.getPreDay('2019-11-11')
getNextDay获取明天CuckooFunction.getNextDay('2019-11-11')
getPreWeek获取前一个周CuckooFunction.getPreWeek('2019-11-11')或CuckooFunction.getPreWeek('2019.11.11')下同
getPreMouth获取前一个月CuckooFunction.getPreMouth('2019-11-11')
getPreYear获取前一年CuckooFunction.getPreYear('2019-11-11')
getPreThreeMouth获取前一个季度CuckooFunction.getPreThreeMouth('2019-11-11')
getNextWeek获取下一周CuckooFunction.getNextWeek('2019-11-11')
getNextMouth获取下一个月CuckooFunction.getNextMouth('2019-11-11')
getNextYear获取下一个年CuckooFunction.getNextYear('2019-11-11')
getDateDistance获取时间段数组CuckooFunction.getDateDistance('2019-11-11')
formatDate格式化时间CuckooFunction.dateFormat('YYYY-mm-dd', new Date()) 或 CuckooFunction.dateFormat('YYYY', new Date())
isLeapYear是否是闰年CuckooFunction.isLeapYear(2019)
getDaysForMonth获取指定月份的天数CuckooFunction.getDaysForMonth(2019, 12)
  1. 数据字典类
函数名称函数描述函数如何调用
codeToName字典数据编码转中文CuckooFunction.codeToName({ '1000': 23, '4000': 3232},{'code': '21212', 'title': 'AAAAA', 'childrens': {'code': '1000', 'title': '洛阳'}})
  1. 货币类
函数名称函数描述函数如何调用
numberToChinese数字转大写中文CuckooFunction.numberToChinese(21231)
  1. 校验类
函数名称函数描述函数如何调用
checkPhone是否是手机号CuckooFunction.checkPhone('13933333333')
checkTelephone是否是电话号码CuckooFunction.checkTelephone('430-3333')
checkBankCard是否是银行卡号CuckooFunction.checkBankCard('21232321321313')
checkEmail是否是emailCuckooFunction.checkEmail('dsd@163.com')
checkIdCard是否是身份证CuckooFunction.checkIdCard('153434366666666666')
isObj是否是ObjectCuckooFunction.isObj({})
isArray是否是数组CuckooFunction.isArray([])
isEmpty是否是null或undefined类型CuckooFunction.isEmpty('0')
isEmpty判断空CuckooFunction.isEmpty()
checkNumber是否全部是数字CuckooFunction.checkNumber()
checkDecimal是否为数字CuckooFunction.checkDecimal()
checkInteger是否为整数CuckooFunction.checkInteger()
checkNoCnString是否是非汉字字符CuckooFunction.checkNoCnString()
checkChinese是否包含汉字CuckooFunction.checkChinese()
checkQQ是否是QQ号CuckooFunction.checkQQ()
checkIP是否是IP地址CuckooFunction.checkIP()
checkURL是否是URLCuckooFunction.checkURL()
checkQuote是否包含特殊字符CuckooFunction.checkQuote()
checkDate检查是否是日期,验证短日期(2019-11-11)CuckooFunction.checkDate()
checkTime是否是时间,验证时间(10:57:10)CuckooFunction.checkTime()
checkFullTime是否是时间,验证时间(2019-11-11 10:57:10)CuckooFunction.checkFullTime()
checkSexByIdCard判断性别CuckooFunction.checkSexByIdCard()
checkEnStrRange是否是0-20个字母数字组合CuckooFunction.checkEnStrRange()
  1. 字符串类
函数名称函数描述函数如何调用
guiduuidCuckooFunction.uuid()
trim去掉两边空格CuckooFunction.trim(' d ')
trimLeft去掉左侧空格CuckooFunction.trimLeft(' d ')
trimRight去掉右侧空格CuckooFunction.trimRight(' d ')

函数详解

附件

如何构建函数库应用

1.登陆

npm login
// 登陆过程中,如果有问题,出现403,一般有几种情况,一是因为发布包的名称与npm库重复;还有则是用户名错误等

2.初始化

// 配置函数库名、版本号、作者......
npm init

package name: (cuckoo-function) 
version: (1.0.0) 
description: 常用函数库
entry point: (index.js) 
test command: 
git repository: (https://github.com/ddcome/cuckoo-function.git) 
keywords: 函数库
author: ddcome
license: (ISC) 

3.webpack安装和配置

npm install --save-dev clean-webpack-plugin
// 根目录创建webpack.config.js
// node 核心模块,处理路径相关
const path = require('path')
// webpack插件,新版本用法发与webpack中文网上写的有点出入,需要注意
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
// 引入模板文件, 看你需不需要
// const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  mode: 'production',
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'index.js',
    libraryTarget: 'umd',
    library: 'Biu', // Peanut 可以随便更换,不是固定值,是函数库名字,类似Jquery
  },
  plugins: [
         new CleanWebpackPlugin(),
        //  new HtmlWebpackPlugin({ template: './src/index.html' }),
        ],

}

4.安装其他的包babel

npm install --save-dev babel-loader @babel/core @babel/cli @babel/preset-env
npm install --save @babel/polyfill

5.babel预设配置在根目录下创建配置文件babel.config.js或者.babelrc

babel.config.js

const presets = [
  [
    "@babel/env",
    {
      targets: {
        edge: "17",
        firefox: "60",
        chrome: "67",
        safari: "11.1",
      },
      useBuiltIns: "usage",
    },
  ],
];
module.exports = { presets };

.babelrc

{
    "presets": [
        [
          "@babel/env",
          {
            "targets": {
              "edge": "17",
              "firefox": "60",
              "chrome": "67",
              "safari": "11.1",
            },
            "useBuiltIns": "usage",
          },
        ],
      ],
    "plugins": []
  }

webpack配置babel-loader解析es6

module: {
            rules: [
              {
                test: /\.js$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                  loader: 'babel-loader',
                  options: {
                    presets: ['@babel/preset-env']
                  }
                }
              }
            ]
          }

6.开始编写

mkdir src
touch src/index.js

// index.js
function add(a, b) {
  return a + b
}
export default {add}
  
export default { add }
// 使用import引入 import Biu from 'biu-function'
// 这个Biu就是导出的default对象
// 使用 script标签引入,则需要使用Biu.default.add()
// Biu实在webpack.config.js定义的library的名字

7.构建与发布

"build": "webpack"
// "build": "webpack --config webpack.config.js"
  
"main": "dist/index.js"
修改版本号后
npm run build // 相当于执行 webpck进行打包
npm publish // 直接发布

8.使用

npm install cuckoo-funciton

import CuckooFunction  from 'cuckoo-function';
console.log(CuckooFunction.add(1,2)); 
1.1.0

4 years ago

1.0.27

4 years ago

1.0.26

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago