@orioro/util 0.0.0 → 0.1.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 +1 -0
- package/babel.config.cjs +13 -0
- package/coverage/clover.xml +488 -45
- package/coverage/coverage-final.json +28 -2
- package/coverage/lcov-report/ValidationError.ts.html +184 -0
- package/coverage/lcov-report/base.css +19 -7
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +248 -58
- package/coverage/lcov-report/prettify.js +1 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +52 -14
- package/coverage/lcov-report/src/debug/deepFreeze.ts.html +157 -0
- package/coverage/lcov-report/src/debug/index.html +146 -0
- package/coverage/lcov-report/src/debug/index.ts.html +91 -0
- package/coverage/lcov-report/src/debug/wait.ts.html +127 -0
- package/coverage/lcov-report/src/index.html +131 -0
- package/coverage/lcov-report/src/interpolate/index.html +116 -0
- package/coverage/lcov-report/src/interpolate/index.ts.html +277 -0
- package/coverage/lcov-report/src/maybeFn.ts.html +94 -0
- package/coverage/lcov-report/src/promise/index.html +146 -0
- package/coverage/lcov-report/src/promise/index.ts.html +91 -0
- package/coverage/lcov-report/src/promise/promiseReduce.ts.html +130 -0
- package/coverage/lcov-report/src/promise/resolveNestedPromises.ts.html +271 -0
- package/coverage/lcov-report/src/switchValue.ts.html +253 -0
- package/coverage/lcov-report/src/typeOf.ts.html +328 -0
- package/coverage/lcov-report/src/validate/ValidationError.ts.html +184 -0
- package/coverage/lcov-report/src/validate/async/index.html +131 -0
- package/coverage/lcov-report/src/validate/async/index.ts.html +241 -0
- package/coverage/lcov-report/src/validate/async/parseValidator.ts.html +136 -0
- package/coverage/lcov-report/src/validate/async/validateAsyncFn.ts.html +208 -0
- package/coverage/lcov-report/src/validate/async/validators/and.ts.html +154 -0
- package/coverage/lcov-report/src/validate/async/validators/index.html +146 -0
- package/coverage/lcov-report/src/validate/async/validators/index.ts.html +91 -0
- package/coverage/lcov-report/src/validate/async/validators/logical.ts.html +253 -0
- package/coverage/lcov-report/src/validate/async/validators/or.ts.html +151 -0
- package/coverage/lcov-report/src/validate/async/validators/shape.ts.html +565 -0
- package/coverage/lcov-report/src/validate/common/ValidationError.ts.html +184 -0
- package/coverage/lcov-report/src/validate/common/index.html +116 -0
- package/coverage/lcov-report/src/validate/common/util/defaultErrorMessage.ts.html +163 -0
- package/coverage/lcov-report/src/validate/common/util/index.html +161 -0
- package/coverage/lcov-report/src/validate/common/util/index.ts.html +94 -0
- package/coverage/lcov-report/src/validate/common/util/parseValidator.ts.html +316 -0
- package/coverage/lcov-report/src/validate/common/util/parseValidatorInput.ts.html +316 -0
- package/coverage/lcov-report/src/validate/common/util/resolveValidationResult.ts.html +277 -0
- package/coverage/lcov-report/src/validate/common/util/validatorParser.ts.html +316 -0
- package/coverage/lcov-report/src/validate/common/validators/index.html +131 -0
- package/coverage/lcov-report/src/validate/common/validators/index.ts.html +88 -0
- package/coverage/lcov-report/src/validate/common/validators/type.ts.html +388 -0
- package/coverage/lcov-report/src/validate/fmtValidationResult.ts.html +268 -0
- package/coverage/lcov-report/src/validate/index.html +116 -0
- package/coverage/lcov-report/src/validate/index.ts.html +94 -0
- package/coverage/lcov-report/src/validate/makeValidate.ts.html +634 -0
- package/coverage/lcov-report/src/validate/specUtil/commonTests.js.html +1324 -0
- package/coverage/lcov-report/src/validate/specUtil/index.html +116 -0
- package/coverage/lcov-report/src/validate/sync/index.html +131 -0
- package/coverage/lcov-report/src/validate/sync/index.ts.html +244 -0
- package/coverage/lcov-report/src/validate/sync/parseValidator.ts.html +136 -0
- package/coverage/lcov-report/src/validate/sync/validateSyncFn.ts.html +223 -0
- package/coverage/lcov-report/src/validate/sync/validators/and.ts.html +148 -0
- package/coverage/lcov-report/src/validate/sync/validators/index.html +146 -0
- package/coverage/lcov-report/src/validate/sync/validators/index.ts.html +91 -0
- package/coverage/lcov-report/src/validate/sync/validators/logical.ts.html +226 -0
- package/coverage/lcov-report/src/validate/sync/validators/or.ts.html +130 -0
- package/coverage/lcov-report/src/validate/sync/validators/shape.ts.html +523 -0
- package/coverage/lcov-report/src/validate/sync/validators/type.ts.html +154 -0
- package/coverage/lcov-report/src/validate/syncValidators/and.ts.html +157 -0
- package/coverage/lcov-report/src/validate/syncValidators/index.html +176 -0
- package/coverage/lcov-report/src/validate/syncValidators/index.ts.html +97 -0
- package/coverage/lcov-report/src/validate/syncValidators/or.ts.html +127 -0
- package/coverage/lcov-report/src/validate/syncValidators/shape.ts.html +559 -0
- package/coverage/lcov-report/src/validate/syncValidators/string.ts.html +163 -0
- package/coverage/lcov-report/src/validate/syncValidators/type.ts.html +154 -0
- package/coverage/lcov-report/src/validate/util/defaultErrorMessage.ts.html +169 -0
- package/coverage/lcov-report/src/validate/util/index.html +146 -0
- package/coverage/lcov-report/src/validate/util/index.ts.html +91 -0
- package/coverage/lcov-report/src/validate/util/resolveValidationResult.ts.html +253 -0
- package/coverage/lcov-report/src/validate/validate.ts.html +220 -0
- package/coverage/lcov-report/src/validate/validateAsync.ts.html +220 -0
- package/coverage/lcov-report/src/validate/validators/and.ts.html +157 -0
- package/coverage/lcov-report/src/validate/validators/index.html +176 -0
- package/coverage/lcov-report/src/validate/validators/index.ts.html +97 -0
- package/coverage/lcov-report/src/validate/validators/or.ts.html +127 -0
- package/coverage/lcov-report/src/validate/validators/shape.ts.html +541 -0
- package/coverage/lcov-report/src/validate/validators/type.ts.html +154 -0
- package/coverage/lcov-report/src/validate_/ValidationError.ts.html +184 -0
- package/coverage/lcov-report/src/validate_/fmtValidationResult.ts.html +268 -0
- package/coverage/lcov-report/src/validate_/index.html +161 -0
- package/coverage/lcov-report/src/validate_/makeValidate.ts.html +634 -0
- package/coverage/lcov-report/src/validate_/validate.ts.html +220 -0
- package/coverage/lcov-report/switchValue.ts.html +253 -0
- package/coverage/lcov-report/typeOf.ts.html +331 -0
- package/coverage/lcov-report/validate.ts.html +757 -0
- package/coverage/lcov.info +1045 -74
- package/dist/index.mjs +1428 -74
- package/jest.config.js +6 -0
- package/package.json +27 -27
- package/rollup.config.mjs +6 -0
- package/src/PromiseLikeEventEmitter/index.ts +35 -0
- package/src/array/arrayChunk.ts +7 -0
- package/src/array/index.ts +1 -0
- package/src/debug/debugFn/index.ts +48 -0
- package/src/debug/debugFn/util.ts +27 -0
- package/src/debug/deepFreeze.ts +26 -0
- package/src/debug/index.ts +3 -0
- package/src/debug/wait.ts +14 -0
- package/src/index.ts +8 -0
- package/src/interpolate/index.spec.ts +20 -0
- package/src/interpolate/index.ts +64 -0
- package/src/maybeFn.ts +3 -0
- package/src/promise/batchFn.spec.ts +92 -0
- package/src/promise/batchFn.ts +176 -0
- package/src/promise/index.ts +3 -0
- package/src/promise/promiseReduce.ts +15 -0
- package/src/promise/resolveNestedPromises.spec.ts +205 -0
- package/src/promise/resolveNestedPromises.ts +83 -0
- package/src/promise/types.ts +2 -0
- package/src/switchValue.spec.ts +30 -0
- package/src/switchValue.ts +59 -0
- package/src/typeOf.spec.ts +47 -0
- package/src/typeOf.ts +81 -0
- package/src/validate/__snapshots__/index.spec.ts.snap +9 -0
- package/src/validate/async/index.spec.ts +236 -0
- package/src/validate/async/index.ts +52 -0
- package/src/validate/async/validateAsyncFn.ts +41 -0
- package/src/validate/async/validators/index.ts +2 -0
- package/src/validate/async/validators/logical.ts +56 -0
- package/src/validate/async/validators/shape.ts +160 -0
- package/src/validate/async/validators/tmpand.ts +24 -0
- package/src/validate/async/validators/tmpor.ts +21 -0
- package/src/validate/common/ValidationError.ts +33 -0
- package/src/validate/common/util/defaultErrorMessage.ts +26 -0
- package/src/validate/common/util/index.ts +3 -0
- package/src/validate/common/util/parseValidatorInput.ts +77 -0
- package/src/validate/common/util/resolveValidationResult.ts +64 -0
- package/src/validate/common/validators/index.ts +1 -0
- package/src/validate/common/validators/type.ts +101 -0
- package/src/validate/index.spec.ts +5 -0
- package/src/validate/index.ts +3 -0
- package/src/validate/specUtil/commonTests.js +413 -0
- package/src/validate/sync/index.spec.ts +81 -0
- package/src/validate/sync/index.ts +53 -0
- package/src/validate/sync/validateSyncFn.ts +46 -0
- package/src/validate/sync/validators/index.ts +2 -0
- package/src/validate/sync/validators/logical.ts +47 -0
- package/src/validate/sync/validators/shape.ts +146 -0
- package/src/validate/types/async.ts +20 -0
- package/src/validate/types/common.ts +70 -0
- package/src/validate/types/index.ts +3 -0
- package/src/validate/types/sync.ts +20 -0
- package/tsconfig.json +11 -0
- package/array/index.js +0 -11
- package/coverage/lcov-report/array/index.html +0 -93
- package/coverage/lcov-report/array/index.js.html +0 -98
- package/coverage/lcov-report/coverage/coverage-final.json.html +0 -95
- package/coverage/lcov-report/coverage/index.html +0 -93
- package/coverage/lcov-report/coverage/lcov-report/index.html +0 -106
- package/coverage/lcov-report/coverage/lcov-report/prettify.js.html +0 -68
- package/coverage/lcov-report/coverage/lcov-report/sorter.js.html +0 -539
- package/coverage/lcov-report/fn/index.html +0 -93
- package/coverage/lcov-report/fn/index.js.html +0 -215
- package/dist/index.js +0 -116
- package/fn/index.js +0 -50
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<title>Code coverage report for fn/index.js</title>
|
|
5
|
-
<meta charset="utf-8" />
|
|
6
|
-
<link rel="stylesheet" href="../prettify.css" />
|
|
7
|
-
<link rel="stylesheet" href="../base.css" />
|
|
8
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
9
|
-
<style type='text/css'>
|
|
10
|
-
.coverage-summary .sorter {
|
|
11
|
-
background-image: url(../sort-arrow-sprite.png);
|
|
12
|
-
}
|
|
13
|
-
</style>
|
|
14
|
-
</head>
|
|
15
|
-
<body>
|
|
16
|
-
<div class='wrapper'>
|
|
17
|
-
<div class='pad1'>
|
|
18
|
-
<h1>
|
|
19
|
-
<a href="../index.html">All files</a> / <a href="index.html">fn</a> index.js
|
|
20
|
-
</h1>
|
|
21
|
-
<div class='clearfix'>
|
|
22
|
-
<div class='fl pad1y space-right2'>
|
|
23
|
-
<span class="strong">100% </span>
|
|
24
|
-
<span class="quiet">Statements</span>
|
|
25
|
-
<span class='fraction'>24/24</span>
|
|
26
|
-
</div>
|
|
27
|
-
<div class='fl pad1y space-right2'>
|
|
28
|
-
<span class="strong">92.86% </span>
|
|
29
|
-
<span class="quiet">Branches</span>
|
|
30
|
-
<span class='fraction'>13/14</span>
|
|
31
|
-
</div>
|
|
32
|
-
<div class='fl pad1y space-right2'>
|
|
33
|
-
<span class="strong">100% </span>
|
|
34
|
-
<span class="quiet">Functions</span>
|
|
35
|
-
<span class='fraction'>9/9</span>
|
|
36
|
-
</div>
|
|
37
|
-
<div class='fl pad1y space-right2'>
|
|
38
|
-
<span class="strong">100% </span>
|
|
39
|
-
<span class="quiet">Lines</span>
|
|
40
|
-
<span class='fraction'>24/24</span>
|
|
41
|
-
</div>
|
|
42
|
-
</div>
|
|
43
|
-
</div>
|
|
44
|
-
<div class='status-line high'></div>
|
|
45
|
-
<pre><table class="coverage">
|
|
46
|
-
<tr><td class="line-count quiet">1
|
|
47
|
-
2
|
|
48
|
-
3
|
|
49
|
-
4
|
|
50
|
-
5
|
|
51
|
-
6
|
|
52
|
-
7
|
|
53
|
-
8
|
|
54
|
-
9
|
|
55
|
-
10
|
|
56
|
-
11
|
|
57
|
-
12
|
|
58
|
-
13
|
|
59
|
-
14
|
|
60
|
-
15
|
|
61
|
-
16
|
|
62
|
-
17
|
|
63
|
-
18
|
|
64
|
-
19
|
|
65
|
-
20
|
|
66
|
-
21
|
|
67
|
-
22
|
|
68
|
-
23
|
|
69
|
-
24
|
|
70
|
-
25
|
|
71
|
-
26
|
|
72
|
-
27
|
|
73
|
-
28
|
|
74
|
-
29
|
|
75
|
-
30
|
|
76
|
-
31
|
|
77
|
-
32
|
|
78
|
-
33
|
|
79
|
-
34
|
|
80
|
-
35
|
|
81
|
-
36
|
|
82
|
-
37
|
|
83
|
-
38
|
|
84
|
-
39
|
|
85
|
-
40
|
|
86
|
-
41
|
|
87
|
-
42
|
|
88
|
-
43
|
|
89
|
-
44
|
|
90
|
-
45
|
|
91
|
-
46
|
|
92
|
-
47
|
|
93
|
-
48
|
|
94
|
-
49
|
|
95
|
-
50
|
|
96
|
-
51</td><td class="line-coverage quiet"><span class="cline-any cline-yes">3x</span>
|
|
97
|
-
<span class="cline-any cline-neutral"> </span>
|
|
98
|
-
<span class="cline-any cline-yes">3x</span>
|
|
99
|
-
<span class="cline-any cline-yes">35x</span>
|
|
100
|
-
<span class="cline-any cline-yes">28x</span>
|
|
101
|
-
<span class="cline-any cline-yes">28x</span>
|
|
102
|
-
<span class="cline-any cline-yes">7x</span>
|
|
103
|
-
<span class="cline-any cline-yes">6x</span>
|
|
104
|
-
<span class="cline-any cline-neutral"> </span>
|
|
105
|
-
<span class="cline-any cline-yes">1x</span>
|
|
106
|
-
<span class="cline-any cline-neutral"> </span>
|
|
107
|
-
<span class="cline-any cline-neutral"> </span>
|
|
108
|
-
<span class="cline-any cline-neutral"> </span>
|
|
109
|
-
<span class="cline-any cline-yes">3x</span>
|
|
110
|
-
<span class="cline-any cline-yes">14x</span>
|
|
111
|
-
<span class="cline-any cline-neutral"> </span>
|
|
112
|
-
<span class="cline-any cline-neutral"> </span>
|
|
113
|
-
<span class="cline-any cline-yes">3x</span>
|
|
114
|
-
<span class="cline-any cline-yes">9x</span>
|
|
115
|
-
<span class="cline-any cline-yes">23x</span>
|
|
116
|
-
<span class="cline-any cline-neutral"> </span>
|
|
117
|
-
<span class="cline-any cline-neutral"> </span>
|
|
118
|
-
<span class="cline-any cline-yes">9x</span>
|
|
119
|
-
<span class="cline-any cline-yes">8x</span>
|
|
120
|
-
<span class="cline-any cline-neutral"> </span>
|
|
121
|
-
<span class="cline-any cline-yes">1x</span>
|
|
122
|
-
<span class="cline-any cline-neutral"> </span>
|
|
123
|
-
<span class="cline-any cline-neutral"> </span>
|
|
124
|
-
<span class="cline-any cline-neutral"> </span>
|
|
125
|
-
<span class="cline-any cline-yes">3x</span>
|
|
126
|
-
<span class="cline-any cline-yes">3x</span>
|
|
127
|
-
<span class="cline-any cline-yes">6x</span>
|
|
128
|
-
<span class="cline-any cline-neutral"> </span>
|
|
129
|
-
<span class="cline-any cline-neutral"> </span>
|
|
130
|
-
<span class="cline-any cline-neutral"> </span>
|
|
131
|
-
<span class="cline-any cline-yes">3x</span>
|
|
132
|
-
<span class="cline-any cline-yes">3x</span>
|
|
133
|
-
<span class="cline-any cline-yes">6x</span>
|
|
134
|
-
<span class="cline-any cline-yes">6x</span>
|
|
135
|
-
<span class="cline-any cline-neutral"> </span>
|
|
136
|
-
<span class="cline-any cline-neutral"> </span>
|
|
137
|
-
<span class="cline-any cline-neutral"> </span>
|
|
138
|
-
<span class="cline-any cline-neutral"> </span>
|
|
139
|
-
<span class="cline-any cline-neutral"> </span>
|
|
140
|
-
<span class="cline-any cline-neutral"> </span>
|
|
141
|
-
<span class="cline-any cline-yes">3x</span>
|
|
142
|
-
<span class="cline-any cline-neutral"> </span>
|
|
143
|
-
<span class="cline-any cline-neutral"> </span>
|
|
144
|
-
<span class="cline-any cline-neutral"> </span>
|
|
145
|
-
<span class="cline-any cline-neutral"> </span>
|
|
146
|
-
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">const mingo = require('mingo')
|
|
147
|
-
|
|
148
|
-
const _test = (criteria, ...args) => {
|
|
149
|
-
if (typeof criteria === 'object') {
|
|
150
|
-
const query = new mingo.Query(criteria)
|
|
151
|
-
return query.test(args[0])
|
|
152
|
-
} else if (typeof criteria === 'function') {
|
|
153
|
-
return criteria(...args)
|
|
154
|
-
} else {
|
|
155
|
-
return criteria
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const _fnApply = (fnSpec, ...args) => {
|
|
160
|
-
return typeof fnSpec === 'function' ? <span class="branch-0 cbranch-no" title="branch not covered" >fnSpec(...args) </span>: fnSpec.fn(...args)
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const applyMatching = (fnSpecList, ...args) => {
|
|
164
|
-
const matching = fnSpecList.find(fnSpec => {
|
|
165
|
-
return _test(fnSpec.criteria, ...args)
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
if (matching) {
|
|
169
|
-
return _fnApply(matching, ...args)
|
|
170
|
-
} else {
|
|
171
|
-
throw new Error('No matching spec')
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const applyMatchingReduce = (fnSpecList, arg, injectArgs = []) => {
|
|
176
|
-
return fnSpecList.reduce((acc, fnSpec) => {
|
|
177
|
-
return _test(fnSpec.criteria, acc) ? _fnApply(fnSpec, acc, ...injectArgs) : acc
|
|
178
|
-
}, arg)
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const applyMatchingReduceAsync = (fnSpecList, arg, injectArgs = []) => {
|
|
182
|
-
return fnSpecList.reduce((previous, fnSpec) => {
|
|
183
|
-
return previous.then(res => {
|
|
184
|
-
return _test(fnSpec.criteria, res) ?
|
|
185
|
-
Promise.resolve(_fnApply(fnSpec, res, ...injectArgs)) :
|
|
186
|
-
Promise.resolve(res)
|
|
187
|
-
})
|
|
188
|
-
}, Promise.resolve(arg))
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
module.exports = {
|
|
192
|
-
applyMatching,
|
|
193
|
-
applyMatchingReduce,
|
|
194
|
-
applyMatchingReduceAsync,
|
|
195
|
-
}
|
|
196
|
-
</pre></td></tr>
|
|
197
|
-
</table></pre>
|
|
198
|
-
<div class='push'></div><!-- for sticky footer -->
|
|
199
|
-
</div><!-- /wrapper -->
|
|
200
|
-
<div class='footer quiet pad2 space-top1 center small'>
|
|
201
|
-
Code coverage
|
|
202
|
-
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Thu Jun 13 2019 20:54:46 GMT-0300 (-03)
|
|
203
|
-
</div>
|
|
204
|
-
</div>
|
|
205
|
-
<script src="../prettify.js"></script>
|
|
206
|
-
<script>
|
|
207
|
-
window.onload = function () {
|
|
208
|
-
if (typeof prettyPrint === 'function') {
|
|
209
|
-
prettyPrint();
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
</script>
|
|
213
|
-
<script src="../sorter.js"></script>
|
|
214
|
-
</body>
|
|
215
|
-
</html>
|
package/dist/index.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
function _typeof(obj) {
|
|
6
|
-
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
|
7
|
-
_typeof = function (obj) {
|
|
8
|
-
return typeof obj;
|
|
9
|
-
};
|
|
10
|
-
} else {
|
|
11
|
-
_typeof = function (obj) {
|
|
12
|
-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return _typeof(obj);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function _toConsumableArray(arr) {
|
|
20
|
-
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function _arrayWithoutHoles(arr) {
|
|
24
|
-
if (Array.isArray(arr)) {
|
|
25
|
-
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
|
|
26
|
-
|
|
27
|
-
return arr2;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function _iterableToArray(iter) {
|
|
32
|
-
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function _nonIterableSpread() {
|
|
36
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance");
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
var mingo = require('mingo');
|
|
40
|
-
|
|
41
|
-
var _test = function _test(criteria) {
|
|
42
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
43
|
-
args[_key - 1] = arguments[_key];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (_typeof(criteria) === 'object') {
|
|
47
|
-
var query = new mingo.Query(criteria);
|
|
48
|
-
return query.test(args[0]);
|
|
49
|
-
} else if (typeof criteria === 'function') {
|
|
50
|
-
return criteria.apply(void 0, args);
|
|
51
|
-
} else {
|
|
52
|
-
return criteria;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
var _fnApply = function _fnApply(fnSpec) {
|
|
57
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
58
|
-
args[_key2 - 1] = arguments[_key2];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return typeof fnSpec === 'function' ? fnSpec.apply(void 0, args) : fnSpec.fn.apply(fnSpec, args);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
var applyMatching = function applyMatching(fnSpecList) {
|
|
65
|
-
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
66
|
-
args[_key3 - 1] = arguments[_key3];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
var matching = fnSpecList.find(function (fnSpec) {
|
|
70
|
-
return _test.apply(void 0, [fnSpec.criteria].concat(args));
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
if (matching) {
|
|
74
|
-
return _fnApply.apply(void 0, [matching].concat(args));
|
|
75
|
-
} else {
|
|
76
|
-
throw new Error('No matching spec');
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
var applyMatchingReduce = function applyMatchingReduce(fnSpecList, arg) {
|
|
81
|
-
var injectArgs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
82
|
-
return fnSpecList.reduce(function (acc, fnSpec) {
|
|
83
|
-
return _test(fnSpec.criteria, acc) ? _fnApply.apply(void 0, [fnSpec, acc].concat(_toConsumableArray(injectArgs))) : acc;
|
|
84
|
-
}, arg);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
var applyMatchingReduceAsync = function applyMatchingReduceAsync(fnSpecList, arg) {
|
|
88
|
-
var injectArgs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
89
|
-
return fnSpecList.reduce(function (previous, fnSpec) {
|
|
90
|
-
return previous.then(function (res) {
|
|
91
|
-
return _test(fnSpec.criteria, res) ? Promise.resolve(_fnApply.apply(void 0, [fnSpec, res].concat(_toConsumableArray(injectArgs)))) : Promise.resolve(res);
|
|
92
|
-
});
|
|
93
|
-
}, Promise.resolve(arg));
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
module.exports = {
|
|
97
|
-
applyMatching: applyMatching,
|
|
98
|
-
applyMatchingReduce: applyMatchingReduce,
|
|
99
|
-
applyMatchingReduceAsync: applyMatchingReduceAsync
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
var arrayReduceAsync = function arrayReduceAsync(arr, fn, initial) {
|
|
103
|
-
return arr.reduce(function (previousPromise, item, index) {
|
|
104
|
-
return previousPromise.then(function (acc) {
|
|
105
|
-
return Promise.resolve(fn(acc, item, index, arr));
|
|
106
|
-
});
|
|
107
|
-
}, Promise.resolve(initial));
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
var array = {
|
|
111
|
-
arrayReduceAsync: arrayReduceAsync
|
|
112
|
-
};
|
|
113
|
-
var array_1 = array.arrayReduceAsync;
|
|
114
|
-
|
|
115
|
-
exports.__moduleExports = array;
|
|
116
|
-
exports.arrayReduceAsync = array_1;
|
package/fn/index.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
const mingo = require('mingo')
|
|
2
|
-
|
|
3
|
-
const _test = (criteria, ...args) => {
|
|
4
|
-
if (typeof criteria === 'object') {
|
|
5
|
-
const query = new mingo.Query(criteria)
|
|
6
|
-
return query.test(args[0])
|
|
7
|
-
} else if (typeof criteria === 'function') {
|
|
8
|
-
return criteria(...args)
|
|
9
|
-
} else {
|
|
10
|
-
return criteria
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const _fnApply = (fnSpec, ...args) => {
|
|
15
|
-
return typeof fnSpec === 'function' ? fnSpec(...args) : fnSpec.fn(...args)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const applyMatching = (fnSpecList, ...args) => {
|
|
19
|
-
const matching = fnSpecList.find(fnSpec => {
|
|
20
|
-
return _test(fnSpec.criteria, ...args)
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
if (matching) {
|
|
24
|
-
return _fnApply(matching, ...args)
|
|
25
|
-
} else {
|
|
26
|
-
throw new Error('No matching spec')
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const applyMatchingReduce = (fnSpecList, arg, injectArgs = []) => {
|
|
31
|
-
return fnSpecList.reduce((acc, fnSpec) => {
|
|
32
|
-
return _test(fnSpec.criteria, acc) ? _fnApply(fnSpec, acc, ...injectArgs) : acc
|
|
33
|
-
}, arg)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const applyMatchingReduceAsync = (fnSpecList, arg, injectArgs = []) => {
|
|
37
|
-
return fnSpecList.reduce((previous, fnSpec) => {
|
|
38
|
-
return previous.then(res => {
|
|
39
|
-
return _test(fnSpec.criteria, res) ?
|
|
40
|
-
Promise.resolve(_fnApply(fnSpec, res, ...injectArgs)) :
|
|
41
|
-
Promise.resolve(res)
|
|
42
|
-
})
|
|
43
|
-
}, Promise.resolve(arg))
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
module.exports = {
|
|
47
|
-
applyMatching,
|
|
48
|
-
applyMatchingReduce,
|
|
49
|
-
applyMatchingReduceAsync,
|
|
50
|
-
}
|