vue-cryptojs 2.1.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # vue-cryptojs
2
- A small wrapper for integrating crypto-js into VueJS
2
+ A small wrapper for integrating crypto-js into Vue3 and Vue2
3
3
 
4
4
  ## How to install:
5
5
  ```bash
@@ -8,6 +8,15 @@ npm install vue-cryptojs
8
8
 
9
9
  And in your entry file:
10
10
  ```js
11
+ // Vue3
12
+ import { createApp } from 'vue'
13
+ import VueCryptojs from 'vue-cryptojs'
14
+
15
+ const app = createApp(...)
16
+ app.use(VueCryptojs)
17
+ app.mount('#app')
18
+
19
+ // Vue2
11
20
  import Vue from 'vue'
12
21
  import VueCryptojs from 'vue-cryptojs'
13
22
 
@@ -18,15 +27,26 @@ This wrapper bind `CryptoJS` to `Vue` or `this` if you're using single file comp
18
27
 
19
28
  Simple AES text encrypt/decrypt example:
20
29
  ```js
21
- const encryptedText = this.CryptoJS.AES.encrypt("Hi There!", "Secret Passphrase").toString()
22
- const decryptedText = this.CryptoJS.AES.decrypt(encryptedText, "Secret Passphrase").toString(this.CryptoJS.enc.Utf8)
30
+ const encryptedText = this.$CryptoJS.AES.encrypt("Hi There!", "Secret Passphrase").toString()
31
+ const decryptedText = this.$CryptoJS.AES.decrypt(encryptedText, "Secret Passphrase").toString(this.CryptoJS.enc.Utf8)
23
32
  ```
24
33
 
25
- Also `crypto-js` is available as:
34
+ For Vue3 we suggest to use `inject` on Composition API:
26
35
  ```js
27
- Vue.CryptoJS
28
- this.CryptoJS
29
- this.$CryptoJS
36
+ <script>
37
+ import { inject } from 'vue'
38
+
39
+ export default {
40
+ setup() {
41
+ const cryoptojs = inject('cryptojs')
42
+
43
+ return {
44
+ cryoptojs
45
+ }
46
+ }
47
+ }
48
+ </script>
49
+
30
50
  ```
31
51
 
32
52
  Please kindly check full documention of [crypto-js](https://github.com/brix/crypto-js)
@@ -12,19 +12,31 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
12
12
  /* eslint-disable */
13
13
  var VueCryptojs = {
14
14
  install: function install(Vue, options) {
15
- Vue.CryptoJS = _cryptoJs["default"];
16
- Object.defineProperties(Vue.prototype, {
17
- CryptoJS: {
18
- get: function get() {
19
- return _cryptoJs["default"];
20
- }
21
- },
22
- $CryptoJS: {
23
- get: function get() {
24
- return _cryptoJs["default"];
15
+ Vue.CryptoJS = _cryptoJs["default"]; // VueJS 2
16
+
17
+ if (Vue.prototype) {
18
+ Object.defineProperties(Vue.prototype, {
19
+ $CryptoJS: {
20
+ get: function get() {
21
+ return _cryptoJs["default"];
22
+ }
23
+ },
24
+ CryptoJS: {
25
+ get: function get() {
26
+ return _cryptoJs["default"];
27
+ }
25
28
  }
26
- }
27
- });
29
+ });
30
+ } // VueJS 3
31
+
32
+
33
+ if (Vue.config && Vue.config.globalProperties) {
34
+ Vue.config.globalProperties.$CryptoJS = _cryptoJs["default"];
35
+ }
36
+
37
+ if (Vue.provide && typeof Vue.provide === 'function') {
38
+ Vue.provide('cryptojs', _cryptoJs["default"]);
39
+ }
28
40
 
29
41
  if (typeof window !== 'undefined' && window.Vue) {
30
42
  window.Vue.use(VueCryptojs);
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _cryptoJs=_interopRequireDefault(require("crypto-js"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}var VueCryptojs={install:function(e,t){e.CryptoJS=_cryptoJs.default,Object.defineProperties(e.prototype,{CryptoJS:{get:function(){return _cryptoJs.default}},$CryptoJS:{get:function(){return _cryptoJs.default}}}),"undefined"!=typeof window&&window.Vue&&window.Vue.use(VueCryptojs)}},_default=VueCryptojs;exports.default=_default;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _cryptoJs=_interopRequireDefault(require("crypto-js"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}var VueCryptojs={install:function(e,t){e.CryptoJS=_cryptoJs.default,e.prototype&&Object.defineProperties(e.prototype,{$CryptoJS:{get:function(){return _cryptoJs.default}},CryptoJS:{get:function(){return _cryptoJs.default}}}),e.config&&e.config.globalProperties&&(e.config.globalProperties.$CryptoJS=_cryptoJs.default),e.provide&&"function"==typeof e.provide&&e.provide("cryptojs",_cryptoJs.default),"undefined"!=typeof window&&window.Vue&&window.Vue.use(VueCryptojs)}},_default=VueCryptojs;exports.default=_default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-cryptojs",
3
- "version": "2.1.3",
3
+ "version": "2.2.0",
4
4
  "description": "A small wrapper for integrating crypto-js into VueJS",
5
5
  "main": "dist/vue-cryptojs.min.js",
6
6
  "scripts": {
@@ -8,8 +8,11 @@
8
8
  "build": "node_modules/gulp/bin/gulp.js"
9
9
  },
10
10
  "keywords": [
11
- "vue",
11
+ "crypto",
12
12
  "crypto-js",
13
+ "encrypt",
14
+ "vue",
15
+ "vuejs",
13
16
  "wrapper"
14
17
  ],
15
18
  "repository": {
@@ -22,15 +25,15 @@
22
25
  "vue": ">= 2.0.0"
23
26
  },
24
27
  "devDependencies": {
25
- "@babel/core": "^7.3.4",
26
- "@babel/preset-env": "^7.3.4",
27
- "gulp": "^4.0.0",
28
+ "@babel/core": "^7.10.5",
29
+ "@babel/preset-env": "^7.10.4",
30
+ "gulp": "^4.0.2",
28
31
  "gulp-babel": "^8.0.0",
29
32
  "gulp-rename": "^1.2.2",
30
33
  "gulp-uglify": "^3.0.2",
31
- "vue": "^2.6.8"
34
+ "vue": "^2.6.11"
32
35
  },
33
36
  "dependencies": {
34
- "crypto-js": "^3.1"
37
+ "crypto-js": "^4.0.0"
35
38
  }
36
39
  }
package/src/index.mjs CHANGED
@@ -4,10 +4,26 @@ import cryptojs from 'crypto-js'
4
4
  const VueCryptojs = {
5
5
  install (Vue, options) {
6
6
  Vue.CryptoJS = cryptojs
7
- Object.defineProperties(Vue.prototype, {
8
- CryptoJS: { get() { return cryptojs } },
9
- $CryptoJS: { get() { return cryptojs } }
10
- })
7
+
8
+ // VueJS 2
9
+
10
+ if (Vue.prototype) {
11
+ Object.defineProperties(Vue.prototype, {
12
+ $CryptoJS: { get() { return cryptojs } },
13
+ CryptoJS: { get() { return cryptojs } }
14
+ })
15
+ }
16
+
17
+ // VueJS 3
18
+
19
+ if (Vue.config && Vue.config.globalProperties) {
20
+ Vue.config.globalProperties.$CryptoJS = cryptojs
21
+ }
22
+
23
+ if (Vue.provide && typeof Vue.provide === 'function') {
24
+ Vue.provide('cryptojs', cryptojs)
25
+ }
26
+
11
27
  if (typeof window !== 'undefined' && window.Vue) {
12
28
  window.Vue.use(VueCryptojs)
13
29
  }