Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@gsp-sys/utils

Package Overview
Dependencies
Maintainers
7
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gsp-sys/utils

通用工具函数库

latest
npmnpm
Version
0.0.7
Version published
Maintainers
7
Created
Source

@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变量工具函数需要在浏览器环境中运行

FAQs

Package last updated on 08 Dec 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts