');
152 |
153 | headings.each(function(i, heading) {
154 | var $h = $(heading);
155 |
156 | var anchor = $('
').attr('id', opts.anchorName(i, heading, opts.prefix) + ANCHOR_PREFIX).insertBefore($h);
157 |
158 | var span = $('
')
159 | .text(opts.headerText(i, heading, $h));
160 |
161 | //build TOC item
162 | var a = $('
')
163 | .append(span)
164 | .attr('href', '#' + opts.anchorName(i, heading, opts.prefix))
165 | .bind('click', function(e) {
166 | scrollTo(e);
167 | el.trigger('selected', $(this).attr('href'));
168 | });
169 |
170 | span.addClass(opts.itemClass(i, heading, $h, opts.prefix));
171 |
172 | tocs.push(a);
173 |
174 | ul.append(a);
175 | });
176 | el.html(ul);
177 |
178 | calcHadingOffsets();
179 | });
180 | };
181 |
182 |
183 | jQuery.fn.toc.defaults = {
184 | container: 'body',
185 | selectors: 'h1,h2,h3',
186 | smoothScrolling: true,
187 | prefix: 'toc',
188 | onHighlight: function() {},
189 | highlightOnScroll: true,
190 | navbarOffset: 0,
191 | anchorName: function(i, heading, prefix) {
192 | return prefix+i;
193 | },
194 | headerText: function(i, heading, $heading) {
195 | return $heading.text();
196 | },
197 | itemClass: function(i, heading, $heading, prefix) {
198 | return prefix + '-' + $heading[0].tagName.toLowerCase();
199 | }
200 |
201 | };
202 |
203 | })(jQuery);
204 |
--------------------------------------------------------------------------------
/docs/API.md:
--------------------------------------------------------------------------------
1 | ## Classes
2 |
3 |
4 | MiddlewareManager
5 | Manage middlewares for an object.
6 | Middleware functions are functions that have access to the target function and it's arguments,
7 | and the target object and the next middleware function in the target function cycle.
8 | The next middleware function is commonly denoted by a variable named next.
9 | Middleware functions can perform the following tasks:
10 |
11 | Execute any code.
12 | Make changes to the function's arguments.
13 | End the target function.
14 | Call the next middleware in the stack.
15 |
16 | If the current middleware function does not end the target function cycle,
17 | it must call next() to pass control to the next middleware function. Otherwise,
18 | the target function will be left hanging.
19 | e.g.
20 | const walk = target => next => (...args) => {
21 | this.log(`walk function start.`);
22 | const result = next(...args);
23 | this.log(`walk function end.`);
24 | return result;
25 | }
26 | Middleware object is an object that contains function's name as same as the target object's function name.
27 | e.g.
28 | const Logger = {
29 | walk: target => next => (...args) => {
30 | console.log(`walk function start.`);
31 | const result = next(...args);
32 | console.log(`walk function end.`);
33 | return result;
34 | }
35 | }
36 | Function's name start or end with "_" will not be able to apply middleware.
37 |
38 | MiddlewareManager
39 |
40 |
41 |
42 | ## Functions
43 |
44 |
45 | compose(...funcs) ⇒ function
46 | Composes single-argument functions from right to left. The rightmost
47 | function can take multiple arguments as it provides the signature for
48 | the resulting composite function.
49 |
50 |
51 |
52 |
53 |
54 | ## MiddlewareManager
55 | Manage middlewares for an object.
56 | Middleware functions are functions that have access to the target function and it's arguments,
57 | and the target object and the next middleware function in the target function cycle.
58 | The next middleware function is commonly denoted by a variable named next.
59 |
60 | Middleware functions can perform the following tasks:
61 | - Execute any code.
62 | - Make changes to the function's arguments.
63 | - End the target function.
64 | - Call the next middleware in the stack.
65 |
66 | If the current middleware function does not end the target function cycle,
67 | it must call next() to pass control to the next middleware function. Otherwise,
68 | the target function will be left hanging.
69 |
70 | e.g.
71 | ```
72 | const walk = target => next => (...args) => {
73 | this.log(`walk function start.`);
74 | const result = next(...args);
75 | this.log(`walk function end.`);
76 | return result;
77 | }
78 | ```
79 |
80 | Middleware object is an object that contains function's name as same as the target object's function name.
81 |
82 | e.g.
83 | ```
84 | const Logger = {
85 | walk: target => next => (...args) => {
86 | console.log(`walk function start.`);
87 | const result = next(...args);
88 | console.log(`walk function end.`);
89 | return result;
90 | }
91 | }
92 | ```
93 |
94 | Function's name start or end with "_" will not be able to apply middleware.
95 |
96 | **Kind**: global class
97 |
98 | * [MiddlewareManager](#MiddlewareManager)
99 | * [new MiddlewareManager(target, ...middlewareObjects)](#new_MiddlewareManager_new)
100 | * [.use(methodName, ...middlewares)](#MiddlewareManager+use) ⇒
object
101 |
102 |
103 |
104 | ### new MiddlewareManager(target, ...middlewareObjects)
105 | **Returns**:
object - this
106 |
107 | | Param | Type | Description |
108 | | --- | --- | --- |
109 | | target |
object | The target object. |
110 | | ...middlewareObjects |
object | Middleware objects. |
111 |
112 |
113 |
114 | ### middlewareManager.use(methodName, ...middlewares) ⇒
object
115 | Apply (register) middleware functions to the target function or apply (register) middleware objects.
116 | If the first argument is a middleware object, the rest arguments must be middleware objects.
117 |
118 | **Kind**: instance method of
[MiddlewareManager](#MiddlewareManager)
119 | **Returns**:
object - this
120 |
121 | | Param | Type | Description |
122 | | --- | --- | --- |
123 | | methodName |
string |
object | String for target function name, object for a middleware object. |
124 | | ...middlewares |
function |
object | The middleware chain to be applied. |
125 |
126 |
127 |
128 | ## MiddlewareManager
129 | **Kind**: global class
130 |
131 | * [MiddlewareManager](#MiddlewareManager)
132 | * [new MiddlewareManager(target, ...middlewareObjects)](#new_MiddlewareManager_new)
133 | * [.use(methodName, ...middlewares)](#MiddlewareManager+use) ⇒
object
134 |
135 |
136 |
137 | ### new MiddlewareManager(target, ...middlewareObjects)
138 | **Returns**:
object - this
139 |
140 | | Param | Type | Description |
141 | | --- | --- | --- |
142 | | target |
object | The target object. |
143 | | ...middlewareObjects |
object | Middleware objects. |
144 |
145 |
146 |
147 | ### middlewareManager.use(methodName, ...middlewares) ⇒
object
148 | Apply (register) middleware functions to the target function or apply (register) middleware objects.
149 | If the first argument is a middleware object, the rest arguments must be middleware objects.
150 |
151 | **Kind**: instance method of
[MiddlewareManager](#MiddlewareManager)
152 | **Returns**:
object - this
153 |
154 | | Param | Type | Description |
155 | | --- | --- | --- |
156 | | methodName |
string |
object | String for target function name, object for a middleware object. |
157 | | ...middlewares |
function |
object | The middleware chain to be applied. |
158 |
159 |
160 |
161 | ## compose(...funcs) ⇒
function
162 | Composes single-argument functions from right to left. The rightmost
163 | function can take multiple arguments as it provides the signature for
164 | the resulting composite function.
165 |
166 | **Kind**: global function
167 | **Returns**:
function - A function obtained by composing the argument functions
168 | from right to left. For example, compose(f, g, h) is identical to doing
169 | (...args) => f(g(h(...args))).
170 |
171 | | Param | Type | Description |
172 | | --- | --- | --- |
173 | | ...funcs |
function | The functions to compose. |
174 |
175 |
--------------------------------------------------------------------------------
/docs/html/classes.list.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
js-middleware Classes
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
30 |
31 |
32 |
33 |
34 | Classes
35 |
38 |
39 |
40 |
41 | Global
42 |
45 |
46 |
47 |
48 |
49 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
Classes
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 | Classes
143 |
144 |
145 | MiddlewareManager
146 |
147 |
148 | MiddlewareManager
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 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
200 |
201 |
202 |
203 |
204 |
205 |
206 | Documentation generated by JSDoc 3.4.3
207 |
208 | on 2017-06-21
209 |
210 | using the DocStrap template .
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
296 |
297 |
298 |
299 |
--------------------------------------------------------------------------------
/lib/Middleware.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | let middlewareManagerHash = [];
3 |
4 | /**
5 | * Composes single-argument functions from right to left. The rightmost
6 | * function can take multiple arguments as it provides the signature for
7 | * the resulting composite function.
8 | *
9 | * @param {...Function} funcs The functions to compose.
10 | * @returns {Function} A function obtained by composing the argument functions
11 | * from right to left. For example, compose(f, g, h) is identical to doing
12 | * (...args) => f(g(h(...args))).
13 | */
14 | export function compose(...funcs) {
15 | if (funcs.length === 0) {
16 | return arg => arg;
17 | }
18 |
19 | funcs = funcs.filter(func => typeof func === 'function');
20 |
21 | if (funcs.length === 1) {
22 | return funcs[0];
23 | }
24 |
25 | const last = funcs[funcs.length - 1];
26 | const rest = funcs.slice(0, -1);
27 | return (...args) => rest.reduceRight((composed, f) => f(composed), last(...args));
28 | }
29 |
30 | /**
31 | * Manage middlewares for an object.
32 | * Middleware functions are functions that have access to the target function and it's arguments,
33 | * and the target object and the next middleware function in the target function cycle.
34 | * The next middleware function is commonly denoted by a variable named next.
35 | *
36 | * Middleware functions can perform the following tasks:
37 | * - Execute any code.
38 | * - Make changes to the function's arguments.
39 | * - End the target function.
40 | * - Call the next middleware in the stack.
41 | *
42 | * If the current middleware function does not end the target function cycle,
43 | * it must call next() to pass control to the next middleware function. Otherwise,
44 | * the target function will be left hanging.
45 | *
46 | * e.g.
47 | * ```
48 | * const walk = target => next => (...args) => {
49 | * this.log(`walk function start.`);
50 | * const result = next(...args);
51 | * this.log(`walk function end.`);
52 | * return result;
53 | * }
54 | * ```
55 | *
56 | * Middleware object is an object that contains function's name as same as the target object's function name.
57 | *
58 | * e.g.
59 | * ```
60 | * const Logger = {
61 | * walk: target => next => (...args) => {
62 | * console.log(`walk function start.`);
63 | * const result = next(...args);
64 | * console.log(`walk function end.`);
65 | * return result;
66 | * }
67 | * }
68 | * ```
69 | *
70 | * Function's name start or end with "_" will not be able to apply middleware.
71 | *
72 | * @example
73 | *
74 | * ## Basic
75 | *
76 | * We define a Person class.
77 | * // the target object
78 | * class Person {
79 | * // the target function
80 | * walk(step) {
81 | * this.step = step;
82 | * }
83 | *
84 | * speak(word) {
85 | * this.word = word;
86 | * }
87 | * }
88 | *
89 | * Then we define a middleware function to print log.
90 | *
91 | * // middleware for walk function
92 | * const logger = target => next => (...args) => {
93 | * console.log(`walk start, steps: ${args[0]}.`);
94 | * const result = next(...args);
95 | * console.log(`walk end.`);
96 | * return result;
97 | * }
98 | *
99 | * Now we apply the log function as a middleware to a Person instance.
100 | *
101 | * // apply middleware to target object
102 | * const p = new Person();
103 | * const middlewareManager = new MiddlewareManager(p);
104 | * middlewareManager.use('walk', logger);
105 | * p.walk(3);
106 | *
107 | * Whenever a Person instance call it's walk method, we'll see logs from the looger middleware.
108 | *
109 | * ## Middleware object
110 | * We can also apply a middleware object to a target object.
111 | * Middleware object is an object that contains function's name as same as the target object's function name.
112 | *
113 | * const PersonMiddleware = {
114 | * walk: target => next => step => {
115 | * console.log(`walk start, steps: step.`);
116 | * const result = next(step);
117 | * console.log(`walk end.`);
118 | * return result;
119 | * },
120 | * speak: target => next => word => {
121 | * word = 'this is a middleware trying to say: ' + word;
122 | * return next(word);
123 | * }
124 | * }
125 | *
126 | * // apply middleware to target object
127 | * const p = new Person();
128 | * const middlewareManager = new MiddlewareManager(p);
129 | * middlewareManager.use(PersonMiddleware);
130 | * p.walk(3);
131 | * p.speak('hi');
132 | *
133 | * ## middlewareMethods
134 | * In a class, function's name start or end with "_" will not be able to apply as middleware.
135 | * Or we can use `middlewareMethods` to define function names for middleware target within a class.
136 | *
137 | * class PersonMiddleware {
138 | * constructor() {
139 | * // Or Define function names for middleware target.
140 | * this.middlewareMethods = ['walk', 'speak'];
141 | * }
142 | * // Function's name start or end with "_" will not be able to apply as middleware.
143 | * _getPrefix() {
144 | * return 'Middleware log: ';
145 | * }
146 | * log(text) {
147 | * console.log(this._getPrefix() + text);
148 | * }
149 | * walk(target) {
150 | * return next => step => {
151 | * this.log(`walk start, steps: step.`);
152 | * const result = next(step);
153 | * this.log(`walk end.`);
154 | * return result;
155 | * }
156 | * }
157 | * speak(target) {
158 | * return next => word => {
159 | * this.log('this is a middleware trying to say: ' + word);
160 | * return next(word);
161 | * }
162 | * }
163 | * }
164 | *
165 | * // apply middleware to target object
166 | * const p = new Person();
167 | * const middlewareManager = new MiddlewareManager(p);
168 | * middlewareManager.use(new PersonMiddleware())
169 | * p.walk(3);
170 | * p.speak('hi');
171 | *
172 | */
173 | export class MiddlewareManager {
174 | /**
175 | * @param {object} target The target object.
176 | * @param {...object} middlewareObjects Middleware objects.
177 | * @return {object} this
178 | */
179 | constructor(target, ...middlewareObjects) {
180 | let instance = middlewareManagerHash.find(function (key) {
181 | return key._target === target;
182 | });
183 | // a target can only has one MiddlewareManager instance
184 | if (instance === undefined) {
185 | this._target = target;
186 | this._methods = {};
187 | this._methodMiddlewares = {};
188 | middlewareManagerHash.push(this);
189 | instance = this;
190 | }
191 | instance.use(...middlewareObjects);
192 |
193 | return instance;
194 | }
195 |
196 | // Function's name start or end with "_" will not be able to apply middleware.
197 | _methodIsValid(methodName) {
198 | return !/^_+|_+$|constructor/g.test(methodName);
199 | }
200 |
201 | // Apply middleware to method
202 | _applyToMethod(methodName, ...middlewares) {
203 | if (typeof methodName === 'string' && this._methodIsValid(methodName)) {
204 | let method = this._methods[methodName] || this._target[methodName];
205 | if (typeof method === 'function') {
206 | this._methods[methodName] = method;
207 | if (this._methodMiddlewares[methodName] === undefined) {
208 | this._methodMiddlewares[methodName] = [];
209 | }
210 | middlewares.forEach(middleware =>
211 | typeof middleware === 'function' && this._methodMiddlewares[methodName].push(middleware(this._target))
212 | );
213 | this._target[methodName] = compose(...this._methodMiddlewares[methodName])(method.bind(this._target));
214 | }
215 | }
216 | }
217 |
218 | /**
219 | * Apply (register) middleware functions to the target function or apply (register) middleware objects.
220 | * If the first argument is a middleware object, the rest arguments must be middleware objects.
221 | *
222 | * @param {string|object} methodName String for target function name, object for a middleware object.
223 | * @param {...function|...object} middlewares The middleware chain to be applied.
224 | * @return {object} this
225 | */
226 | use(methodName, ...middlewares) {
227 | if (typeof methodName === 'object') {
228 | Array.prototype.slice.call(arguments).forEach(arg => {
229 | // A middleware object can specify target functions within middlewareMethods (Array).
230 | // e.g. obj.middlewareMethods = ['method1', 'method2'];
231 | // only method1 and method2 will be the target function.
232 | typeof arg === 'object' &&
233 | (arg.middlewareMethods ||
234 | (Object.keys(arg).length ? Object.keys(arg) : Object.getOwnPropertyNames(Object.getPrototypeOf(arg)))
235 | ).forEach(key => {
236 | typeof arg[key] === 'function' && this._methodIsValid(key) && this._applyToMethod(key, arg[key].bind(arg));
237 | });
238 | });
239 | } else {
240 | this._applyToMethod(methodName, ...middlewares);
241 | }
242 |
243 | return this;
244 | }
245 | }
246 |
247 | if (typeof window !== 'undefined') {
248 | window['MiddlewareManager'] = MiddlewareManager;
249 | }
250 |
--------------------------------------------------------------------------------
/docs/html/global.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
js-middleware Global
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
30 |
31 |
32 |
33 |
34 | Classes
35 |
38 |
39 |
40 |
41 | Global
42 |
45 |
46 |
47 |
48 |
49 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
Global
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 | Methods
151 |
152 |
153 |
154 |
155 |
156 | compose(funcs)
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
Composes single-argument functions from right to left. The rightmost
165 | function can take multiple arguments as it provides the signature for
166 | the resulting composite function.
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 | Parameters:
177 |
178 |
179 |
180 |
181 |
182 |
183 | Name
184 |
185 |
186 | Type
187 |
188 |
189 | Argument
190 |
191 |
192 |
193 |
194 | Description
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 | funcs
204 |
205 |
206 |
207 |
208 |
209 | function
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 | <repeatable>
224 |
225 |
226 |
227 |
228 |
229 |
230 | The functions to compose.
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 | Returns:
291 |
292 |
293 |
294 |
A function obtained by composing the argument functions
295 | from right to left. For example, compose(f, g, h) is identical to doing
296 | (...args) => f(g(h(...args))).
297 |
298 |
299 |
300 |
301 |
302 |
303 | Type
304 |
305 |
306 |
307 | function
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
362 |
363 |
364 |
365 |
366 |
367 |
368 | Documentation generated by JSDoc 3.4.3
369 |
370 | on 2017-06-21
371 |
372 | using the DocStrap template .
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
458 |
459 |
460 |
461 |
--------------------------------------------------------------------------------
/docs/html/styles/sunlight.default.css:
--------------------------------------------------------------------------------
1 | /* global styles */
2 | .sunlight-container {
3 | clear: both !important;
4 | position: relative !important;
5 | margin: 10px 0 !important;
6 | }
7 | .sunlight-code-container {
8 | clear: both !important;
9 | position: relative !important;
10 | border: none;
11 | border-color: #969696 !important;
12 | background-color: #FFFFFF !important;
13 | }
14 | .sunlight-highlighted, .sunlight-container, .sunlight-container textarea {
15 | font-family: Consolas, Inconsolata, Monaco, "Courier New" !important;
16 | font-size: 12px !important;
17 | line-height: 15px !important;
18 | }
19 | .sunlight-highlighted, .sunlight-container textarea {
20 | color: #000000 !important;
21 | margin: 0 !important;
22 | }
23 | .sunlight-container textarea {
24 | padding-left: 0 !important;
25 | margin-left: 0 !important;
26 | margin-right: 0 !important;
27 | padding-right: 0 !important;
28 | }
29 | .sunlight-code-container > .sunlight-highlighted {
30 | white-space: pre;
31 | overflow-x: auto;
32 | overflow-y: hidden; /* ie requires this wtf? */
33 | }
34 | .sunlight-highlighted {
35 | z-index: 1;
36 | position: relative;
37 | }
38 | .sunlight-highlighted * {
39 | background: transparent;
40 | }
41 | .sunlight-line-number-margin {
42 | float: left !important;
43 | margin-right: 5px !important;
44 | margin-top: 0 !important;
45 | margin-bottom: 0 !important;
46 | padding: 0 !important;
47 | padding-right: 4px !important;
48 | padding-left: 4px !important;
49 | border-right: 1px solid #CCCCCC !important;
50 | background-color: #EEEEEE !important;
51 | color: #848484 !important;
52 | text-align: right !important;
53 | position: relative;
54 | z-index: 3;
55 | }
56 | .sunlight-highlighted a, .sunlight-line-number-margin a {
57 | border: none !important;
58 | text-decoration: none !important;
59 | font-weight: normal !important;
60 | font-style: normal !important;
61 | padding: 0 !important;
62 | }
63 | .sunlight-line-number-margin a {
64 | color: inherit !important;
65 | }
66 | .sunlight-line-highlight-overlay {
67 | position: absolute;
68 | top: 0;
69 | left: 0;
70 | width: 100%;
71 | z-index: 0;
72 | }
73 | .sunlight-line-highlight-overlay div {
74 | height: 15px;
75 | width: 100%;
76 | }
77 | .sunlight-line-highlight-overlay .sunlight-line-highlight-active {
78 | background-color: #E7FCFA;
79 | }
80 |
81 | /* menu */
82 | .sunlight-menu {
83 | background-color: #FFFFCC;
84 | color: #000000;
85 | }
86 | .sunlight-menu ul {
87 | margin: 0 !important;
88 | padding: 0 !important;
89 | list-style-type: none !important;
90 | }
91 | .sunlight-menu li {
92 | float: right !important;
93 | margin-left: 5px !important;
94 | }
95 | .sunlight-menu a, .sunlight-menu img {
96 | color: #000099 !important;
97 | text-decoration: none !important;
98 | border: none !important;
99 | }
100 |
101 |
102 |
103 |
104 | .sunlight-string,
105 | .sunlight-char,
106 | .sunlight-heredoc,
107 | .sunlight-heredocDeclaration,
108 | .sunlight-nowdoc,
109 | .sunlight-longString,
110 | .sunlight-rawString,
111 | .sunlight-binaryString,
112 | .sunlight-rawLongString,
113 | .sunlight-binaryLongString,
114 | .sunlight-verbatimString,
115 | .sunlight-diff .sunlight-removed {
116 | color: #990000 !important;
117 | }
118 |
119 | .sunlight-ident,
120 | .sunlight-operator,
121 | .sunlight-punctuation,
122 | .sunlight-delimiter,
123 | .sunlight-diff .sunlight-unchanged {
124 | color: #000000 !important;
125 | }
126 |
127 | .sunlight-comment,
128 | .sunlight-xmlDocCommentContent,
129 | .sunlight-nginx .sunlight-ssiCommand,
130 | .sunlight-sln .sunlight-formatDeclaration,
131 | .sunlight-diff .sunlight-added {
132 | color: #009900 !important;
133 | }
134 | .sunlight-number,
135 | .sunlight-guid,
136 | .sunlight-cdata {
137 | color: #CC6600 !important;
138 | }
139 |
140 | .sunlight-named-ident,
141 | .sunlight-constant,
142 | .sunlight-javascript .sunlight-globalVariable,
143 | .sunlight-globalObject,
144 | .sunlight-python .sunlight-attribute,
145 | .sunlight-nginx .sunlight-context,
146 | .sunlight-httpd .sunlight-context,
147 | .sunlight-haskell .sunlight-class,
148 | .sunlight-haskell .sunlight-type,
149 | .sunlight-lisp .sunlight-declarationSpecifier,
150 | .sunlight-erlang .sunlight-userDefinedFunction,
151 | .sunlight-diff .sunlight-header {
152 | color: #2B91AF !important;
153 | }
154 | .sunlight-keyword,
155 | .sunlight-languageConstruct,
156 | .sunlight-css
157 | .sunlight-element,
158 | .sunlight-bash .sunlight-command,
159 | .sunlight-specialOperator,
160 | .sunlight-erlang .sunlight-moduleAttribute,
161 | .sunlight-xml .sunlight-tagName,
162 | .sunlight-xml .sunlight-operator,
163 | .sunlight-diff .sunlight-modified {
164 | color: #0000FF !important;
165 | }
166 | .sunlight-shortOpenTag,
167 | .sunlight-openTag,
168 | .sunlight-closeTag,
169 | .sunlight-xmlOpenTag,
170 | .sunlight-xmlCloseTag,
171 | .sunlight-aspOpenTag,
172 | .sunlight-aspCloseTag,
173 | .sunlight-label,
174 | .sunlight-css .sunlight-importantFlag {
175 | background-color: #FFFF99 !important;
176 | color: #000000 !important;
177 | }
178 | .sunlight-function,
179 | .sunlight-globalFunction,
180 | .sunlight-ruby .sunlight-specialFunction,
181 | .sunlight-objective-c .sunlight-messageDestination,
182 | .sunlight-6502asm .sunlight-illegalOpcode,
183 | .sunlight-powershell .sunlight-switch,
184 | .sunlight-lisp .sunlight-macro,
185 | .sunlight-lisp .sunlight-specialForm,
186 | .sunlight-lisp .sunlight-type,
187 | .sunlight-sln .sunlight-sectionName,
188 | .sunlight-diff .sunlight-rangeInfo {
189 | color: #B069AF !important;
190 | }
191 |
192 | .sunlight-variable,
193 | .sunlight-specialVariable,
194 | .sunlight-environmentVariable,
195 | .sunlight-objective-c .sunlight-messageArgumentName,
196 | .sunlight-lisp .sunlight-globalVariable,
197 | .sunlight-ruby .sunlight-globalVariable,
198 | .sunlight-ruby .sunlight-instanceVariable,
199 | .sunlight-sln .sunlight-operator {
200 | color: #325484 !important;
201 | }
202 | .sunlight-regexLiteral,
203 | .sunlight-lisp .sunlight-operator,
204 | .sunlight-6502asm .sunlight-pseudoOp,
205 | .sunlight-erlang .sunlight-macro {
206 | color: #FF00B2 !important;
207 | }
208 | .sunlight-specialVariable {
209 | font-style: italic !important;
210 | font-weight: bold !important;
211 | }
212 | .sunlight-csharp .sunlight-pragma,
213 | .sunlight-preprocessorDirective,
214 | .sunlight-vb .sunlight-compilerDirective,
215 | .sunlight-diff .sunlight-mergeHeader,
216 | .sunlight-diff .sunlight-noNewLine {
217 | color: #999999 !important;
218 | font-style: italic !important;
219 | }
220 | .sunlight-xmlDocCommentMeta,
221 | .sunlight-java .sunlight-annotation,
222 | .sunlight-scala .sunlight-annotation,
223 | .sunlight-docComment {
224 | color: #808080 !important;
225 | }
226 | .sunlight-quotedIdent,
227 | .sunlight-ruby .sunlight-subshellCommand,
228 | .sunlight-lisp .sunlight-keywordArgument,
229 | .sunlight-haskell .sunlight-infixOperator,
230 | .sunlight-erlang .sunlight-quotedAtom {
231 | color: #999900 !important;
232 | }
233 |
234 |
235 |
236 | /* xml */
237 | .sunlight-xml .sunlight-string {
238 | color: #990099 !important;
239 | }
240 | .sunlight-xml .sunlight-attribute {
241 | color: #FF0000 !important;
242 | }
243 | .sunlight-xml .sunlight-entity {
244 | background-color: #EEEEEE !important;
245 | color: #000000 !important;
246 | border: 1px solid #000000 !important;
247 | }
248 | .sunlight-xml .sunlight-doctype {
249 | color: #2B91AF !important;
250 | }
251 |
252 | /* javascript */
253 | .sunlight-javascript .sunlight-reservedWord {
254 | font-style: italic !important;
255 | }
256 |
257 | /* css */
258 | .sunlight-css .sunlight-microsoftFilterPrefix {
259 | color: #FF00FF !important;
260 | }
261 | .sunlight-css .sunlight-rule {
262 | color: #0099FF !important;
263 | }
264 | .sunlight-css .sunlight-keyword {
265 | color: #4E65B8 !important;
266 | }
267 | .sunlight-css .sunlight-class {
268 | color: #FF0000 !important;
269 | }
270 | .sunlight-css .sunlight-id {
271 | color: #8A8E13 !important;
272 | }
273 | .sunlight-css .sunlight-pseudoClass,
274 | .sunlight-css .sunlight-pseudoElement {
275 | color: #368B87 !important;
276 | }
277 |
278 | /* bash */
279 | .sunlight-bash .sunlight-hashBang {
280 | color: #3D97F5 !important;
281 | }
282 | .sunlight-bash .sunlight-verbatimCommand {
283 | color: #999900 !important;
284 | }
285 | .sunlight-bash .sunlight-variable,
286 | .sunlight-bash .sunlight-specialVariable {
287 | color: #FF0000 !important;
288 | }
289 |
290 | /* python */
291 | .sunlight-python .sunlight-specialMethod {
292 | font-weight: bold !important;
293 | color: #A07DD3;
294 | }
295 |
296 | /* ruby */
297 | .sunlight-ruby .sunlight-symbol {
298 | font-weight: bold !important;
299 | color: #ED7272 !important;
300 | }
301 |
302 | /* brainfuck */
303 | .sunlight-brainfuck {
304 | font-weight: bold !important;
305 | color: #000000 !important;
306 | }
307 | .sunlight-brainfuck .sunlight-increment {
308 | background-color: #FF9900 !important;
309 | }
310 | .sunlight-brainfuck .sunlight-decrement {
311 | background-color: #FF99FF !important;
312 | }
313 | .sunlight-brainfuck .sunlight-incrementPointer {
314 | background-color: #FFFF99 !important;
315 | }
316 | .sunlight-brainfuck .sunlight-decrementPointer {
317 | background-color: #66CCFF !important;
318 | }
319 | .sunlight-brainfuck .sunlight-read {
320 | background-color: #FFFFFF !important;
321 | }
322 | .sunlight-brainfuck .sunlight-write {
323 | background-color: #99FF99 !important;
324 | }
325 | .sunlight-brainfuck .sunlight-openLoop, .sunlight-brainfuck .sunlight-closeLoop {
326 | background-color: #FFFFFF !important;
327 | }
328 |
329 | /* 6502 asm */
330 | .sunlight-6502asm .sunlight-label {
331 | font-weight: bold !important;
332 | color: #000000 !important;
333 | background: none !important;
334 | }
335 |
336 | /* lisp */
337 | .sunlight-lisp .sunlight-macro {
338 | font-style: italic !important;
339 | }
340 |
341 | /* erlang */
342 | .sunlight-erlang .sunlight-atom {
343 | font-weight: bold !important;
344 | }
--------------------------------------------------------------------------------
/docs/html/styles/sunlight.dark.css:
--------------------------------------------------------------------------------
1 | /* global styles */
2 | .sunlight-container {
3 | clear: both !important;
4 | position: relative !important;
5 | margin: 10px 0 !important;
6 | }
7 | .sunlight-code-container {
8 | clear: both !important;
9 | position: relative !important;
10 | border: none;
11 | border-color: #626262 !important;
12 | background-color: #262626 !important;
13 | }
14 | .sunlight-highlighted, .sunlight-container, .sunlight-container textarea {
15 | font-family: Consolas, Inconsolata, Monaco, "Courier New" !important;
16 | font-size: 12px !important;
17 | line-height: 15px !important;
18 | }
19 | .sunlight-highlighted, .sunlight-container textarea {
20 | color: #FFFFFF !important;
21 | margin: 0 !important;
22 | }
23 | .sunlight-container textarea {
24 | padding-left: 0 !important;
25 | margin-left: 0 !important;
26 | margin-right: 0 !important;
27 | padding-right: 0 !important;
28 | }
29 | .sunlight-code-container > .sunlight-highlighted {
30 | white-space: pre;
31 | overflow-x: auto;
32 | overflow-y: hidden; /* ie requires this wtf? */
33 | }
34 | .sunlight-highlighted {
35 | z-index: 1;
36 | position: relative;
37 | }
38 | .sunlight-highlighted * {
39 | background: transparent;
40 | }
41 | .sunlight-line-number-margin {
42 | float: left !important;
43 | margin-right: 5px !important;
44 | margin-top: 0 !important;
45 | margin-bottom: 0 !important;
46 | padding: 0 !important;
47 | padding-right: 4px !important;
48 | padding-left: 4px !important;
49 | border-right: 1px solid #9A9A9A !important;
50 | background-color: #3E3E3E !important;
51 | color: #9A9A9A !important;
52 | text-align: right !important;
53 | position: relative;
54 | z-index: 3;
55 | }
56 | .sunlight-highlighted a, .sunlight-line-number-margin a {
57 | border: none !important;
58 | text-decoration: none !important;
59 | font-style: normal !important;
60 | padding: 0 !important;
61 | }
62 | .sunlight-line-number-margin a {
63 | color: inherit !important;
64 | }
65 | .sunlight-line-highlight-overlay {
66 | position: absolute;
67 | top: 0;
68 | left: 0;
69 | width: 100%;
70 | z-index: 0;
71 | }
72 | .sunlight-line-highlight-overlay div {
73 | height: 15px;
74 | width: 100%;
75 | }
76 | .sunlight-line-highlight-overlay .sunlight-line-highlight-active {
77 | background-color: #4B4B4B;
78 | }
79 |
80 | /* menu */
81 | .sunlight-menu {
82 | background-color: #FFFFCC;
83 | color: #000000;
84 | }
85 | .sunlight-menu ul {
86 | margin: 0 !important;
87 | padding: 0 !important;
88 | list-style-type: none !important;
89 | }
90 | .sunlight-menu li {
91 | float: right !important;
92 | margin-left: 5px !important;
93 | }
94 | .sunlight-menu a, .sunlight-menu img {
95 | color: #000099 !important;
96 | text-decoration: none !important;
97 | border: none !important;
98 | }
99 |
100 |
101 |
102 |
103 | .sunlight-string,
104 | .sunlight-char,
105 | .sunlight-heredoc,
106 | .sunlight-heredocDeclaration,
107 | .sunlight-nowdoc,
108 | .sunlight-longString,
109 | .sunlight-rawString,
110 | .sunlight-binaryString,
111 | .sunlight-verbatimString,
112 | .sunlight-rawLongString,
113 | .sunlight-binaryLongString,
114 | .sunlight-diff .sunlight-added {
115 | color: #55EB54 !important;
116 | }
117 | .sunlight-operator,
118 | .sunlight-punctuation,
119 | .sunlight-delimiter {
120 | color: #B1EDEC !important;
121 | }
122 | .sunlight-ident,
123 | .sunlight-diff .sunlight-unchanged {
124 | color: #E0E0E0 !important;
125 | font-weight: bold !important;
126 | }
127 | .sunlight-comment,
128 | .sunlight-xmlDocCommentContent,
129 | .sunlight-nginx .sunlight-ssiCommand,
130 | .sunlight-sln .sunlight-formatDeclaration,
131 | .sunlight-diff .sunlight-mergeHeader,
132 | .sunlight-diff .sunlight-noNewLine {
133 | color: #787D31 !important;
134 | }
135 | .sunlight-number,
136 | .sunlight-cdata,
137 | .sunlight-guid,
138 | .sunlight-diff .sunlight-modified {
139 | color: #F7BA7E !important;
140 | font-weight: bold !important;
141 | }
142 | .sunlight-named-ident,
143 | .sunlight-xml .sunlight-attribute,
144 | .sunlight-constant,
145 | .sunlight-javascript .sunlight-globalVariable,
146 | .sunlight-globalObject,
147 | .sunlight-css .sunlight-id,
148 | .sunlight-python .sunlight-attribute,
149 | .sunlight-nginx .sunlight-context,
150 | .sunlight-httpd .sunlight-context,
151 | .sunlight-lisp .sunlight-declarationSpecifier,
152 | .sunlight-erlang .sunlight-userDefinedFunction,
153 | .sunlight-diff .sunlight-removed {
154 | color: #FBBDEE !important;
155 | font-weight: bold !important;
156 | }
157 | .sunlight-keyword,
158 | .sunlight-languageConstruct,
159 | .sunlight-specialOperator,
160 | .sunlight-xml .sunlight-tagName,
161 | .sunlight-xml .sunlight-operator,
162 | .sunlight-bash .sunlight-command,
163 | .sunlight-erlang .sunlight-moduleAttribute {
164 | color: #A3CCF7 !important;
165 | font-weight: bold !important;
166 | }
167 | .sunlight-shortOpenTag,
168 | .sunlight-openTag,
169 | .sunlight-closeTag,
170 | .sunlight-xmlOpenTag,
171 | .sunlight-xmlCloseTag,
172 | .sunlight-aspOpenTag,
173 | .sunlight-aspCloseTag,
174 | .sunlight-label,
175 | .sunlight-css .sunlight-importantFlag {
176 | background-color: #7373C1 !important;
177 | }
178 | .sunlight-content {
179 | color: #FFFFFF !important;
180 | font-weight: bold !important;
181 | }
182 | .sunlight-function,
183 | .sunlight-globalFunction,
184 | .sunlight-objective-c .sunlight-messageDestination,
185 | .sunlight-ruby .sunlight-specialFunction,
186 | .sunlight-6502asm .sunlight-illegalOpcode,
187 | .sunlight-powershell .sunlight-switch,
188 | .sunlight-lisp .sunlight-macro,
189 | .sunlight-lisp .sunlight-specialForm,
190 | .sunlight-lisp .sunlight-type,
191 | .sunlight-sln .sunlight-sectionName,
192 | .sunlight-diff .sunlight-header {
193 | color: #C8BBF1 !important;
194 | font-weight: bold !important;
195 | }
196 | .sunlight-variable,
197 | .sunlight-environmentVariable,
198 | .sunlight-specialVariable,
199 | .sunlight-objective-c .sunlight-messageArgumentName,
200 | .sunlight-lisp .sunlight-globalVariable,
201 | .sunlight-ruby .sunlight-globalVariable,
202 | .sunlight-ruby .sunlight-instanceVariable {
203 | color: #F5E5B0 !important;
204 | font-weight: bold !important;
205 | }
206 | .sunlight-regexLiteral,
207 | .sunlight-lisp .sunlight-operator,
208 | .sunlight-6502asm .sunlight-pseudoOp,
209 | .sunlight-erlang .sunlight-macro,
210 | .sunlight-diff .sunlight-rangeInfo {
211 | color: #E0F16A !important;
212 | }
213 | .sunlight-specialVariable {
214 | font-style: italic !important;
215 | font-weight: bold !important;
216 | }
217 | .sunlight-csharp .sunlight-pragma,
218 | .sunlight-preprocessorDirective,
219 | .sunlight-vb .sunlight-compilerDirective {
220 | color: #666363 !important;
221 | font-style: italic !important;
222 | }
223 | .sunlight-xmlDocCommentMeta,
224 | .sunlight-java .sunlight-annotation,
225 | .sunlight-scala .sunlight-annotation,
226 | .sunlight-docComment {
227 | color: #666363 !important;
228 | }
229 | .sunlight-quotedIdent,
230 | .sunlight-ruby .sunlight-subshellCommand,
231 | .sunlight-lisp .sunlight-keywordArgument,
232 | .sunlight-haskell .sunlight-infixOperator,
233 | .sunlight-erlang .sunlight-quotedAtom {
234 | color: #F8CA16 !important;
235 | }
236 |
237 |
238 |
239 |
240 | /* html/xml */
241 | .sunlight-xml .sunlight-tagName,
242 | .sunlight-xml .sunlight-operator,
243 | .sunlight-xml .sunlight-attribute {
244 | font-weight: normal !important;
245 | }
246 | .sunlight-doctype {
247 | color: #DEB9B2 !important;
248 | font-style: italic !important;
249 | }
250 | .sunlight-xml .sunlight-entity {
251 | background-color: #E6E585 !important;
252 | color: #000000 !important;
253 | }
254 |
255 | /* javascript */
256 | .sunlight-javascript .sunlight-reservedWord {
257 | font-style: italic !important;
258 | }
259 |
260 | /* css */
261 | .sunlight-css .sunlight-element {
262 | color: #E9EE97 !important;
263 | }
264 | .sunlight-css .sunlight-microsoftFilterPrefix {
265 | color: #C9FF9F !important;
266 | }
267 | .sunlight-css .sunlight-rule {
268 | color: #0099FF !important;
269 | }
270 | .sunlight-css .sunlight-class {
271 | color: #E78282 !important;
272 | }
273 | .sunlight-css .sunlight-pseudoClass, .sunlight-css .sunlight-pseudoElement {
274 | color: #73D693 !important;
275 | }
276 |
277 | /* bash */
278 | .sunlight-bash .sunlight-hashBang {
279 | color: #FFFF00 !important;
280 | }
281 |
282 | .sunlight-bash .sunlight-verbatimCommand {
283 | color: #BBA4EE !important;
284 | }
285 | .sunlight-bash .sunlight-variable,
286 | .sunlight-bash .sunlight-specialVariable {
287 | color: #ED8585 !important;
288 | }
289 |
290 | /* python */
291 | .sunlight-python .sunlight-specialMethod {
292 | font-weight: bold !important;
293 | color: #B0A3C2;
294 | }
295 |
296 | /* ruby */
297 | .sunlight-ruby .sunlight-symbol {
298 | font-weight: bold !important;
299 | color: #90EEA2 !important;
300 | }
301 |
302 | /* brainfuck */
303 | .sunlight-brainfuck {
304 | font-weight: bold !important;
305 | color: #000000 !important;
306 | }
307 | .sunlight-brainfuck .sunlight-increment {
308 | background-color: #FF9900 !important;
309 | }
310 | .sunlight-brainfuck .sunlight-decrement {
311 | background-color: #FF99FF !important;
312 | }
313 | .sunlight-brainfuck .sunlight-incrementPointer {
314 | background-color: #FFFF99 !important;
315 | }
316 | .sunlight-brainfuck .sunlight-decrementPointer {
317 | background-color: #66CCFF !important;
318 | }
319 | .sunlight-brainfuck .sunlight-read {
320 | background-color: #FFFFFF !important;
321 | }
322 | .sunlight-brainfuck .sunlight-write {
323 | background-color: #99FF99 !important;
324 | }
325 | .sunlight-brainfuck .sunlight-openLoop, .sunlight-brainfuck .sunlight-closeLoop {
326 | background-color: #FFFFFF !important;
327 | }
328 |
329 | /* 6502 asm */
330 | .sunlight-6502asm .sunlight-label {
331 | background: none !important;
332 | color: #FFFFFF !important;
333 | text-decoration: underline !important;
334 | }
335 |
336 | /* lisp */
337 | .sunlight-lisp .sunlight-macro {
338 | font-style: italic !important;
339 | }
340 |
341 | /* erlang */
342 | .sunlight-erlang .sunlight-atom {
343 | color: #FFFFFF !important;
344 | font-weight: bold !important;
345 | }
--------------------------------------------------------------------------------
/docs/html/quicksearch.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
12 |
13 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/docs/html/scripts/prettify/Apache-License-2.0.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/docs/html/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
js-middleware Index
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
30 |
31 |
32 |
33 |
34 | Classes
35 |
38 |
39 |
40 |
41 | Global
42 |
45 |
46 |
47 |
48 |
49 |
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 | js-middleware Powerful Javascript Middleware Pattern implementation, apply middleweares to any object.
97 | A painless solution to make codes as scalable and maintainable as ReduxJS and ExpressJS.
98 | Links
103 | Overview Middleware functions are functions that have access to the target function and it's arguments,
104 | and the target object and the next middleware function in the target function cycle.
105 | The next middleware function is commonly denoted by a variable named next.
106 | Middleware functions can perform the following tasks:
107 |
108 | Execute any code.
109 | Make changes to the function's arguments.
110 | End the target function.
111 | Call the next middleware in the stack.
112 | If the current middleware function does not end the target function cycle,
113 | it must call next() to pass control to the next middleware function. Otherwise,
114 | the target function will be left hanging.
115 |
116 |
117 | Get started
118 | window.MiddlewareManager is available for browsers by include
119 | dist/middleware.min.js file in your HTML.<script src="middleware.min.js"></script>
120 | Or install the packagenpm install --save js-middleware and import it in your filesimport {MiddlewareManager} from 'js-middleware';
121 |
122 | Usages Basic We define a Person class.
123 | // the target object
124 | class Person {
125 | // the target function
126 | walk(step) {
127 | this.step = step;
128 | }
129 |
130 | speak(word) {
131 | this.word = word;
132 | }
133 | }Then we define a middleware function to print log.
134 | // middleware for walk function
135 | const logger = target => next => (...args) => {
136 | console.log(`walk start, steps: ${args[0]}.`);
137 | const result = next(...args);
138 | console.log(`walk end.`);
139 | return result;
140 | }Now we apply the log function as a middleware to a Person instance.
141 | // apply middleware to target object
142 | const p = new Person();
143 | const middlewareManager = new MiddlewareManager(p);
144 | middlewareManager.use('walk', logger);
145 | p.walk(3);Whenever a Person instance call it's walk method, we'll see logs from the looger middleware.
146 | Middleware object We can also apply a middleware object to a target object. Middleware object is an object that contains function's name as same as the target object's function name.
147 | Function's name start or end with "_" will not be able to apply middleware.
148 | const PersonMiddleware = {
149 | walk: target => next => step => {
150 | console.log(`walk start, steps: step.`);
151 | const result = next(step);
152 | console.log(`walk end.`);
153 | return result;
154 | },
155 | speak: target => next => word => {
156 | word = 'this is a middleware trying to say: ' + word;
157 | return next(word);
158 | }
159 | }
160 |
161 | // apply middleware to target object
162 | const p = new Person();
163 | const middlewareManager = new MiddlewareManager(p);
164 | middlewareManager.use(PersonMiddleware);
165 | p.walk(3);
166 | p.speak('hi');middlewareMethods In a class, function's name start or end with "_" will not be able to apply as middleware.
167 | Or we can use middlewareMethods to define function names for middleware target within a class.
168 | class PersonMiddleware {
169 | constructor() {
170 | /**
171 | * Or Define function names for middleweare target.
172 | * @type {Array}
173 | */
174 | this.middlewareMethods = ['walk', 'speak'];
175 | }
176 | // Function's name start or end with "_" will not be able to apply as middleware.
177 | _getPrefix() {
178 | return 'Middleware log: ';
179 | }
180 | log(text) {
181 | console.log('Middleware log: ' + text);
182 | }
183 | walk(target) {
184 | return next => step => {
185 | this.log(`walk start, steps: step.`);
186 | const result = next(step);
187 | this.log(`walk end.`);
188 | return result;
189 | }
190 | }
191 | speak(target) {
192 | return next => word => {
193 | this.log('this is a middleware tring to say: ' + word);
194 | return next(word);
195 | }
196 | }
197 | }
198 |
199 | // apply middleware to target object
200 | const p = new Person();
201 | const middlewareManager = new MiddlewareManager(p);
202 | middlewareManager.use(new PersonMiddleware())
203 | p.walk(3);
204 | p.speak('hi');APIs .use(methodName, ...middlewares) Apply (register) middleware functions to the target function or apply (register) middleware objects.
205 | If the first argument is a middleware object, the rest arguments must be middleware objects.
206 |
207 | {string|object} methodName String for target function name, object for a middleware object.
208 | {...function} middlewares The middleware chain to be applied.
209 | return {object} this
210 |
211 | Build
212 | Run npm install to install requirements.
213 |
214 | Run gulp to builds the library, generates dist/middleware.js as the core script, watches for file changes,
215 | starts a HTTP server for debug.
216 | Usage
217 | gulp [TASK] [OPTIONS...]
218 |
219 | Available tasks
220 | build Builds the library.
221 | clean Cleans files.
222 | clean:dist Cleans dist files.
223 | clean:docs Cleans docs files.
224 | default
225 | docs Builds documentation.
226 | docs:html Builds HTML documentation.
227 | docs:md Builds markdown documentation.
228 | help Display this help text.
229 | lint Lint JS files.
230 | mini Minify the library.
231 | server Starts a HTTP server for debug.
232 | test Run test cases.
233 | watch Watches for changes in files, re-lint, re-build & re-docs.
234 | Run gulp docs to build docs. View markdown docs with docs/API.md, or run gulp server to start a HTTP server
235 | and view HTML docs with localhost:3000/docs/html/ .
236 |
237 | Roadmap & Make contributions
238 | Supports RegExp to match method names, pass the current method name as param to the current middleware.
239 | once(methodName, ...middlewares) Apply middlewares only run once.
240 | Be able to unuse middlewares.
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
279 |
280 |
281 |
282 |
283 |
284 |
285 | Documentation generated by JSDoc 3.4.3
286 |
287 | on 2017-06-21
288 |
289 | using the DocStrap template .
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
375 |
376 |
377 |
378 |
--------------------------------------------------------------------------------
/docs/html/scripts/lunr.min.js:
--------------------------------------------------------------------------------
1 | /**
2 | * lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 0.7.1
3 | * Copyright (C) 2016 Oliver Nightingale
4 | * @license MIT
5 | */
6 | !function(){var t=function(e){var n=new t.Index;return n.pipeline.add(t.trimmer,t.stopWordFilter,t.stemmer),e&&e.call(n,n),n};t.version="0.7.1",t.utils={},t.utils.warn=function(t){return function(e){t.console&&console.warn&&console.warn(e)}}(this),t.utils.asString=function(t){return void 0===t||null===t?"":t.toString()},t.EventEmitter=function(){this.events={}},t.EventEmitter.prototype.addListener=function(){var t=Array.prototype.slice.call(arguments),e=t.pop(),n=t;if("function"!=typeof e)throw new TypeError("last argument must be a function");n.forEach(function(t){this.hasHandler(t)||(this.events[t]=[]),this.events[t].push(e)},this)},t.EventEmitter.prototype.removeListener=function(t,e){if(this.hasHandler(t)){var n=this.events[t].indexOf(e);this.events[t].splice(n,1),this.events[t].length||delete this.events[t]}},t.EventEmitter.prototype.emit=function(t){if(this.hasHandler(t)){var e=Array.prototype.slice.call(arguments,1);this.events[t].forEach(function(t){t.apply(void 0,e)})}},t.EventEmitter.prototype.hasHandler=function(t){return t in this.events},t.tokenizer=function(e){return arguments.length&&null!=e&&void 0!=e?Array.isArray(e)?e.map(function(e){return t.utils.asString(e).toLowerCase()}):e.toString().trim().toLowerCase().split(t.tokenizer.seperator):[]},t.tokenizer.seperator=/[\s\-]+/,t.tokenizer.load=function(t){var e=this.registeredFunctions[t];if(!e)throw new Error("Cannot load un-registered function: "+t);return e},t.tokenizer.label="default",t.tokenizer.registeredFunctions={"default":t.tokenizer},t.tokenizer.registerFunction=function(e,n){n in this.registeredFunctions&&t.utils.warn("Overwriting existing tokenizer: "+n),e.label=n,this.registeredFunctions[n]=e},t.Pipeline=function(){this._stack=[]},t.Pipeline.registeredFunctions={},t.Pipeline.registerFunction=function(e,n){n in this.registeredFunctions&&t.utils.warn("Overwriting existing registered function: "+n),e.label=n,t.Pipeline.registeredFunctions[e.label]=e},t.Pipeline.warnIfFunctionNotRegistered=function(e){var n=e.label&&e.label in this.registeredFunctions;n||t.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",e)},t.Pipeline.load=function(e){var n=new t.Pipeline;return e.forEach(function(e){var i=t.Pipeline.registeredFunctions[e];if(!i)throw new Error("Cannot load un-registered function: "+e);n.add(i)}),n},t.Pipeline.prototype.add=function(){var e=Array.prototype.slice.call(arguments);e.forEach(function(e){t.Pipeline.warnIfFunctionNotRegistered(e),this._stack.push(e)},this)},t.Pipeline.prototype.after=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._stack.indexOf(e);if(-1==i)throw new Error("Cannot find existingFn");i+=1,this._stack.splice(i,0,n)},t.Pipeline.prototype.before=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._stack.indexOf(e);if(-1==i)throw new Error("Cannot find existingFn");this._stack.splice(i,0,n)},t.Pipeline.prototype.remove=function(t){var e=this._stack.indexOf(t);-1!=e&&this._stack.splice(e,1)},t.Pipeline.prototype.run=function(t){for(var e=[],n=t.length,i=this._stack.length,r=0;n>r;r++){for(var o=t[r],s=0;i>s&&(o=this._stack[s](o,r,t),void 0!==o&&""!==o);s++);void 0!==o&&""!==o&&e.push(o)}return e},t.Pipeline.prototype.reset=function(){this._stack=[]},t.Pipeline.prototype.toJSON=function(){return this._stack.map(function(e){return t.Pipeline.warnIfFunctionNotRegistered(e),e.label})},t.Vector=function(){this._magnitude=null,this.list=void 0,this.length=0},t.Vector.Node=function(t,e,n){this.idx=t,this.val=e,this.next=n},t.Vector.prototype.insert=function(e,n){this._magnitude=void 0;var i=this.list;if(!i)return this.list=new t.Vector.Node(e,n,i),this.length++;if(e
n.idx?n=n.next:(i+=e.val*n.val,e=e.next,n=n.next);return i},t.Vector.prototype.similarity=function(t){return this.dot(t)/(this.magnitude()*t.magnitude())},t.SortedSet=function(){this.length=0,this.elements=[]},t.SortedSet.load=function(t){var e=new this;return e.elements=t,e.length=t.length,e},t.SortedSet.prototype.add=function(){var t,e;for(t=0;t1;){if(o===t)return r;t>o&&(e=r),o>t&&(n=r),i=n-e,r=e+Math.floor(i/2),o=this.elements[r]}return o===t?r:-1},t.SortedSet.prototype.locationFor=function(t){for(var e=0,n=this.elements.length,i=n-e,r=e+Math.floor(i/2),o=this.elements[r];i>1;)t>o&&(e=r),o>t&&(n=r),i=n-e,r=e+Math.floor(i/2),o=this.elements[r];return o>t?r:t>o?r+1:void 0},t.SortedSet.prototype.intersect=function(e){for(var n=new t.SortedSet,i=0,r=0,o=this.length,s=e.length,a=this.elements,h=e.elements;;){if(i>o-1||r>s-1)break;a[i]!==h[r]?a[i]h[r]&&r++:(n.add(a[i]),i++,r++)}return n},t.SortedSet.prototype.clone=function(){var e=new t.SortedSet;return e.elements=this.toArray(),e.length=e.elements.length,e},t.SortedSet.prototype.union=function(t){var e,n,i;this.length>=t.length?(e=this,n=t):(e=t,n=this),i=e.clone();for(var r=0,o=n.toArray();rp;p++)c[p]===a&&d++;h+=d/f*l.boost}}this.tokenStore.add(a,{ref:o,tf:h})}n&&this.eventEmitter.emit("add",e,this)},t.Index.prototype.remove=function(t,e){var n=t[this._ref],e=void 0===e?!0:e;if(this.documentStore.has(n)){var i=this.documentStore.get(n);this.documentStore.remove(n),i.forEach(function(t){this.tokenStore.remove(t,n)},this),e&&this.eventEmitter.emit("remove",t,this)}},t.Index.prototype.update=function(t,e){var e=void 0===e?!0:e;this.remove(t,!1),this.add(t,!1),e&&this.eventEmitter.emit("update",t,this)},t.Index.prototype.idf=function(t){var e="@"+t;if(Object.prototype.hasOwnProperty.call(this._idfCache,e))return this._idfCache[e];var n=this.tokenStore.count(t),i=1;return n>0&&(i=1+Math.log(this.documentStore.length/n)),this._idfCache[e]=i},t.Index.prototype.search=function(e){var n=this.pipeline.run(this.tokenizerFn(e)),i=new t.Vector,r=[],o=this._fields.reduce(function(t,e){return t+e.boost},0),s=n.some(function(t){return this.tokenStore.has(t)},this);if(!s)return[];n.forEach(function(e,n,s){var a=1/s.length*this._fields.length*o,h=this,u=this.tokenStore.expand(e).reduce(function(n,r){var o=h.corpusTokens.indexOf(r),s=h.idf(r),u=1,l=new t.SortedSet;if(r!==e){var c=Math.max(3,r.length-e.length);u=1/Math.log(c)}o>-1&&i.insert(o,a*s*u);for(var f=h.tokenStore.get(r),d=Object.keys(f),p=d.length,v=0;p>v;v++)l.add(f[d[v]].ref);return n.union(l)},new t.SortedSet);r.push(u)},this);var a=r.reduce(function(t,e){return t.intersect(e)});return a.map(function(t){return{ref:t,score:i.similarity(this.documentVector(t))}},this).sort(function(t,e){return e.score-t.score})},t.Index.prototype.documentVector=function(e){for(var n=this.documentStore.get(e),i=n.length,r=new t.Vector,o=0;i>o;o++){var s=n.elements[o],a=this.tokenStore.get(s)[e].tf,h=this.idf(s);r.insert(this.corpusTokens.indexOf(s),a*h)}return r},t.Index.prototype.toJSON=function(){return{version:t.version,fields:this._fields,ref:this._ref,tokenizer:this.tokenizerFn.label,documentStore:this.documentStore.toJSON(),tokenStore:this.tokenStore.toJSON(),corpusTokens:this.corpusTokens.toJSON(),pipeline:this.pipeline.toJSON()}},t.Index.prototype.use=function(t){var e=Array.prototype.slice.call(arguments,1);e.unshift(this),t.apply(this,e)},t.Store=function(){this.store={},this.length=0},t.Store.load=function(e){var n=new this;return n.length=e.length,n.store=Object.keys(e.store).reduce(function(n,i){return n[i]=t.SortedSet.load(e.store[i]),n},{}),n},t.Store.prototype.set=function(t,e){this.has(t)||this.length++,this.store[t]=e},t.Store.prototype.get=function(t){return this.store[t]},t.Store.prototype.has=function(t){return t in this.store},t.Store.prototype.remove=function(t){this.has(t)&&(delete this.store[t],this.length--)},t.Store.prototype.toJSON=function(){return{store:this.store,length:this.length}},t.stemmer=function(){var t={ational:"ate",tional:"tion",enci:"ence",anci:"ance",izer:"ize",bli:"ble",alli:"al",entli:"ent",eli:"e",ousli:"ous",ization:"ize",ation:"ate",ator:"ate",alism:"al",iveness:"ive",fulness:"ful",ousness:"ous",aliti:"al",iviti:"ive",biliti:"ble",logi:"log"},e={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""},n="[^aeiou]",i="[aeiouy]",r=n+"[^aeiouy]*",o=i+"[aeiou]*",s="^("+r+")?"+o+r,a="^("+r+")?"+o+r+"("+o+")?$",h="^("+r+")?"+o+r+o+r,u="^("+r+")?"+i,l=new RegExp(s),c=new RegExp(h),f=new RegExp(a),d=new RegExp(u),p=/^(.+?)(ss|i)es$/,v=/^(.+?)([^s])s$/,g=/^(.+?)eed$/,m=/^(.+?)(ed|ing)$/,y=/.$/,S=/(at|bl|iz)$/,w=new RegExp("([^aeiouylsz])\\1$"),k=new RegExp("^"+r+i+"[^aeiouwxy]$"),x=/^(.+?[^aeiou])y$/,b=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,E=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,F=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,_=/^(.+?)(s|t)(ion)$/,z=/^(.+?)e$/,O=/ll$/,P=new RegExp("^"+r+i+"[^aeiouwxy]$"),T=function(n){var i,r,o,s,a,h,u;if(n.length<3)return n;if(o=n.substr(0,1),"y"==o&&(n=o.toUpperCase()+n.substr(1)),s=p,a=v,s.test(n)?n=n.replace(s,"$1$2"):a.test(n)&&(n=n.replace(a,"$1$2")),s=g,a=m,s.test(n)){var T=s.exec(n);s=l,s.test(T[1])&&(s=y,n=n.replace(s,""))}else if(a.test(n)){var T=a.exec(n);i=T[1],a=d,a.test(i)&&(n=i,a=S,h=w,u=k,a.test(n)?n+="e":h.test(n)?(s=y,n=n.replace(s,"")):u.test(n)&&(n+="e"))}if(s=x,s.test(n)){var T=s.exec(n);i=T[1],n=i+"i"}if(s=b,s.test(n)){var T=s.exec(n);i=T[1],r=T[2],s=l,s.test(i)&&(n=i+t[r])}if(s=E,s.test(n)){var T=s.exec(n);i=T[1],r=T[2],s=l,s.test(i)&&(n=i+e[r])}if(s=F,a=_,s.test(n)){var T=s.exec(n);i=T[1],s=c,s.test(i)&&(n=i)}else if(a.test(n)){var T=a.exec(n);i=T[1]+T[2],a=c,a.test(i)&&(n=i)}if(s=z,s.test(n)){var T=s.exec(n);i=T[1],s=c,a=f,h=P,(s.test(i)||a.test(i)&&!h.test(i))&&(n=i)}return s=O,a=c,s.test(n)&&a.test(n)&&(s=y,n=n.replace(s,"")),"y"==o&&(n=o.toLowerCase()+n.substr(1)),n};return T}(),t.Pipeline.registerFunction(t.stemmer,"stemmer"),t.generateStopWordFilter=function(t){var e=t.reduce(function(t,e){return t[e]=e,t},{});return function(t){return t&&e[t]!==t?t:void 0}},t.stopWordFilter=t.generateStopWordFilter(["a","able","about","across","after","all","almost","also","am","among","an","and","any","are","as","at","be","because","been","but","by","can","cannot","could","dear","did","do","does","either","else","ever","every","for","from","get","got","had","has","have","he","her","hers","him","his","how","however","i","if","in","into","is","it","its","just","least","let","like","likely","may","me","might","most","must","my","neither","no","nor","not","of","off","often","on","only","or","other","our","own","rather","said","say","says","she","should","since","so","some","than","that","the","their","them","then","there","these","they","this","tis","to","too","twas","us","wants","was","we","were","what","when","where","which","while","who","whom","why","will","with","would","yet","you","your"]),t.Pipeline.registerFunction(t.stopWordFilter,"stopWordFilter"),t.trimmer=function(t){return t.replace(/^\W+/,"").replace(/\W+$/,"")},t.Pipeline.registerFunction(t.trimmer,"trimmer"),t.TokenStore=function(){this.root={docs:{}},this.length=0},t.TokenStore.load=function(t){var e=new this;return e.root=t.root,e.length=t.length,e},t.TokenStore.prototype.add=function(t,e,n){var n=n||this.root,i=t.charAt(0),r=t.slice(1);return i in n||(n[i]={docs:{}}),0===r.length?(n[i].docs[e.ref]=e,void(this.length+=1)):this.add(r,e,n[i])},t.TokenStore.prototype.has=function(t){if(!t)return!1;for(var e=this.root,n=0;n 122 || (d < 65 || j > 90 || b.push([Math.max(65, j) | 32, Math.min(d, 90) | 32]), d < 97 || j > 122 || b.push([Math.max(97, j) & -33, Math.min(d, 122) & -33]))
29 | }
30 | }
31 | b.sort(function(a, f) {
32 | return a[0] - f[0] || f[1] - a[1]
33 | });
34 | f = [];
35 | j = [NaN, NaN];
36 | for (c = 0; c < b.length; ++c) i = b[c], i[0] <= j[1] + 1 ? j[1] = Math.max(j[1], i[1]) : f.push(j = i);
37 | b = ["["];
38 | o && b.push("^");
39 | b.push.apply(b, a);
40 | for (c = 0; c < f.length; ++c) i = f[c], b.push(e(i[0])), i[1] > i[0] && (i[1] + 1 > i[0] && b.push("-"), b.push(e(i[1])));
41 | b.push("]");
42 | return b.join("")
43 | }
44 |
45 | function y(a) {
46 | for (var f = a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g), b = f.length, d = [], c = 0, i = 0; c < b; ++c) {
47 | var j = f[c];
48 | j === "(" ? ++i : "\\" === j.charAt(0) && (j = +j.substring(1)) && j <= i && (d[j] = -1)
49 | }
50 | for (c = 1; c < d.length; ++c) - 1 === d[c] && (d[c] = ++t);
51 | for (i = c = 0; c < b; ++c) j = f[c], j === "(" ? (++i, d[i] === void 0 && (f[c] = "(?:")) : "\\" === j.charAt(0) && (j = +j.substring(1)) && j <= i && (f[c] = "\\" + d[i]);
52 | for (i = c = 0; c < b; ++c)"^" === f[c] && "^" !== f[c + 1] && (f[c] = "");
53 | if (a.ignoreCase && s) for (c = 0; c < b; ++c) j = f[c], a = j.charAt(0), j.length >= 2 && a === "[" ? f[c] = h(j) : a !== "\\" && (f[c] = j.replace(/[A-Za-z]/g, function(a) {
54 | a = a.charCodeAt(0);
55 | return "[" + String.fromCharCode(a & -33, a | 32) + "]"
56 | }));
57 | return f.join("")
58 | }
59 | for (var t = 0, s = !1, l = !1, p = 0, d = a.length; p < d; ++p) {
60 | var g = a[p];
61 | if (g.ignoreCase) l = !0;
62 | else if (/[a-z]/i.test(g.source.replace(/\\u[\da-f]{4}|\\x[\da-f]{2}|\\[^UXux]/gi, ""))) {
63 | s = !0;
64 | l = !1;
65 | break
66 | }
67 | }
68 | for (var r = {
69 | b: 8,
70 | t: 9,
71 | n: 10,
72 | v: 11,
73 | f: 12,
74 | r: 13
75 | }, n = [], p = 0, d = a.length; p < d; ++p) {
76 | g = a[p];
77 | if (g.global || g.multiline) throw Error("" + g);
78 | n.push("(?:" + y(g) + ")")
79 | }
80 | return RegExp(n.join("|"), l ? "gi" : "g")
81 | }
82 |
83 | function M(a) {
84 | function m(a) {
85 | switch (a.nodeType) {
86 | case 1:
87 | if (e.test(a.className)) break;
88 | for (var g = a.firstChild; g; g = g.nextSibling) m(g);
89 | g = a.nodeName;
90 | if ("BR" === g || "LI" === g) h[s] = "\n", t[s << 1] = y++, t[s++ << 1 | 1] = a;
91 | break;
92 | case 3:
93 | case 4:
94 | g = a.nodeValue, g.length && (g = p ? g.replace(/\r\n?/g, "\n") : g.replace(/[\t\n\r ]+/g, " "), h[s] = g, t[s << 1] = y, y += g.length, t[s++ << 1 | 1] = a)
95 | }
96 | }
97 | var e = /(?:^|\s)nocode(?:\s|$)/,
98 | h = [],
99 | y = 0,
100 | t = [],
101 | s = 0,
102 | l;
103 | a.currentStyle ? l = a.currentStyle.whiteSpace : window.getComputedStyle && (l = document.defaultView.getComputedStyle(a, q).getPropertyValue("white-space"));
104 | var p = l && "pre" === l.substring(0, 3);
105 | m(a);
106 | return {
107 | a: h.join("").replace(/\n$/, ""),
108 | c: t
109 | }
110 | }
111 |
112 | function B(a, m, e, h) {
113 | m && (a = {
114 | a: m,
115 | d: a
116 | }, e(a), h.push.apply(h, a.e))
117 | }
118 |
119 | function x(a, m) {
120 | function e(a) {
121 | for (var l = a.d, p = [l, "pln"], d = 0, g = a.a.match(y) || [], r = {}, n = 0, z = g.length; n < z; ++n) {
122 | var f = g[n],
123 | b = r[f],
124 | o = void 0,
125 | c;
126 | if (typeof b === "string") c = !1;
127 | else {
128 | var i = h[f.charAt(0)];
129 | if (i) o = f.match(i[1]), b = i[0];
130 | else {
131 | for (c = 0; c < t; ++c) if (i = m[c], o = f.match(i[1])) {
132 | b = i[0];
133 | break
134 | }
135 | o || (b = "pln")
136 | }
137 | if ((c = b.length >= 5 && "lang-" === b.substring(0, 5)) && !(o && typeof o[1] === "string")) c = !1, b = "src";
138 | c || (r[f] = b)
139 | }
140 | i = d;
141 | d += f.length;
142 | if (c) {
143 | c = o[1];
144 | var j = f.indexOf(c),
145 | k = j + c.length;
146 | o[2] && (k = f.length - o[2].length, j = k - c.length);
147 | b = b.substring(5);
148 | B(l + i, f.substring(0, j), e, p);
149 | B(l + i + j, c, C(b, c), p);
150 | B(l + i + k, f.substring(k), e, p)
151 | } else p.push(l + i, b)
152 | }
153 | a.e = p
154 | }
155 | var h = {},
156 | y;
157 | (function() {
158 | for (var e = a.concat(m), l = [], p = {}, d = 0, g = e.length; d < g; ++d) {
159 | var r = e[d],
160 | n = r[3];
161 | if (n) for (var k = n.length; --k >= 0;) h[n.charAt(k)] = r;
162 | r = r[1];
163 | n = "" + r;
164 | p.hasOwnProperty(n) || (l.push(r), p[n] = q)
165 | }
166 | l.push(/[\S\s]/);
167 | y = L(l)
168 | })();
169 | var t = m.length;
170 | return e
171 | }
172 |
173 | function u(a) {
174 | var m = [],
175 | e = [];
176 | a.tripleQuotedStrings ? m.push(["str", /^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/, q, "'\""]) : a.multiLineStrings ? m.push(["str", /^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, q, "'\"`"]) : m.push(["str", /^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/, q, "\"'"]);
177 | a.verbatimStrings && e.push(["str", /^@"(?:[^"]|"")*(?:"|$)/, q]);
178 | var h = a.hashComments;
179 | h && (a.cStyleComments ? (h > 1 ? m.push(["com", /^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/, q, "#"]) : m.push(["com", /^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/, q, "#"]), e.push(["str", /^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/, q])) : m.push(["com", /^#[^\n\r]*/, q, "#"]));
180 | a.cStyleComments && (e.push(["com", /^\/\/[^\n\r]*/, q]), e.push(["com", /^\/\*[\S\s]*?(?:\*\/|$)/, q]));
181 | a.regexLiterals && e.push(["lang-regex", /^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);
182 | (h = a.types) && e.push(["typ", h]);
183 | a = ("" + a.keywords).replace(/^ | $/g, "");
184 | a.length && e.push(["kwd", RegExp("^(?:" + a.replace(/[\s,]+/g, "|") + ")\\b"), q]);
185 | m.push(["pln", /^\s+/, q, " \r\n\t\xa0"]);
186 | e.push(["lit", /^@[$_a-z][\w$@]*/i, q], ["typ", /^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/, q], ["pln", /^[$_a-z][\w$@]*/i, q], ["lit", /^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i, q, "0123456789"], ["pln", /^\\[\S\s]?/, q], ["pun", /^.[^\s\w"-$'./@\\`]*/, q]);
187 | return x(m, e)
188 | }
189 |
190 | function D(a, m) {
191 | function e(a) {
192 | switch (a.nodeType) {
193 | case 1:
194 | if (k.test(a.className)) break;
195 | if ("BR" === a.nodeName) h(a), a.parentNode && a.parentNode.removeChild(a);
196 | else for (a = a.firstChild; a; a = a.nextSibling) e(a);
197 | break;
198 | case 3:
199 | case 4:
200 | if (p) {
201 | var b = a.nodeValue,
202 | d = b.match(t);
203 | if (d) {
204 | var c = b.substring(0, d.index);
205 | a.nodeValue = c;
206 | (b = b.substring(d.index + d[0].length)) && a.parentNode.insertBefore(s.createTextNode(b), a.nextSibling);
207 | h(a);
208 | c || a.parentNode.removeChild(a)
209 | }
210 | }
211 | }
212 | }
213 |
214 | function h(a) {
215 | function b(a, d) {
216 | var e = d ? a.cloneNode(!1) : a,
217 | f = a.parentNode;
218 | if (f) {
219 | var f = b(f, 1),
220 | g = a.nextSibling;
221 | f.appendChild(e);
222 | for (var h = g; h; h = g) g = h.nextSibling, f.appendChild(h)
223 | }
224 | return e
225 | }
226 | for (; !a.nextSibling;) if (a = a.parentNode, !a) return;
227 | for (var a = b(a.nextSibling, 0), e;
228 | (e = a.parentNode) && e.nodeType === 1;) a = e;
229 | d.push(a)
230 | }
231 | var k = /(?:^|\s)nocode(?:\s|$)/,
232 | t = /\r\n?|\n/,
233 | s = a.ownerDocument,
234 | l;
235 | a.currentStyle ? l = a.currentStyle.whiteSpace : window.getComputedStyle && (l = s.defaultView.getComputedStyle(a, q).getPropertyValue("white-space"));
236 | var p = l && "pre" === l.substring(0, 3);
237 | for (l = s.createElement("LI"); a.firstChild;) l.appendChild(a.firstChild);
238 | for (var d = [l], g = 0; g < d.length; ++g) e(d[g]);
239 | m === (m | 0) && d[0].setAttribute("value", m);
240 | var r = s.createElement("OL");
241 | r.className = "linenums";
242 | for (var n = Math.max(0, m - 1 | 0) || 0, g = 0, z = d.length; g < z; ++g) l = d[g], l.className = "L" + (g + n) % 10, l.firstChild || l.appendChild(s.createTextNode("\xa0")), r.appendChild(l);
243 | a.appendChild(r)
244 | }
245 |
246 | function k(a, m) {
247 | for (var e = m.length; --e >= 0;) {
248 | var h = m[e];
249 | A.hasOwnProperty(h) ? window.console && console.warn("cannot override language handler %s", h) : A[h] = a
250 | }
251 | }
252 |
253 | function C(a, m) {
254 | if (!a || !A.hasOwnProperty(a)) a = /^\s*= o && (h += 2);
309 | e >= c && (a += 2)
310 | }
311 | } catch (w) {
312 | "console" in window && console.log(w && w.stack ? w.stack : w)
313 | }
314 | }
315 | var v = ["break,continue,do,else,for,if,return,while"],
316 | w = [
317 | [v, "auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], "catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],
318 | F = [w, "alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],
319 | G = [w, "abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"],
320 | H = [G, "as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],
321 | w = [w, "debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],
322 | I = [v, "and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"],
323 | J = [v, "alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],
324 | v = [v, "case,done,elif,esac,eval,fi,function,in,local,set,then,until"],
325 | K = /^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,
326 | N = /\S/,
327 | O = u({
328 | keywords: [F, H, w, "caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END" + I, J, v],
329 | hashComments: !0,
330 | cStyleComments: !0,
331 | multiLineStrings: !0,
332 | regexLiterals: !0
333 | }),
334 | A = {};
335 | k(O, ["default-code"]);
336 | k(x([], [
337 | ["pln", /^[^]+/],
338 | ["dec", /^]*(?:>|$)/],
339 | ["com", /^<\!--[\S\s]*?(?:--\>|$)/],
340 | ["lang-", /^<\?([\S\s]+?)(?:\?>|$)/],
341 | ["lang-", /^<%([\S\s]+?)(?:%>|$)/],
342 | ["pun", /^(?:<[%?]|[%?]>)/],
343 | ["lang-", /^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],
344 | ["lang-js", /^
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
30 |
31 |
32 |
33 |
34 | Classes
35 |
38 |
39 |
40 |
41 | Global
42 |
45 |
46 |
47 |
48 |
49 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
Class: MiddlewareManager
76 |
77 |
78 |
79 |
80 |
81 | MiddlewareManager
82 |
83 |
84 | Manage middlewares for an object.
85 | Middleware functions are functions that have access to the target function and it's arguments,
86 | and the target object and the next middleware function in the target function cycle.
87 | The next middleware function is commonly denoted by a variable named next.
88 |
Middleware functions can perform the following tasks:
89 |
90 | Execute any code.
91 | Make changes to the function's arguments.
92 | End the target function.
93 | Call the next middleware in the stack.
94 |
95 |
If the current middleware function does not end the target function cycle,
96 | it must call next() to pass control to the next middleware function. Otherwise,
97 | the target function will be left hanging.
98 |
e.g.
99 |
const walk = target => next => (...args) => {
100 | this.log(`walk function start.`);
101 | const result = next(...args);
102 | this.log(`walk function end.`);
103 | return result;
104 | }Middleware object is an object that contains function's name as same as the target object's function name.
105 |
e.g.
106 |
const Logger = {
107 | walk: target => next => (...args) => {
108 | console.log(`walk function start.`);
109 | const result = next(...args);
110 | console.log(`walk function end.`);
111 | return result;
112 | }
113 | }Function's name start or end with "_" will not be able to apply middleware.
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 | new MiddlewareManager()
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 | Example
194 |
195 | ## Basic
196 |
197 | We define a Person class.
198 | // the target object
199 | class Person {
200 | // the target function
201 | walk(step) {
202 | this.step = step;
203 | }
204 |
205 | speak(word) {
206 | this.word = word;
207 | }
208 | }
209 |
210 | Then we define a middleware function to print log.
211 |
212 | // middleware for walk function
213 | const logger = target => next => (...args) => {
214 | console.log(`walk start, steps: ${args[0]}.`);
215 | const result = next(...args);
216 | console.log(`walk end.`);
217 | return result;
218 | }
219 |
220 | Now we apply the log function as a middleware to a Person instance.
221 |
222 | // apply middleware to target object
223 | const p = new Person();
224 | const middlewareManager = new MiddlewareManager(p);
225 | middlewareManager.use('walk', logger);
226 | p.walk(3);
227 |
228 | Whenever a Person instance call it's walk method, we'll see logs from the looger middleware.
229 |
230 | ## Middleware object
231 | We can also apply a middleware object to a target object.
232 | Middleware object is an object that contains function's name as same as the target object's function name.
233 |
234 | const PersonMiddleware = {
235 | walk: target => next => step => {
236 | console.log(`walk start, steps: step.`);
237 | const result = next(step);
238 | console.log(`walk end.`);
239 | return result;
240 | },
241 | speak: target => next => word => {
242 | word = 'this is a middleware trying to say: ' + word;
243 | return next(word);
244 | }
245 | }
246 |
247 | // apply middleware to target object
248 | const p = new Person();
249 | const middlewareManager = new MiddlewareManager(p);
250 | middlewareManager.use(PersonMiddleware);
251 | p.walk(3);
252 | p.speak('hi');
253 |
254 | ## middlewareMethods
255 | In a class, function's name start or end with "_" will not be able to apply as middleware.
256 | Or we can use `middlewareMethods` to define function names for middleware target within a class.
257 |
258 | class PersonMiddleware {
259 | constructor() {
260 | // Or Define function names for middleware target.
261 | this.middlewareMethods = ['walk', 'speak'];
262 | }
263 | // Function's name start or end with "_" will not be able to apply as middleware.
264 | _getPrefix() {
265 | return 'Middleware log: ';
266 | }
267 | log(text) {
268 | console.log(this._getPrefix() + text);
269 | }
270 | walk(target) {
271 | return next => step => {
272 | this.log(`walk start, steps: step.`);
273 | const result = next(step);
274 | this.log(`walk end.`);
275 | return result;
276 | }
277 | }
278 | speak(target) {
279 | return next => word => {
280 | this.log('this is a middleware trying to say: ' + word);
281 | return next(word);
282 | }
283 | }
284 | }
285 |
286 | // apply middleware to target object
287 | const p = new Person();
288 | const middlewareManager = new MiddlewareManager(p);
289 | middlewareManager.use(new PersonMiddleware())
290 | p.walk(3);
291 | p.speak('hi');
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 | Methods
314 |
315 |
316 |
317 |
318 |
319 | use(methodName, middlewares)
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
Apply (register) middleware functions to the target function or apply (register) middleware objects.
328 | If the first argument is a middleware object, the rest arguments must be middleware objects.
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 | Parameters:
339 |
340 |
341 |
342 |
343 |
344 |
345 | Name
346 |
347 |
348 | Type
349 |
350 |
351 | Argument
352 |
353 |
354 |
355 |
356 | Description
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 | methodName
366 |
367 |
368 |
369 |
370 |
371 | string
372 | |
373 |
374 | object
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 | String for target function name, object for a middleware object.
394 |
395 |
396 |
397 |
398 |
399 |
400 | middlewares
401 |
402 |
403 |
404 |
405 |
406 | function
407 | |
408 |
409 | object
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 | <repeatable>
424 |
425 |
426 |
427 |
428 |
429 |
430 | The middleware chain to be applied.
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 | Returns:
491 |
492 |
493 |
496 |
497 |
498 |
499 |
500 |
501 | Type
502 |
503 |
504 |
505 | object
506 |
507 |
508 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 |
518 |
519 |
520 |
521 |
522 |
523 |
524 |
525 |
526 |
527 |
528 |
529 |
530 |
531 |
Class: MiddlewareManager
532 |
533 |
534 |
535 |
536 |
537 | MiddlewareManager
538 |
539 |
540 |
541 |
542 |
543 |
544 |
545 |
546 |
547 |
548 |
549 |
550 | new MiddlewareManager(target, middlewareObjects)
551 |
552 |
553 |
554 |
555 |
556 |
557 |
558 |
559 |
560 |
561 |
562 |
563 |
564 | Parameters:
565 |
566 |
567 |
568 |
569 |
570 |
571 | Name
572 |
573 |
574 | Type
575 |
576 |
577 | Argument
578 |
579 |
580 |
581 |
582 | Description
583 |
584 |
585 |
586 |
587 |
588 |
589 |
590 |
591 | target
592 |
593 |
594 |
595 |
596 |
597 | object
598 |
599 |
600 |
601 |
602 |
603 |
604 |
605 |
606 |
607 |
608 |
609 |
610 |
611 |
612 |
613 |
614 |
615 |
616 | The target object.
617 |
618 |
619 |
620 |
621 |
622 |
623 | middlewareObjects
624 |
625 |
626 |
627 |
628 |
629 | object
630 |
631 |
632 |
633 |
634 |
635 |
636 |
637 |
638 |
639 |
640 |
641 |
642 |
643 | <repeatable>
644 |
645 |
646 |
647 |
648 |
649 |
650 | Middleware objects.
651 |
652 |
653 |
654 |
655 |
656 |
657 |
658 |
659 |
660 |
661 |
662 |
663 |
664 |
665 |
666 |
667 |
668 |
669 |
670 |
671 |
672 |
673 |
674 |
675 |
676 |
677 |
678 |
679 |
680 |
681 |
682 |
683 |
684 |
685 |
686 |
687 |
688 |
689 |
690 |
691 |
692 |
693 |
694 |
695 |
696 |
697 |
698 |
699 |
700 |
701 |
702 |
703 |
704 |
705 |
706 |
707 |
708 |
709 |
710 | Returns:
711 |
712 |
713 |
716 |
717 |
718 |
719 |
720 |
721 | Type
722 |
723 |
724 |
725 | object
726 |
727 |
728 |
729 |
730 |
731 |
732 |
733 |
734 |
735 |
736 |
737 |
738 |
739 |
740 |
741 |
742 |
743 |
744 |
745 |
746 |
747 |
748 |
749 |
750 |
751 |
752 |
753 |
754 | Methods
755 |
756 |
757 |
758 |
759 |
760 | use(methodName, middlewares)
761 |
762 |
763 |
764 |
765 |
766 |
767 |
768 |
Apply (register) middleware functions to the target function or apply (register) middleware objects.
769 | If the first argument is a middleware object, the rest arguments must be middleware objects.
770 |
771 |
772 |
773 |
774 |
775 |
776 |
777 |
778 |
779 | Parameters:
780 |
781 |
782 |
783 |
784 |
785 |
786 | Name
787 |
788 |
789 | Type
790 |
791 |
792 | Argument
793 |
794 |
795 |
796 |
797 | Description
798 |
799 |
800 |
801 |
802 |
803 |
804 |
805 |
806 | methodName
807 |
808 |
809 |
810 |
811 |
812 | string
813 | |
814 |
815 | object
816 |
817 |
818 |
819 |
820 |
821 |
822 |
823 |
824 |
825 |
826 |
827 |
828 |
829 |
830 |
831 |
832 |
833 |
834 | String for target function name, object for a middleware object.
835 |
836 |
837 |
838 |
839 |
840 |
841 | middlewares
842 |
843 |
844 |
845 |
846 |
847 | function
848 | |
849 |
850 | object
851 |
852 |
853 |
854 |
855 |
856 |
857 |
858 |
859 |
860 |
861 |
862 |
863 |
864 | <repeatable>
865 |
866 |
867 |
868 |
869 |
870 |
871 | The middleware chain to be applied.
872 |
873 |
874 |
875 |
876 |
877 |
878 |
879 |
880 |
881 |
882 |
883 |
884 |
885 |
886 |
887 |
888 |
889 |
890 |
891 |
892 |
893 |
894 |
895 |
896 |
897 |
898 |
899 |
900 |
901 |
902 |
903 |
904 |
905 |
906 |
907 |
908 |
909 |
910 |
911 |
912 |
913 |
914 |
915 |
916 |
917 |
918 |
919 |
920 |
921 |
922 |
923 |
924 |
925 |
926 |
927 |
928 |
929 |
930 |
931 | Returns:
932 |
933 |
934 |
937 |
938 |
939 |
940 |
941 |
942 | Type
943 |
944 |
945 |
946 | object
947 |
948 |
949 |
950 |
951 |
952 |
953 |
954 |
955 |
956 |
957 |
958 |
959 |
960 |
961 |
962 |
963 |
964 |
965 |
966 |
967 |
968 |
969 |
970 |
971 |
972 |
973 |
974 |
975 |
976 |
977 |
978 |
981 |
982 |
983 |
984 |
985 |
986 |
987 |
1001 |
1002 |
1003 |
1004 |
1005 |
1006 |
1007 | Documentation generated by JSDoc 3.4.3
1008 |
1009 | on 2017-06-21
1010 |
1011 | using the DocStrap template .
1012 |
1013 |
1014 |
1015 |
1016 |
1017 |
1018 |
1019 |
1020 |
1021 |
1082 |
1083 |
1084 |
1085 |
1086 |
1087 |
1088 |
1089 |
1090 |
1091 |
1092 |
1097 |
1098 |
1099 |
1100 |