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

pangju-utils

v2.3.2

Published

常用js工具类,命名和实现参考Apache Java Common Utils

Downloads

3

Readme

https://img.shields.io/badge/{徽标标题}-{徽标内容}-{徽标颜色}.svg

// eg build

https://img.shields.io/github/issues/{github用户名}/{仓库名}.svg https://img.shields.io/github/forks/{github用户名}/{仓库名}.svg https://img.shields.io/github/stars/{github用户名}/{仓库名}.svg https://img.shields.io/github/license/{github用户名}/{仓库名}.svg

js-utils开发文档

此工具主要由typescript编写而成,目的在于减少日常开发中的一些重复性和样板式代码。 如果你在使用过程中,发现了一些错误,请及时反馈 ,谢谢!!!

[TOC]

ObjectUtils(对象工具类)

isExist

说明

判断对象是否存在,若为undefined则返回false,否则返回true

用法

// CommonJS
const ObjectUtils = require('@pangju666/js-utils/ObjectUtils')
// ESM
import { ObjectUtils } from '@pangju666/js-utils'

句法

isExist(value: unknown): boolean

参数

| 名称 | 类型 | 描述 | | --- | ---- | --- | | value | * | 待检查对象 |

返回

| 类型 | 描述 | | ---- | ---- | | Boolean | 如果对象存在则返回true,否则返回false |

异常

| 类型 | 描述 | | ---- | ---- | | 无 | 无 |

样例代码

const val2 = undefined
ObjectUtils.isExist(val2) // return false

const val1 = null
ObjectUtils.isExist(val1) // return true

const val3 = 2
ObjectUtils.isExist(val3) // return true

const val4 = ''
ObjectUtils.isExist(val4) // return true

const val5 = {}
ObjectUtils.isExist(val5) // return true

isNotExist

说明

判断对象是否存在,若为undefined则返回true,否则返回false

用法

// CommonJS
const ObjectUtils = require('@pangju666/js-utils/ObjectUtils')
// ESM
import { ObjectUtils } from '@pangju666/js-utils'

句法

isNotExist(value: unknown): boolean

参数

| 名称 | 类型 | 描述 | | --- | ---- | --- | | value | * | 待检查对象 |

返回

| 类型 | 描述 | | ---- | ---- | | Boolean | 如果对象存在则返回false,否则返回true |

异常

| 类型 | 描述 | | ---- | ---- | | 无 | 无 |

样例代码

const val2 = undefined
ObjectUtils.isExist(val2) // return true

const val1 = null
ObjectUtils.isExist(val1) // return false

const val3 = 2
ObjectUtils.isExist(val3) // return false

const val4 = ''
ObjectUtils.isExist(val4) // return false

const val5 = {}
ObjectUtils.isExist(val5) // return false

isNull

说明

判断对象是否为空,若为nullundefined则返回true,否则返回false

用法

// CommonJS
const ObjectUtils = require('@pangju666/js-utils/ObjectUtils')
// ESM
import { ObjectUtils } from '@pangju666/js-utils'

句法

isNull(value: unknown): boolean

参数

| 名称 | 类型 | 描述 | | --- | ---- | --- | | value | * | 待检查对象 |

返回

| 类型 | 描述 | | ---- | ---- | | Boolean | 如果对象为空则返回true,否则返回false |

异常

| 类型 | 描述 | | ---- | ---- | | 无 | 无 |

样例代码

const val2 = undefined
ObjectUtils.isNull(val2) // return true

const val1 = null
ObjectUtils.isNull(val1) // return true

const val3 = 2
ObjectUtils.isNull(val3) // return false

const val4 = ''
ObjectUtils.isNull(val4) // return false

const val5 = {}
ObjectUtils.isNull(val5) // return false

isNotNull

说明

判断对象是否为空,若为nullundefined则返回false,否则返回true

用法

// CommonJS
const ObjectUtils = require('@pangju666/js-utils/ObjectUtils')
// ESM
import { ObjectUtils } from '@pangju666/js-utils'

句法

isNull(value: unknown): boolean

参数

| 名称 | 类型 | 描述 | | --- | ---- | --- | | value | * | 待检查对象 |

返回

| 类型 | 描述 | | ---- | ---- | | Boolean | 如果对象为空则返回false,否则返回true |

异常

| 类型 | 描述 | | ---- | ---- | | 无 | 无 |

样例代码

const val2 = undefined
ObjectUtils.isNull(val2) // return false

const val1 = null
ObjectUtils.isNull(val1) // return false

const val3 = 2
ObjectUtils.isNull(val3) // return true

const val4 = ''
ObjectUtils.isNull(val4) // return true

const val5 = {}
ObjectUtils.isNull(val5) // return true

isExistProperty

说明

判断对象属性是否存在,若为undefined则返回false,否则返回true

用法

// CommonJS
const ObjectUtils = require('@pangju666/js-utils/ObjectUtils')
// ESM
import { ObjectUtils } from '@pangju666/js-utils'

句法

isExistProperty(object: object, expression: string): boolean

参数

| 名称 | 类型 | 描述 | 默认值| | --- | ---- | --- | --- | | object | object | 待检查对象 | 无 | | expression | string | 属性表达式 | '' |

返回

| 类型 | 描述 | | ---- | ---- | | Boolean | 如果对象属性存在则返回true,否则返回false |

异常

| 类型 | 描述 | | ---- | ---- | | TypeError | 参数expression必须为string类型 |

样例代码

const val2 = undefined
ObjectUtils.isExistProperty(val2) // return false

const val1 = null
ObjectUtils.isExistProperty(val1) // return false

const val3 = {}
ObjectUtils.isExistProperty(val3, 'test') // return false

const val4 = {test: ''}
ObjectUtils.isExistProperty(val4), 'test2' // return false

const val4 = {test: ''}
ObjectUtils.isExistProperty(val4, 'test') // return true

const val4 = {test: {val: ''}}
ObjectUtils.isExistProperty(val4, 'test.val') // return true

const val4 = {test: {val: ''}}
ObjectUtils.isExistProperty(val4, 'test.val2') // return false

isNotExistProperty

说明

判断对象属性是否存在,若为undefined则返回false,否则返回true

用法

// CommonJS
const ObjectUtils = require('@pangju666/js-utils/ObjectUtils')
// ESM
import { ObjectUtils } from '@pangju666/js-utils'

句法

isNotExistProperty(object: object, expression: string): boolean

参数

| 名称 | 类型 | 描述 | 默认值| | --- | ---- | --- | --- | | object | object | 待检查对象 | 无 | | expression | string | 属性表达式 | '' |

返回

| 类型 | 描述 | | ---- | ---- | | Boolean | 如果对象属性存在则返回false,否则返回true |

异常

| 类型 | 描述 | | ---- | ---- | | TypeError | 参数expression必须为string类型 |

样例代码

const val2 = undefined
ObjectUtils.isNotExistProperty(val2) // return true

const val1 = null
ObjectUtils.isNotExistProperty(val1) // return true

const val3 = {}
ObjectUtils.isNotExistProperty(val3, 'test') // return true

const val4 = {test: ''}
ObjectUtils.isNotExistProperty(val4), 'test2' // return true

const val4 = {test: ''}
ObjectUtils.isNotExistProperty(val4, 'test') // return false

const val4 = {test: {val: ''}}
ObjectUtils.isNotExistProperty(val4, 'test.val') // return false

const val4 = {test: {val: ''}}
ObjectUtils.isNotExistProperty(val4, 'test.val2') // return true