51 lines
3.2 KiB
JSON
51 lines
3.2 KiB
JSON
|
{
|
||
|
"name": "getargs",
|
||
|
"version": "0.0.8",
|
||
|
"description": "Utility to handle optional arguments and argument type checking.",
|
||
|
"main": "index.js",
|
||
|
"dependencies": {},
|
||
|
"devDependencies": {
|
||
|
"chai": "~1.7.2"
|
||
|
},
|
||
|
"scripts": {
|
||
|
"test": "mocha tests.js -u tdd"
|
||
|
},
|
||
|
"keywords": [
|
||
|
"arguments",
|
||
|
"utility"
|
||
|
],
|
||
|
"repository": {
|
||
|
"type": "git",
|
||
|
"url": "git@github.com:airportyh/getargs.git"
|
||
|
},
|
||
|
"author": {
|
||
|
"name": "Toby Ho"
|
||
|
},
|
||
|
"license": "MIT",
|
||
|
"readme": "getargs\n=======\n\nSimple utility for parsing/processing variable length argument lists for Javascript functions; also verifies argument types and argument list length.\n\n## Install\n\nBower - `bower install getargs`; NPM - `npm install getargs`.\n\n## Usage\n\n var getArgs = require('getargs')\n\n function ajax(/* url:string|array, [options]:object, callback:function */){\n var args = getArgs('url:string|array, [options]:object, callback:function', arguments)\n\n console.log('url is', args.url)\n console.log('options is optionally', args.options)\n console.log('callback', args.callback)\n }\n\n## Argument Spec Syntax\n\nThe argument spec is a comma delimited string of individual specs, which look like\n\n argname:type\n\nYou can specify multiple types by using `|`\n\n argname:type|type|type\n\n* `argname` is the name of the argument, and can be called anything\n* `type` is an optional basic Javascript type. Currently these are supported\n * `string`\n * `boolean`\n * `number`\n * `object`\n * `function`\n * `array`\n\n### Optional Arguments\n\nTo denote optional arguments, you'd surround `argname` with square brackets `[]`.\n\n### Type Verification\n\ngetArgs will throw if the arguments have the wrong types\n\n var args = getArgs('url:string', [1])\n // Error: Expected url(pos 0) to be a string\n\n### Argument List Length Verification\n\ngetArgs will throw if there are too many or too few arguments\n\n > getArgs('a,b', [1])\n Error: Not enough arguments, expected 2, got 1\n > getArgs('a,b', [1,1])\n { a: 1, b: 1 }\n > getArgs('a,b', [1,1,1])\n Error: Too many arguments, expected 2, got 3\n\n### Spread Operator\n\nYou can mimick ES6's spread operator\n\n var args = getArgs('first,...rest', [1,2,3,4])\n console.log(args.first) // 1\n console.log(args.rest) // [2,3,4]\n\n### Set properties on an object\n\nIf you pass an object as its third argument, it will set the arguments as properties on that object.\n\n getArgs('a,b,c', arguments, this)\n // Now you can access the arguments by\n // this.a, this.b, and this.c\n \n",
|
||
|
"readmeFilename": "README.md",
|
||
|
"bugs": {
|
||
|
"url": "https://github.com/airportyh/getargs/issues"
|
||
|
},
|
||
|
"_id": "getargs@0.0.8",
|
||
|
"dist": {
|
||
|
"shasum": "8516605872c980178e01ca70106fccd22521fc7c",
|
||
|
"tarball": "http://registry.npmjs.org/getargs/-/getargs-0.0.8.tgz"
|
||
|
},
|
||
|
"_from": "getargs@*",
|
||
|
"_npmVersion": "1.3.8",
|
||
|
"_npmUser": {
|
||
|
"name": "airportyh",
|
||
|
"email": "airportyh@gmail.com"
|
||
|
},
|
||
|
"maintainers": [
|
||
|
{
|
||
|
"name": "airportyh",
|
||
|
"email": "airportyh@gmail.com"
|
||
|
}
|
||
|
],
|
||
|
"directories": {},
|
||
|
"_shasum": "8516605872c980178e01ca70106fccd22521fc7c",
|
||
|
"_resolved": "https://registry.npmjs.org/getargs/-/getargs-0.0.8.tgz"
|
||
|
}
|