JSPM

react-native-randombytes-nodeify

0.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q20423F
  • License MIT

randombytes nodeify for react-native, react-native-randombytes wrapper

Package Exports

  • react-native-randombytes-nodeify
  • react-native-randombytes-nodeify/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-native-randombytes-nodeify) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

react-native-randombytes-nodeify

randombytes nodeify for react-native (metro bundler), react-native-randombytes wrapper

randombytes for dependencies on react-native runtime

What is this

// many packages use "randombytes"
var randomBytes = require('randombytes');

// and "react-native-randombytes" package support like this and similar API
import { randomBytes } from 'react-native-randombytes'
// or
var { randomBytes } = require('react-native-randombytes');

// install this package and set your project
// now, you can use randombytes same node syntax
var randomBytes = require('randombytes');

Installation

  1. add package
npm install react-native-randombytes-nodeify react-native-randombytes
yarn add react-native-randombytes-nodeify react-native-randombytes
  1. add a babel plugin
module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    [
      require.resolve('babel-plugin-module-resolver'),
      {
        alias: {
          randombytes: './node_modules/react-native-randombytes-nodeify',
        },
      },
    ],
  ],
};

Usage

var randomBytes = require('randombytes');

// get 4 random bytes
const rand = randomBytes(4)

// asynchronous API
// uses iOS-side SecRandomCopyBytes
randomBytes(4, (err, bytes) => {
  // bytes is a Buffer object(4 random bytes)
  console.log(bytes.toString('hex'))
})

And We can use node packages!