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

@deriv-com/utils

v0.0.42

Published

A utility library for Deriv web apps.

Downloads

26,253

Readme

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.

Note: Don't forget to update the utils-docs alongside your changes to ensure comprehensive documentation.

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.