This repository was archived by the owner on Sep 16, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +26
-6
lines changed
Expand file tree Collapse file tree 3 files changed +26
-6
lines changed Original file line number Diff line number Diff line change 1- /* eslint-disable global-require */
2- if ( typeof document !== "undefined" ) {
1+ /* eslint-disable global-require, no-restricted-globals */
2+ let globalSelf = null
3+
4+ if ( typeof window !== "undefined" ) {
5+ globalSelf = window
6+ } else if ( typeof global !== "undefined" ) {
7+ globalSelf = global
8+ } else if ( typeof self !== "undefined" ) {
9+ globalSelf = self
10+ }
11+
12+ const document = globalSelf && globalSelf . document
13+ const crypto = globalSelf && ( globalSelf . crypto || globalSelf . msCrypto )
14+ const navigator = globalSelf && globalSelf . navigator
15+
16+ if ( document && crypto ) {
317 // web
418 module . exports = require ( "nanoid" )
5- } else if (
6- typeof navigator !== "undefined" &&
7- navigator . product === "ReactNative"
8- ) {
19+ } else if ( navigator && navigator . product === "ReactNative" ) {
920 // react native
1021 module . exports = require ( "nanoid/non-secure" )
1122} else {
Original file line number Diff line number Diff line change 1+ import test from "ava"
2+
3+ const expected = require ( "nanoid/non-secure" )
4+ const imported = require ( "../src/nanoid" )
5+
6+ test ( "should load non-secure nanoid" , ( t ) => {
7+ t . true ( expected === imported )
8+ } )
Original file line number Diff line number Diff line change 11import test from "ava"
22
33global . document = { }
4+ global . crypto = { }
45
56const expected = require ( "nanoid" )
67const imported = require ( "../src/nanoid" )
You can’t perform that action at this time.
0 commit comments