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

@encointer/util

v0.18.0

Published

Encointer JS utilities

Downloads

488

Readme

@encointer/util

Utilities for Encointer App and Explorer. Contains methods to work with substrate-based Encointer node.

Installation

yarn add @encointer/util

Fixed-point numbers

Package contains parser from fixed-point number representation created with substrate-fixed crate into floating-point Number. Conversion from floating-point to fixed-point also supported. Several bit-length for decimal and fractional parts supported out of the box: 4, 8, 16, 32, 64.

Usage

To decode number with 64 bits of decimal part and 64 bits of fractional part use parseI64F64. To encode number as fixed point with 4 bits for decimal and fractional use functions toI16F16 (returns fixed-point as BigNum) and encodeFloatToI4F4 (returns Uint8Array).

import { parseI32F32, toI16F16 } from '@encointer/util'
import BN from 'bn.js'

/// Got fixed-point encoded number
const balanceFixPoint = new BN('110000000000000000000000000000001', 2)
console.log(balanceFixPoint)          // -> <BN: 180000001>

/// Parse to Number
const balance = parseI32F32(balanceFixPoint)
console.log(balance)                  // -> 1.5000000002328306

/// Convert to smaller word size
const balance32bit = toI16F16(balance)
console.log(balance32bit)             // -> <BN: 18000>
console.log(balance32bit.toString(2)) // -> 11000000000000000

Various bit-length support

Function parserFixPoint used to produce function converting fixed-point to Number. For example to decode decimal 2 bits and fractional 6 bits use this function to create new parser.

Parameters: upper: 0..128 - number of bits in decimal part lower: 0..128 - number of bits in fractional part

Produced function parameters: raw: substrate_fixed::types::IF as I<upper+lower> precision: 0..lower number bits in fractional part to process

const parseI2F6 = parserFixPoint(2, 6);