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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@gsp-sys/utils

v0.0.7

Published

通用工具函数库

Readme

@gsp-sys/utils

通用工具函数库,为微应用框架提供各种常用工具函数。

目录结构

├── src/
│   ├── auth/         # 认证相关工具函数
│   ├── common/       # 通用工具函数
│   ├── network/      # 网络请求工具
│   ├── storage/      # 存储相关工具
│   ├── theme/        # 主题相关工具
│   └── index.ts      # 导出文件

主要功能模块

认证工具 (auth)

  • getToken() - 获取认证Token
  • setToken(token) - 设置认证Token
  • removeToken() - 移除认证Token

通用工具 (common)

  • dateFormat(fmt, date) - 日期格式化
  • addZero(num) - 数字补零
  • formatDateTime(date) - 时间格式化
  • getPrecision(value) - 获取数值精度
  • numberFormat(value, precision) - 数字精度控制
  • getWeekStartDate(val, firstDayOfWeek) - 获取周起始日期
  • downloadFile(res, fileName) - 文件下载
  • evil(fn) - 安全执行代码字符串
  • getSearchCondValueByName(name) - 获取保存的查询条件

加密工具 (common/crypto)

  • encryption(sourceData) - AES加密
  • decryption(sourceData) - AES解密

网络请求 (network)

  • request(options) - 基础请求函数
  • get(url, params, config) - GET请求
  • post(url, data, config) - POST请求
  • put(url, data, config) - PUT请求
  • del(url, params, config) - DELETE请求

主题工具 (theme)

  • getCssVariableValue(variableName) - 获取CSS变量值
  • setCssVariableValue(variableName, newValue) - 设置CSS变量值
  • setCssVariables(variables) - 批量设置CSS变量
  • getCssVariables(variableNames) - 获取多个CSS变量

使用方法

在项目中导入所需的工具函数:

// 导入单个函数
import { getToken, setToken } from '@gsp-sys/utils';

// 导入请求模块
import { request, get, post } from '@gsp-sys/utils';

// 使用示例
const token = getToken();
setToken('new-token-value');

// 发送请求
const data = await get('/api/data', { id: 1 });

注意事项

  • 所有工具函数都已添加TypeScript类型定义
  • 在使用网络请求函数时,确保已正确配置全局的 window.webConfig.serviceAddress
  • CSS变量工具函数需要在浏览器环境中运行