Remove React Native support for nanoid/async
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Andrey Sitnik · committed by Andrey Sitnik · parent 4c7548a · Browse files · 6 files·+29 added−29 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+29 added−29 removed
- other:+29 added−29 removed
Provenance
- Commit
1297779- Tree
ed03de5- Author
Andrey Sitnik <andrey@sitnik.ru>- Committer
Andrey Sitnik <andrey@sitnik.ru>- Parent
4c7548a
6 files changed+29 added−29 removed
deleted:async/random/index.js-17 removed
1234567891011121314151617let crypto = require('crypto')
// `crypto.randomFill()` is a little faster than `crypto.randomBytes()`,// because we can use faster `Buffer.allocUnsafe()`.let random = bytes => new Promise((resolve, reject) => { // `Buffer.allocUnsafe()` faster because it doesn’t clean memory. // We do not need it, since we will fill memory with new bytes anyway. crypto.randomFill(Buffer.allocUnsafe(bytes), (err, buf) => { if (err) { reject(err) } else { resolve(buf) } })})
module.exports = { random }deleted:async/random/index.rn.js-5 removed
12345let expoRandom = require('expo-random')
let random = bytes => expoRandom.getRandomBytesAsync(bytes)
module.exports = { random }modified:async/index.d.ts+14 added
33 unmodified lines34353637383940414243444546474849505133 unmodified lines * }) * ``` */export function nanoid2 (alphabet: string, size?: number): Promise<string>
/** * Return array with random bytes from hardware random generator. * * ```js * random(5).then(bytes => { * bytes //=> [10, 67, 212, 67, 89] * }) * ``` * * @param bytes The size of array. * @returns Promise with random bytes. */export function random (bytes: number): Promise<Uint8Array>modified:async/index.js+15 added-1 removed
11234567891011121314151617181920212245 unmodified lineslet { random } = require('./random')let crypto = require('crypto')
let { urlAlphabet } = require('..')
// `crypto.randomFill()` is a little faster than `crypto.randomBytes()`,// because we can use faster `Buffer.allocUnsafe()`.let random = bytes => new Promise((resolve, reject) => { // `Buffer.allocUnsafe()` faster because it doesn’t clean memory. // We do not need it, since we will fill memory with new bytes anyway. crypto.randomFill(Buffer.allocUnsafe(bytes), (err, buf) => { if (err) { reject(err) } else { resolve(buf) } })})
let nanoid2 = (alphabet, size = 21) => { // We can’t use bytes bigger than the alphabet. To make bytes values closer // to the alphabet, we apply bitmask on them. We look for the closest // `2 ** x - 1` number, which will be bigger than alphabet size. If we have45 unmodified linesmodified:package.json-3 removed
23 unmodified lines24 "./random/index.js": "./random/index.browser.js",25 "./async/format/index.js": "./async/format/index.browser.js",26 "./async/random/index.js": "./async/random/index.browser.js"27 },28- "react-native": {29- "./async/random/index.js": "./async/random/index.rn.js"30- },28 "sideEffects": false,29 "devDependencies": {30 "@logux/eslint-config": "^36.1.1",31 "@logux/sharec-config": "^0.6.2",145 unmodified linesmodified:README.md-3 removed
194 unmodified lines195 import 'react-native-get-random-values'196 import { nanoid } from 'nanoid'197 ```198 199-For `nanoid/async` you need to install [`expo-random`].200-199 [`react-native-get-random-values`]: https://github.com/LinusU/react-native-get-random-values202-[`expo-random`]: https://www.npmjs.com/package/expo-random200 201 202 ### PouchDB and CouchDB203 174 unmodified lines