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

js-common-utils

v1.0.11

Published

JavaScript Common Utils By sweetQwQ

Downloads

6

Readme

js-common-utils

目录

CommonUtils
CheckUtils
ObjectUtils
DeviceUtils

一.介绍

JS公共库,安装即用

二.安装教程

#使用yarn
yarn add js-common-utils
#使用npm
npm install js-common-utils

三.使用说明

webpack环境引入

imput {CommonUtils,CheckUtils} from 'js-common-utils';

node环境引入

const commonUtils = require('../dist/index.js');

四.使用文档

CommonUtils

deepClone 硬拷贝

deepClone()
  • 方法详细介绍 判断是否为整数

  • 参数

| 参数 | 类型 | 是否必传 | 默认值 | 说明 | |:-----|:----|:-----:|:------:|:-----| | data | any | 是 | 无 | 拷贝对象 |

  • 返回值 深拷贝后的数据
  • 举个例子
let data = 3
let data2 = deepClone(data)
data = 4
console.log(data2)
// ==>3

CheckUtils

check 表单验证

check()
  • 方法详细介绍 表单验证
    提供非空、手机号格式、身份证号格式、邮箱格式、姓名格式、自定义规则验证

  • 参数

| 参数 | 类型| 是否必传 | 默认值 | 说明 | |:--------|:---------|:----:|:------:|:--------| | type | string | 是 | 无 | 验证类型 | | data | any | 是 | 无 | 验证数据 | | message | string | 否 | 无 | 报错信息 | | rule | Function | 否 | 无 | 自定义验证方法 |

  • type

| 参数 | 说明 | |:----------|:--------------| | empty | 非空验证 | | idCard | 身份证号验证 | | phone | 手机号验证 | | name | 姓名验证 | | boolean | boolean类型验证 | | email | 邮箱验证 | | rule | 使用自定义验证方法进行验证 |

  • 返回值 无正常返回值,验证不通过后会抛出异常
  • 举个例子
let data = 3
check('empty', data, '数据为空!')
//==> success
data = ''
check('empty', data, '数据为空!')
//==> error

ObjectUtils

equal 判断两个对象是否相等

equal()
  • 方法详细介绍 判断两个对象是否相等

  • 参数

| 参数 | 类型 | 是否必传 | 默认值 | 说明 | |:-----|:-------|:----:|:------:|:----| | obj1 | object | 是 | 无 | 对象1 | | obj2 | object | 是 | 无 | 对象2 |

  • 返回值 Boolean
  • 举个例子
let a = {Symbol: 1}
let b = {Symbol: 2}
let obj1 = {a: ['123'], b: a}
let obj2 = {a: ['123'], b: b}
console.log(utils.ObjectUtils.equal(obj1, obj2))
//==> false

console.log(utils.ObjectUtils.equal(['123', {a: '123'}], ['123', {a: '123'}]))
//==> true

DeviceUtils

getExplore 判断当前运行环境
getOS 获取操作系统类型

getExplore()
  • 方法详细介绍 判断当前运行环境

  • 返回值 string

  • 举个例子

getExplore()
// ==> Chrome
getOS()
  • 方法详细介绍 获取操作系统类型

  • 返回值 string

  • 举个例子

getOS()
// ==> windows