1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
16 |
|
17 | exports.memoize = function (fn, hasher) {
|
18 | return function memoize() {
|
19 | if (_typeof(memoize.cache) !== 'object') {
|
20 | memoize.cache = {};
|
21 | }
|
22 |
|
23 | var args = [];
|
24 |
|
25 | for (var i = 0; i < arguments.length; i++) {
|
26 | args[i] = arguments[i];
|
27 | }
|
28 |
|
29 | var hash = hasher ? hasher(args) : JSON.stringify(args);
|
30 |
|
31 | if (!(hash in memoize.cache)) {
|
32 | memoize.cache[hash] = fn.apply(fn, args);
|
33 | }
|
34 |
|
35 | return memoize.cache[hash];
|
36 | };
|
37 | };
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | exports.maxArgumentCount = function (fn) {
|
47 | return Object.keys(fn.signatures || {}).reduce(function (args, signature) {
|
48 | var count = (signature.match(/,/g) || []).length + 1;
|
49 | return Math.max(args, count);
|
50 | }, -1);
|
51 | };
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | exports.callWithRightArgumentCount = function (fn, args, argCount) {
|
61 | return Object.keys(fn.signatures || {}).reduce(function (args, signature) {
|
62 | var count = (signature.match(/,/g) || []).length + 1;
|
63 | return Math.max(args, count);
|
64 | }, -1);
|
65 | }; |
\ | No newline at end of file |