From 61762a92207e929c4a0672b002ffacb27b747ffb Mon Sep 17 00:00:00 2001 From: evanvosberg Date: Wed, 12 Feb 2020 03:42:23 +0100 Subject: [PATCH 1/2] Use react-native-crypto to support react native environments. --- package.json | 3 +++ src/core.js | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/package.json b/package.json index b7686de..7ac39a2 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,9 @@ "load-grunt-config": "^0.16.0", "lodash": "^4.17.11" }, + "optionalDependencies": { + "react-native-crypto": "^2.2.0" + }, "keywords": [ "security", "crypto", diff --git a/src/core.js b/src/core.js index 8ba28ed..c4e4451 100644 --- a/src/core.js +++ b/src/core.js @@ -29,6 +29,13 @@ var CryptoJS = CryptoJS || (function (Math, undefined) { } catch (err) {} } + // React native crypto import via require (React Native) + if (!crypto && typeof require === 'function') { + try { + crypto = require('react-native-crypto'); + } catch (err) {} + } + /* * Cryptographically secure pseudorandom number generator * From 0601221933d01c81d03f9e670fa70b116854d69c Mon Sep 17 00:00:00 2001 From: evanvosberg Date: Wed, 12 Feb 2020 11:29:33 +0100 Subject: [PATCH 2/2] Keep optional dependencies in build. --- grunt/config/update_json.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/grunt/config/update_json.js b/grunt/config/update_json.js index 46a5656..01382ac 100644 --- a/grunt/config/update_json.js +++ b/grunt/config/update_json.js @@ -19,7 +19,8 @@ module.exports = { 'repository': null, 'keywords': null, 'main': null, - 'dependencies': null + 'dependencies': null, + 'optionalDependencies': null } }, bower: {