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 🙏

© 2026 – Pkg Stats / Ryan Hefner

utils_web3

v1.0.2

Published

自己常用的一些工具方法

Readme

项目名称

该项目是一个 JavaScript 工具库,提供了一些常用的工具函数和方法,包括数组处理、API 请求封装以及 JSON 数据处理等功能。

安装

npm install utils_web3

使用方法

导入模块

import { ArrayUtils, ApiUtils, JsonUtils } from 'utils_web3';

数组工具(ArrayUtils)

合并并去重多个数组

ArrayUtils.mergeAndDistinct(array1, array2, ...);

将数组分割成指定大小的块

ArrayUtils.chunkArray(array, size);

获取数组中的最大值

ArrayUtils.getMaxValue(array);

获取数组中的最小值

ArrayUtils.getMinValue(array);

获取数组中的平均值

ArrayUtils.getAverageValue(array);

获取数组中的中位数

ArrayUtils.getMedianValue(array);

检查数组是否包含指定元素

ArrayUtils.contains(array, element);

数组去重

ArrayUtils.distinct(array);

在数组中查找元素的索引位置

ArrayUtils.findIndex(array, predicate);

移除数组中指定元素

ArrayUtils.remove(array, element);

将数组中的元素按照指定大小分组

ArrayUtils.groupBySize(array, size);

API 请求封装(ApiUtils)

发起 GET 请求

ApiUtils.get(url, config);

发起 POST 请求

ApiUtils.post(url, data, config);

发起 PUT 请求

ApiUtils.put(url, data, config);

发起 DELETE 请求

ApiUtils.delete(url, config);

JSON 数据处理(JsonUtils)

解析 JSON 字符串

JsonUtils.parseJson(jsonString);

序列化 JavaScript 对象为 JSON 字符串

JsonUtils.stringifyJson(object);

使用 json-bigint 库解析 JSON 字符串

JsonUtils.parseJsonWithBigInt(jsonString);

使用 json5 库解析 JSON 字符串

JsonUtils.parseJsonWithJson5(jsonString);

使用 flatted 库序列化 JavaScript 对象为 JSON 字符串

JsonUtils.stringifyJsonWithFlatted(object);

示例

import { ArrayUtils, ApiUtils, JsonUtils } from 'utils_web3';

const mergedArray = ArrayUtils.mergeAndDistinct([1, 2, 3], [3, 4, 5]);
console.log("mergedArray:", mergedArray)

const jsonString = '{"name": "John", "age": 30}';
const parsedData = JsonUtils.parseJson(jsonString);
console.log("parsedData:", parsedData)

// 示例代码...

许可证

MIT