ppipe 2.6.5 → 3.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.
- package/LICENSE +13 -13
- package/README.md +273 -329
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/pipe.d.ts +3 -0
- package/dist/pipe.d.ts.map +1 -0
- package/dist/pipe.js +211 -0
- package/dist/pipe.js.map +1 -0
- package/dist/placeholder.d.ts +4 -0
- package/dist/placeholder.d.ts.map +1 -0
- package/dist/placeholder.js +26 -0
- package/dist/placeholder.js.map +1 -0
- package/dist/types.d.ts +46 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +65 -38
- package/.eslintrc.js +0 -223
- package/.github/CONTRIBUTING.md +0 -13
- package/.github/ISSUE_TEMPLATE.md +0 -17
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -30
- package/.travis.yml +0 -4
- package/CODE_OF_CONDUCT.md +0 -46
- package/logo/logo_s.png +0 -0
- package/prettier.config.js +0 -8
- package/src/getPropertyByPath.js +0 -35
- package/src/index.js +0 -159
- package/src/lib/isFunction.js +0 -1
- package/src/lib/isPromise.js +0 -3
- package/test/examples.js +0 -175
- package/test/test.js +0 -603
package/test/examples.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
let assert = require("chai").assert;
|
|
2
|
-
let ppipe = require("../src/index.js");
|
|
3
|
-
|
|
4
|
-
const add = (x, y) => x + y;
|
|
5
|
-
const square = x => x * x;
|
|
6
|
-
const divide = (x, y) => x / y;
|
|
7
|
-
const double = x => x * 2;
|
|
8
|
-
|
|
9
|
-
let _ = ppipe._;
|
|
10
|
-
|
|
11
|
-
const delay = fn => (...args) =>
|
|
12
|
-
new Promise(resolve => setTimeout(() => resolve(fn.apply(null, args)), 10));
|
|
13
|
-
const someAPICall = delay(x => x);
|
|
14
|
-
|
|
15
|
-
describe("check readme", function() {
|
|
16
|
-
it("first example", function() {
|
|
17
|
-
const res = ppipe(1)(add, 1)(double)(square)(divide, ppipe._, 8)(add, 1)();
|
|
18
|
-
assert.equal(res, add(divide(square(double(add(1, 1))), 8), 1));
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("second example", function() {
|
|
22
|
-
const res = ppipe(1)
|
|
23
|
-
.pipe(add, 1)
|
|
24
|
-
.pipe(double)
|
|
25
|
-
.pipe(square)
|
|
26
|
-
.pipe(divide, _, 8)
|
|
27
|
-
.pipe(add, 1)();
|
|
28
|
-
assert.equal(res, add(divide(square(double(add(1, 1))), 8), 1));
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("third example", async function() {
|
|
32
|
-
async function asyncDouble(x) {
|
|
33
|
-
const result = x * 2;
|
|
34
|
-
await someAPICall(result);
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
const res = await ppipe(1)
|
|
38
|
-
.pipe(add, 1)
|
|
39
|
-
.pipe(asyncDouble)
|
|
40
|
-
.pipe(square)
|
|
41
|
-
.pipe(divide, _, 8)
|
|
42
|
-
.pipe(add, 1);
|
|
43
|
-
assert.equal(res, add(divide(square(double(add(1, 1))), 8), 1));
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("fourth example", async function() {
|
|
47
|
-
async function asyncComplexDouble(x) {
|
|
48
|
-
const result = x * 2;
|
|
49
|
-
const someInfo = await someAPICall(result);
|
|
50
|
-
return {
|
|
51
|
-
result,
|
|
52
|
-
someInfo,
|
|
53
|
-
getResultPlus: y => result + y
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
const res = await ppipe(1)
|
|
57
|
-
.pipe(add, 1)
|
|
58
|
-
.pipe(asyncComplexDouble)
|
|
59
|
-
.pipe(square, _.result)
|
|
60
|
-
.pipe(divide, _, 8)
|
|
61
|
-
.pipe(add, 1);
|
|
62
|
-
assert.equal(res, add(divide(square(double(add(1, 1))), 8), 1));
|
|
63
|
-
const res2 = await ppipe(1)
|
|
64
|
-
.pipe(add, 1)
|
|
65
|
-
.pipe(asyncComplexDouble)
|
|
66
|
-
.result()
|
|
67
|
-
.pipe(asyncComplexDouble)
|
|
68
|
-
.getResultPlus(2)
|
|
69
|
-
.pipe(square)
|
|
70
|
-
.pipe(divide, _, 8)
|
|
71
|
-
.pipe(add, 1)
|
|
72
|
-
.pipe(add, -2.5);
|
|
73
|
-
assert.equal(11, res2);
|
|
74
|
-
assert.equal(res, add(divide(square(double(add(1, 1))), 8), 1));
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("fourth example async result", async function() {
|
|
78
|
-
async function asyncComplexDouble(x) {
|
|
79
|
-
const result = x * 2;
|
|
80
|
-
const someInfo = await someAPICall(result);
|
|
81
|
-
//go wild with deferring
|
|
82
|
-
return Promise.resolve({
|
|
83
|
-
result,
|
|
84
|
-
someInfo,
|
|
85
|
-
//go wilder with deferring
|
|
86
|
-
getResultPlusAsync: y =>
|
|
87
|
-
new Promise(resolve => setTimeout(() => resolve(result + y), 10))
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
const res3 = await ppipe(1)
|
|
91
|
-
.pipe(add, 1)
|
|
92
|
-
.pipe(asyncComplexDouble)
|
|
93
|
-
.result()
|
|
94
|
-
.pipe(asyncComplexDouble)
|
|
95
|
-
.getResultPlusAsync(2)
|
|
96
|
-
.pipe(square)
|
|
97
|
-
.pipe(divide, _, 8)
|
|
98
|
-
.pipe(add, 1)
|
|
99
|
-
.pipe(add, -2.5);
|
|
100
|
-
assert.equal(11, res3);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("fifth example", async function() {
|
|
104
|
-
async function advancedDouble(x) {
|
|
105
|
-
const result = x * 2;
|
|
106
|
-
const someInfo = await someAPICall(result);
|
|
107
|
-
return {
|
|
108
|
-
getResult() {
|
|
109
|
-
return result;
|
|
110
|
-
},
|
|
111
|
-
someInfo
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
const res = await ppipe(1)
|
|
115
|
-
.pipe(add, 1)
|
|
116
|
-
.pipe(advancedDouble)
|
|
117
|
-
.getResult()
|
|
118
|
-
.pipe(square)
|
|
119
|
-
.pipe(divide, _, 8)
|
|
120
|
-
.pipe(add, 1);
|
|
121
|
-
assert.equal(res, add(divide(square(double(add(1, 1))), 8), 1));
|
|
122
|
-
const res2 = await ppipe(1)
|
|
123
|
-
.pipe(add, 1)
|
|
124
|
-
.pipe(x => Promise.resolve(x))
|
|
125
|
-
//.pipe((...params) => (console.log(params), params[0]))
|
|
126
|
-
.pipe(advancedDouble)
|
|
127
|
-
.getResult()
|
|
128
|
-
.toFixed(2)
|
|
129
|
-
.pipe(parseInt)
|
|
130
|
-
.pipe(square)
|
|
131
|
-
.pipe(divide, _, 8)
|
|
132
|
-
.pipe(add, 1);
|
|
133
|
-
assert.equal(res2, 3);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it("sixth example", async function() {
|
|
137
|
-
class Example {
|
|
138
|
-
constructor(myInt) {
|
|
139
|
-
this.foo = Promise.resolve(myInt);
|
|
140
|
-
}
|
|
141
|
-
addToFoo(x) {
|
|
142
|
-
return this.foo.then(foo => foo + x);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
const res = await ppipe(10)
|
|
146
|
-
.with(new Example(5))
|
|
147
|
-
.addToFoo(_);
|
|
148
|
-
assert.equal(res, 15);
|
|
149
|
-
const res2 = await ppipe(10)
|
|
150
|
-
.with(new Example(5))
|
|
151
|
-
.addToFoo();
|
|
152
|
-
assert.equal(res2, 15);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("seventh example", async function() {
|
|
156
|
-
let logged = false;
|
|
157
|
-
const newPipe = ppipe.extend({
|
|
158
|
-
divide(x, y) {
|
|
159
|
-
return x / y;
|
|
160
|
-
},
|
|
161
|
-
log(...params) {
|
|
162
|
-
logged = true;
|
|
163
|
-
assert.equal(params[params.length - 1], 1);
|
|
164
|
-
return params[params.length - 1];
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
const res = await newPipe(10)
|
|
168
|
-
.pipe(x => x + 1)
|
|
169
|
-
.divide(_, 11)
|
|
170
|
-
.log("here is our x: ")
|
|
171
|
-
.pipe(x => x + 1);
|
|
172
|
-
assert.equal(res, 2);
|
|
173
|
-
assert.equal(logged, true);
|
|
174
|
-
});
|
|
175
|
-
});
|