@deriv-com/utils

中文文档
0.0.59发布于 2026/04/07TypeScriptESM + CJS近 30 天下载 1.5万

A utility library for Deriv web apps.

原始使用文档
文档目录6 节
  1. Overview
  2. Getting Started
  3. Usage Example
  4. Documentation
  5. Contributing
  6. Notes

Deriv Utility Library (@deriv/utils)

npm Coverage Status

Overview

This utility library provides a comprehensive suite of utilities designed to support the development of web applications for Deriv. It encapsulates common functionalities such as handling constants, formatting, sorting, and more, with a focus on enhancing development efficiency and ensuring type safety.

This library is divided into two main namespaces:

  • Constants
    • AppIDConstants: Holds constants related to application IDs for different domains, facilitating domain-based app ID management.
    • CurrencyConstants: Enumerates all currencies supported by Deriv, simplifying currency-related operations.
    • LocalStorageConstants: An exhaustive list of all local storage keys used across Deriv web apps, ensuring consistency in local storage access.
  • Utils
    • FormatUtils: Contains utility functions for string formatting, including number formatting, currency symbol resolution, and more.
    • LocalStorageUtils: Provides a typesafe wrapper around the browser's localStorage functionality, enhancing reliability and ease of use.
    • ObjectUtils: Offers functions for manipulating objects, such as deep merging, cloning, and property extraction.
    • PromiseUtils: Includes utilities for handling promises, such as timeout wrappers and promise chaining helpers.
    • URLUtils: Contains functions for manipulating URLs, including parameter extraction, URL construction, and query string manipulation.
    • WebSocketUtils: Encapsulates utilities specific to the Deriv WebSocket, addressing environment detection, login ID retrieval, and app ID management.
    • CountryUtils: A utility for retrieving and managing the client's country and related data.

Getting Started

To get started simply install deriv utils from the @deriv-com/utils package

npm i --save @deriv-com/utils

or

yarn add @deriv-com/utils

Usage Example

Each of the namespaces listed above are exposed directly from the library root. In this example, we are using the FormatUtils.formatMoney() functionality to format different currencies to their correct decimal points or localised formatting.

import { FormatUtils } from "@deriv-com/utils";

const formattedBalance = FormatUtils.formatMoney(1, { currency: "BTC" });
console.log(formattedBalance); // Should output 1.00000000

Documentation

For detailed documentation on each utility and constant, refer to the specific files in the constants and utils directories. Each utility function and constant is documented with JSDoc comments, providing insights into their purpose, parameters, and return values. (A dedicated document page is in the pipeline)

Contributing

We welcome contributions to the @deriv-com/utils library. If you have suggestions for improvements or find a bug, please open an issue or submit a pull request.

Notes

  • @deriv-com/utils outputs both ESM and CJS files but currently, this library only support code running in the browser environment. However, support for Node runtime is planned in the pipeline.

版本与发布记录

@deriv-com/utils 共发布 58 个版本,首次发布于 2024/02/02;过去 12 个月发布了 7 个版本。

版本发布日期距今
0.0.59latest2026/04/077 个月前
0.0.582026/01/269 个月前
0.0.572025/12/3010 个月前
0.0.562025/12/2210 个月前
0.0.552025/12/2210 个月前
0.0.542025/12/2210 个月前

关于 @deriv-com/utils 的常见问题

@deriv-com/utils 是什么?

A utility library for Deriv web apps.

如何安装 @deriv-com/utils?

在项目目录运行 npm install @deriv-com/utils,或使用 pnpm add / yarn add / bun add。

@deriv-com/utils 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@deriv-com/utils 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@deriv-com/utils 可以商用吗?

@deriv-com/utils 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@deriv-com/utils 的下载量有多少?

根据 npm 官方下载统计,@deriv-com/utils 在 2026/10/12 – 2026/11/10 这 30 天内被下载 15,263 次,日均约 509 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@deriv-com/utils 还在维护吗?

最新版本 0.0.59 发布于 2026/04/07(7 个月前);至今共发布 58 个版本,其中过去 12 个月发布了 7 个;首次发布于 2024/02/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。