-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
233 lines (182 loc) · 8.25 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
"use strict";
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
function _construct(Parent, args, Class) { if (isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
// Generated by CoffeeScript 2.3.2
(function () {
var Args,
Kiduc,
hasProto,
hasSetProto,
splice = [].splice;
hasProto = !!{}.__proto__;
hasSetProto = !!Object.setPrototypeOf;
Args = function () {
var getKey, getValue;
var Args = function Args(args, kiduc) {
_classCallCheck(this, Args);
this.kiduc = kiduc;
this.keys = function () {
var arg, j, len, results;
results = [];
for (j = 0, len = args.length; j < len; j++) {
arg = args[j];
results.push(getKey(arg));
}
return results;
};
this.values = function () {
var arg, j, len, results;
results = [];
for (j = 0, len = args.length; j < len; j++) {
arg = args[j];
results.push(getValue(arg, kiduc));
}
return results;
};
this.mixin = function (options) {
var data, i, key;
data = function () {
var j, len, ref, results;
ref = this.keys();
results = [];
for (i = j = 0, len = ref.length; j < len; i = ++j) {
key = ref[i];
if (options[key]) {
options[key].key = key;
results.push(options[key]);
} else {
results.push(args[i]);
}
}
return results;
}.call(this);
return new Args(data, kiduc);
};
};
;
getKey = function getKey(arg) {
if (typeof arg === 'string') {
return arg;
} else {
return arg.key;
}
};
getValue = function getValue(arg, kiduc) {
if (typeof arg !== 'string') {
switch (arg.type) {
case 'static':
return arg.value;
case 'dynamic':
return kiduc.run.apply(kiduc, arg.value);
}
}
};
return Args;
}.call(this);
Kiduc = function () {
var $scope;
var Kiduc =
/*#__PURE__*/
function () {
function Kiduc(scope) {
_classCallCheck(this, Kiduc);
this[$scope] = {};
this.scope = scope;
return;
}
_createClass(Kiduc, [{
key: "add",
value: function add(name, args) {
var _ref, _ref2, _splice$call, _splice$call2;
var content, ref;
ref = args, (_ref = ref, _ref2 = _toArray(_ref), args = _ref2.slice(0), _ref), (_splice$call = splice.call(args, -1), _splice$call2 = _slicedToArray(_splice$call, 1), content = _splice$call2[0], _splice$call);
args = new Args(args, this);
return this[$scope][name] = {
args: args,
content: content,
handler: _construct(Function, _toConsumableArray(args.keys()).concat([content]))
};
}
}, {
key: "run",
value: function run(name, scope, options) {
var args, globalScope, item;
item = this[$scope][name];
if (item) {
globalScope = this.scope;
args = item.args.mixin(options).values();
return item.handler.apply({
scope: scope,
global: globalScope
}, args);
}
}
}, {
key: "defaults",
value: function defaults(name) {
var args;
args = this[$scope][name].args;
return args.values();
}
}, {
key: "reset",
value: function reset(scope) {
this[$scope] = {};
return this.scope = scope || this.scope;
}
}, {
key: "clone",
value: function clone(deep) {
var handles, next, scope;
scope = this.scope;
handles = this[$scope];
if (deep) {
next = new Kiduc(_objectSpread({}, scope));
next[$scope] = _objectSpread({}, handles);
} else {
next = new Kiduc(scope);
next[$scope] = handles;
}
return next;
}
}, {
key: "next",
value: function next() {
var scope = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var next;
next = new Kiduc(scope);
if (hasProto) {
next.scope.__proto__ = this.scope;
next[$scope].__proto__ = this[$scope];
} else if (hasSetProto) {
Object.setPrototypeOf(next.scope, this.scope);
Object.setPrototypeOf(next[$scope], [$scope]);
} else {
next = this.clone();
}
return next;
}
}]);
return Kiduc;
}();
;
$scope = Symbol('scope');
return Kiduc;
}.call(this);
module.exports = Kiduc;
}).call(void 0);