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

@orochi-network/utilities

v0.2.40

Published

One for all utilities library

Downloads

541

Readme

@orochi-network/utilities

An one for all utilities library, this contain all utilities that need for Smart Contract test, Oracle, Orand.... This package is working for both cjs and esm and It's supposed to work on node and browser. It it isn't working please let us know.

Installation:

yarn add @orochi-network/utilities

FixedFloat: A JavaScript Fixed-Point Number Library

This library provides a FixedFloat class for representing and manipulating fixed-point decimal numbers in JavaScript. Fixed-point numbers offer an alternative to floating-point numbers, ensuring consistent decimal precision for financial calculations and other scenarios where exact decimal representation is crucial.

Features:

  • Represents numbers with a fixed number of decimal places.
  • Supports basic arithmetic operations (addition, subtraction, multiplication, division).
  • Handles decimal point scaling for consistent calculations.
  • Provides methods for formatting numbers in decimal and pretty-printed formats.

Usage:

  1. Import the FixedFloat class:
import { FixedFloat } from '@orochi-network/utilities';
  1. Create FixedFloat instances:
  • From a number or string, .from(): This method is simply tell the FixedFloat to take the given value and convert it for a given decimals. For example FixedFloat.from(12.3456, 2) will be convert to { basedValue: 1234n, decimals:2 }. It's represent for 12.34. Apparently, basedValue = givenValue * 10^decimals.
const fixed1: FixedFloat = FixedFloat.from(12.3456); // Represents 12.3456 in 4 decimal places
const fixed2: FixedFloat = FixedFloat.from('3.14159'); // Represents 3.1415 in 5 decimal places
  • From a IFixedFloat, .fromFixedFloat(): This method create a new instance of FixedFloat from its basedValue and decimals. If decimals < 0, basedValue = basedValue * 10^(|decimals|), otherwise it will take basedValue and decimals as input and created new instance of FixedFloat
const fixed3: FixedFloat = FixedFloat.fromFixedFloat({ basedValue: 123456n, decimals: 4 }); // Represents 12.3456
  1. Perform calculations:
const value: FixedFloat = fixed1.add(fixed2).sub(fixed1);
  1. Format the output:
const decimalString: string = FixedFloat.fromFixedFloat({ basedValue: 1234n, decimals: 2 }).toFixed(); // Output: "12.34"
const prettyString: string = FixedFloat.from(1234.5672).pretty(); // Output: "1,234.5672" (locale-specific formatting)

Example:

import FixedFloat from '@orochi-network/utilities';

const price: FixedFloat = FixedFloat.from(12.99, 2);
const quantity: FixedFloat = FixedFloat.fromFixedFloat({ basedValue: 2n, decimals: 0 });

const total: FixedFloat = price.mul(quantity);

console.log(`Total price: ${total.toFixed(2)}`); // Output: Total price: 25.98

Additional Notes:

  • The decimals parameter during creation defines the number of decimal places for the FixedFloat instance.
  • The toFixed and pretty methods allow for customized decimal formatting.
  • The library performs validation on input values and throws errors for invalid operations like division by zero.

BigInt Scalar Type: A custom scalar type for GraphQL to handle BigInt in data responses.

Usage:

  1. Import the ScalarType class:
import ScalarType from '@orochi-network/utilities';
  1. Add the BigInt scalar in the type definitions of your GraphQL schema:
scalar BigInt
  1. Add the BigInt scalar in the resolvers of your GraphQL schema:
const resolvers = {
  BigInt: ScalarType.BigInt
  // other resolvers
};

Random

Usage: You must init it first since it gonna check the environment and load compatible version

await Random.init();
console.log(Random.bytes(32));
console.log(Random.string(32));
console.log(Random.integer(2, 8));
console.log(Random.bigInteger());