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

utility-mar

v1.0.30

Published

常用的公共组件

Downloads

11

Readme

工具库 utility-mar

常见的一些工具类方法

目录

安装

// 全部引入
import * as utility from utility-mar;
// 或者
// 按需引入
import {utiDate} from utility-mar;

API

utility.method调用对应的API库

method为以下API方法

.utiDate

将时间转换为xxxx-xx-xx xx:xx:xx

  • utility.utiDate.toTime(date)
  • utility.utiDate.toDateTime(date)
  • utility.utiDate.toDate(date)

date参数:[Date] | 毫秒[Number] | 毫秒[String]

.cookie

  • .get(name)
  • .set({key, value, end, path, domain, secure})

.dataFormat

数据格式化处理

  • .deleteEmpty(obj) 删除空元素

.download

下载

.validator

校验相关

示例

import { validator as validatorOrigin } from utility-mar;
// 使用:实例化一个validator
const validator=new validatorOrigin({
  // 自定义的校验type , reg规则 ,错误信息
  patterns:{
    'mobile':{
      'pattern': /^1\d{10}$/,
      'errorMessage': '请输入正确的手机号码'
    },
  },
  // 自定义错误回调方法
  errorHandler:({desc})=>{
    Vue.prototype.$Notice.warning({
      title:'输入错误',
      //msg取传入,没有取默认
      desc
    })
  }
});

//调用
validator.validate({isEmpty:true,params:[
  {
    type:"mobile",
    errorMessage:"..."
  }
]})
  .then((valid)=>{
    if(valid){
      // valid是校验结果
    }
  })

validator实例 API

  • .getPattern({ type:'mobile' })

返回:type对应的pattern对象

// 返回
{
  'pattern':/^\d{6,12}$/,//正则表达式
  'errorMessage': '请输入正确的qq'//错误message信息
}
  • .validate([{type,value,msg}])

执行校验方法

返回:promise

默认支持的type类型

qq

mobile

name

cnid

plateNumber 车牌号

noBlank 匹配一个非空白符

password 8位数字加字母的组合

.copy

  1. .deepCopy 深拷贝

  2. .deepDiff(parama, paramb) 比较

如果相同,返回true。否则返回false

.dataStructure

  • .Tree
import { dataStructure } from "utility-mar"
let data = [{
  label: 'aa',
  children: [{
      label: 'bb'
    },
    {
      label: 'cc'
    }
  ]
}, {
  label: '2'
}];
let treeInstance = new dataStructure.Tree(data);
console.log("输入原始data");
console.log(data);
console.log(treeInstance.getNode(1).getParent().getData());

.color

  • .getGradientColorsByValues

  • .getLightDarkColor

  • .getGradientColorsByNum

.util

  • .unionArray 合并两个数组,并集
  • .throttle 节流函数

开发步骤

npm install

需要更新对应方法库,在src目录下对应方法文件编写即可
新增方法,在根目录index.js导出加入

测试

安装mocha chai 在test目录写对应js的测试文件
mocha执行测试
mocha chai

发布

执行yarn build 修改package.json版本
npm login marjoven *****
npm publish