🚀 Launch Week Day 2:Introducing Custom Tabs for Org Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

commandments

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

commandments

Parse argument commands/options from code comments using esprima and minimist.

Source
npmnpm
Version
0.1.1
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

commandments NPM version

Parse argument commands/options from code comments using esprima and minimist.

Install

Install with npm

npm i commandments --save

Run tests

npm test

Usage

var commandments = require('commandments');

Example

Given you have a file named app.js with some code comments (both block and line comments will work):

// abc: apple kiwi grapefruit */
function foo(str) {
  return str;
}

function bar(str) {
  /* xyz: --exclude=cranberry */
  return str;
}

Pass keyword(s) to identify comments to parse, and the string with comments to parse.

var fs = require('fs');
var str = fs.readFileSync('lib/app.js', 'utf8');

// commandments([keywords], str);
var args = commandments(['abc', 'xyz'], str);

Results in:

{ abc: { _: [ 'apple', 'kiwi', 'grapefruit' ] },
  xyz: { _: [], exclude: 'cranberry' } }

API

commandments

Pass the keywords to use for identifying comments that should be parsed.

  • keywords {String|Array}: Keyword(s) to identify comments to parse.
  • str {String}: A string of valid javascript with comments to parse.
  • options {Object}: Options to pass to minimist
  • returns {Object}: Object of parsed arguments.

Heads up!:

  • a keyword must be the first thing in a comment, and
  • a "commandments comment" should only have arguments to be parsed.

Example:

commandments([keywords], str, opts={});

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert
Released under the MIT license

This file was generated by verb on November 29, 2014.

Keywords

args

FAQs

Package last updated on 29 Nov 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts