npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

funwithflags

v1.0.2

Published

parse argument options

Downloads

83

Readme

🚩 funwithflags

funwithflags

Build Status NPM version MIT License fliphub fluents

parse argument options

This module is minimist refactored as a fluent class ~125% faster.

browser support

📘 examples

var argv = require('funwithflags')(process.argv.slice(2));
console.log(argv);

📦 install

yarn add funwithflags --dev
npm install funwithflags --save-dev

⚙ options

| Name | Type | Description | ?Default | Example | | ---- | ---- | ----------- | -------- | -------- | | string | string | Array<string> | names to always treat as strings | null | | boolean | boolean | string | Array<string> | always treat as booleans. if true will treat all double hyphenated arguments without equal signs. (e.g. affects --foo, not -f or --foo=bar) | null | | alias | Object | an object mapping string names to strings or arrays of string names to use as aliases | {} | | default | Object | an object mapping string argument names to default values| {} | | ['--'] | boolean | populate argv._ with everything before the -- and argv['--'] with everything after the -- | null | | stopEarly | boolean | when true, populate argv._ with everything after the first non-option| null | | unknown | Function | a function which is invoked with a command line parameter not defined in the opts configuration object. If the function returns false, the unknown option is not added to argv | null | | obj | boolean | when true, returns the object instance of FunWithFlags | null | | vars | boolean | when true, allows args without dashes to be used as flags | null | | camel | boolean | when true, camelCases object keys on argv | null | | underscore | boolean | when false, object is returned with no _ (for looping over object keys or values or the like) | null |

extending the class

🔬 tests

🏋️ benchmarks

verbose


var unknown = []

// captures the unknown args, similar to how `vars` does
function unknownFn(arg) {
  unknown.push(arg)
  return true
}

var opts = {
  'default': {
    'moose.box': 11,
    'eh': true,
    'igloo': false,
  },
  'alias': {
    'moose.box': 'mooses.boxes',
    'rain': 'british-columbia',
  },
  'boolean': ['eh', 'igloo'],
  'string': ['country', 'nan', 'noflag'],
  'vars': true,
  '--': true,
  'obj': true, // will return the instance
  'unknown': unknownFn,
}

var args = [
  '--country=canada',

  // aliased to `rain` so it will have `rain: true, 'british-columbia': true`
  '--british-columbia',

  // no value is default a true boolean
  '--igloo',

  // dot notation
  '--a.b=100',

  // using `string: 'nan'` we ensure this stays as a string
  '--nan',
  '99',

  // first flag is boolean (t: true)
  // second flag assigned to following value (f: 555)
  '-tf',
  '555',

  // mooses and globbing are parsed only because `vars: true``
  'mooses.boxes=moozes',
  'globbing',
  `"**/*"`,

  // after double dash
  '--',
  'dis-little-piggy',
  'went-to-market',
]

var obj = require('../')(args, opts)
const argv = obj.argv