1 | 'use strict';
|
2 |
|
3 | var Options = require('./options');
|
4 |
|
5 | module.exports = normalizeArgs;
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | function normalizeArgs (args) {
|
14 | var path, schema, options, callback;
|
15 | args = Array.prototype.slice.call(args);
|
16 |
|
17 | if (typeof args[args.length - 1] === 'function') {
|
18 |
|
19 | callback = args.pop();
|
20 | }
|
21 |
|
22 | if (typeof args[0] === 'string') {
|
23 |
|
24 | path = args[0];
|
25 | if (typeof args[2] === 'object') {
|
26 |
|
27 | schema = args[1];
|
28 | options = args[2];
|
29 | }
|
30 | else {
|
31 |
|
32 | schema = undefined;
|
33 | options = args[1];
|
34 | }
|
35 | }
|
36 | else {
|
37 |
|
38 | path = '';
|
39 | schema = args[0];
|
40 | options = args[1];
|
41 | }
|
42 |
|
43 | if (!(options instanceof Options)) {
|
44 | options = new Options(options);
|
45 | }
|
46 |
|
47 | return {
|
48 | path: path,
|
49 | schema: schema,
|
50 | options: options,
|
51 | callback: callback
|
52 | };
|
53 | }
|