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

get-random-values-polypony

v1.0.0

Published

Synchronous randombytes function that works in node, the browser & react-native!

Downloads

462

Readme

get-random-values-polypony

Standard & TypeScript definitions Device Tests

get-random-values-polypony is a thorougly tested, normalizing ponyfill for crypto.getRandomValues with a polyfill option.

  • It is tested to work with react-native(ios, android), expo, node 6+, IE 11, Metro, Firefox, Safari
  • No dependencies.

npm i get-random-values-polypony --save

Usage

You can use it like an other randomBytes function by calling:

const getRandomValues = require('get-random-values-polypony')
const randomUint8Array = getRandomValues(new Uint8Array(16))

Or setup the polyfill like:

require('get-random-values-polypony').polyfill()

crypto.getRandomValues(new Uint8Array(16))

Why?

Normalizing behavior both in ponyfill and polyfill

The polyfill respects (unlike other implementations) that the native crypto.getRandomValues do not support Float32Array, Float64Array, DataView, BigInt64Array or BigUint64Array and behaves likewise on node/react-native. Similarly the crypto.getRandomValues polyfill does not accept a ArrayBuffer that has more than 65536 bytes.

The ponyfill on the other hand will accept all native ArrayBufferView implementations at any size, on all platforms.

Expo support

This library works out-of-the-box with expo - no additional setup needed.

No dependencies

Other react-native implementations use base64 to process the native data in JavaScript, this implementation works around this by using hex encoded data which can be easily processed without a library (also: it uses less data).

Some other implementations use like this a random-seed implementations. Those dependencies are often part of a bigger crypto suite that comes with dependencies and dependencies of dependencies, bloating the package tree while not necessarily improving the safety.

Chrome logic for react-native

To implement it for react-native, this library ported google chrome's random implementation to javascript. The advantage of google's implementation is the small initial random value (64bit) which is easy to supply - even in expo. It should also come with the same level of security as chrome does.

Non-blocking

Other implementations such as react-native-get-random-values use blocking native calls in react-native that may create locks between the native and JS thread. get-random-values-polypony only requires a secure initial seed, like browsers and the rest is executed on the javascript thread.

License

MIT