returndotjs 1.0.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.
Files changed (5) hide show
  1. package/README.md +70 -0
  2. package/index.js +12 -0
  3. package/package.json +14 -0
  4. package/safe.js +26 -0
  5. package/t.js +9 -0
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # Return.js
2
+ > Returning, but better.
3
+
4
+ Instead of doing this..
5
+
6
+ ```js
7
+ function add(a, b) {
8
+ return a + b
9
+ }
10
+ ```
11
+
12
+ ...you can now do this!
13
+
14
+ ```js
15
+ require('returndotjs')
16
+
17
+ functions.add = function(a, b) {
18
+ _return(a + b)
19
+ }
20
+ const add = functions.add
21
+ ```
22
+
23
+ Or this:
24
+
25
+ ```js
26
+ const { functions, _return } = require('returndotjs/safe')
27
+
28
+ functions.add = function(a, b) {
29
+ _return(a + b)
30
+ }
31
+ const add = functions.add
32
+ ```
33
+
34
+ And then...
35
+ ```js
36
+ console.log(add(1, 2))
37
+ ```
38
+
39
+ which outputs `3`!
40
+
41
+ ## Important Note
42
+
43
+ Using Return.js will work with the following examples:
44
+ ```js
45
+ require('returndotjs')
46
+
47
+ functions.hi = function () {
48
+ _return("hi")
49
+ }
50
+
51
+ // or
52
+
53
+ functions.hi = () => {
54
+ _return("hi")
55
+ }
56
+
57
+ ```
58
+
59
+ But it won't work like this:
60
+
61
+ ```js
62
+ const hi = functions.hi = () => {
63
+ _return("hi")
64
+ }
65
+
66
+ console.log(hi()) // undefined
67
+
68
+ ```
69
+
70
+ or in any other way than the given examples that work.
package/index.js ADDED
@@ -0,0 +1,12 @@
1
+ const { _return, functions } = require('./safe')
2
+
3
+ var _myGlobal
4
+
5
+ if (typeof global !== 'undefined') {
6
+ _myGlobal = global
7
+ } else {
8
+ _myGlobal = window
9
+ }
10
+
11
+ _myGlobal._return = _return
12
+ _myGlobal.functions = functions
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "returndotjs",
3
+ "version": "1.0.0",
4
+ "description": "Return it.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [
10
+ "return"
11
+ ],
12
+ "author": "tj-commits",
13
+ "license": "MIT"
14
+ }
package/safe.js ADDED
@@ -0,0 +1,26 @@
1
+ let returnValue
2
+ function _return(value) {
3
+ returnValue = value
4
+ }
5
+
6
+ var functions = new Proxy({}, {
7
+ set(target, p, newValue, reciever) {
8
+ target[p] = newValue
9
+ return true
10
+ },
11
+ get(target, p, reciever) {
12
+ if (typeof target[p] === 'function') {
13
+ return function (...args) {
14
+ target[p](...args)
15
+ var result = returnValue
16
+ returnValue = undefined
17
+ return result
18
+ }
19
+ }
20
+ return target[p]
21
+ }
22
+ })
23
+
24
+
25
+ exports._return = _return
26
+ exports.functions = functions
package/t.js ADDED
@@ -0,0 +1,9 @@
1
+ require('./index')
2
+
3
+ functions.hi = function() {
4
+ _return("hi")
5
+ }
6
+
7
+ var hi =functions.hi
8
+
9
+ console.log(hi())