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

react-native-bignumber

v0.2.3

Published

⚡️ The fastest Big Number library for React Native.

Downloads

946

Readme

🔢 react-native-bignumber

The fastest Big Number library for React Native.

  • 🏎️ Up to 300x faster than all other solutions
  • ⚡️ Lightning fast implementation with pure C++ and JSI
  • 🧪 Well tested in JS and C++ (OpenSSL)
  • 💰 Made for crypto apps and Wallets
  • 🤌 Up to 5x smaller in JS-bundle size
  • 🔢 Store numbers as big as your Phone's RAM can store
  • 🔁 Easy drop-in replacement for BN.js

Installation

yarn add react-native-bignumber
cd ios && pod install
expo install react-native-bignumber
expo prebuild

Usage

..as a normal library

The exposed BN class is used to create new BigNumber instances from strings (binary, hex, decimal), ArrayBuffers, Buffers, numbers, or other BigNumber instances.

import { BN } from 'react-native-bignumber'

const a = new BN(3274556)
const b = new BN(9856712)
const c = a.mul(b) // 32.276.355.419.872

Refer to BN.js' documentation for a full API reference and usage guide.

For example, this is how you calculate large Fibonacci numbers:

function fibonacci(n: number): BN {
  let prev = new BN(0)
  let prevPrev = new BN(1)
  let number = new BN(1)

  for (let i = 1; i < n; i++) {
    prevPrev = prev
    prev = number
    number = prevPrev.add(prev)
  }

  return number
}

const f = fibonacci(50) // 12.586.269.025

..as a drop-in replacement

Since popular libraries like ethers.js or elliptic use BN.js under the hood, react-native-bignumber exposes exactly the same API as BN.js so it can be used as a drop-in replacement and promises much greater speed at common crypto operations.

In your babel.config.js, add a module resolver to replace bn.js with react-native-bignumber:

+const path = require('path');

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
+   [
+     'module-resolver',
+     {
+       alias: {
+         'bn.js': 'react-native-bignumber',
+       },
+     },
+   ],
    ...
  ],
};

Now, all imports for bn.js will be resolved as react-native-bignumber instead.

In the Exodus app, this single line change reduced app launch time by 4 seconds! 🚀

Community Discord

Join the Margelo Community Discord to chat about react-native-bignumber or other Margelo libraries.

Sponsors

This library is supported by Exodus. Send, receive, and exchange Bitcoin and 160+ cryptocurrencies with ease on the world's leading Desktop, Mobile and Hardware crypto wallets: exodus.com

Adopting at scale

react-native-bignumber was built at Margelo, an elite app development agency. For enterprise support or other business inquiries, contact us at [email protected]!