Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / utile / lib / args.js
1 /*
2  * args.js: function argument parsing helper utility
3  *
4  * (C) 2012, Nodejitsu Inc.
5  * MIT LICENSE
6  *
7  */
8
9 var utile = require('./index');
10
11 //
12 // ### function args(_args)
13 // #### _args {Arguments} Original function arguments
14 //
15 // Top-level method will accept a javascript "arguments" object (the actual keyword
16 // "arguments" inside any scope), and attempt to return back an intelligent object
17 // representing the functions arguments
18 //
19 module.exports = function (_args) {
20   var args = utile.rargs(_args),
21       _cb;
22
23   //
24   // Find and define the first argument
25   //
26   Object.defineProperty(args, 'first', { value: args[0] });
27
28   //
29   // Find and define any callback
30   //
31   _cb = args[args.length - 1] || args[args.length];
32   if (typeof _cb === "function") {
33     Object.defineProperty(args, 'callback', { value: _cb });
34     Object.defineProperty(args, 'cb', { value: _cb });
35     args.pop();
36   }
37
38   //
39   // Find and define the last argument
40   //
41   if (args.length) {
42     Object.defineProperty(args, 'last', { value: args[args.length - 1] });
43   }
44
45   return args;
46 };