Get unlimited public & private packages + team-based management with npm Teams.Learn more »

args-any

1.0.1 • Public • Published

args-any

Utility lib for parsing command options

Build Status Codacy Badge Coverage Status tested with jest code style: prettier David GitHub npm

Installation

npm install args-any

Test

npm test

Usage

Parse arguments to a map

import { parse } from "args-any";
const args = ["-option1", "value1", "-option2>4", "-option3 lt 5"]
 
const options = parse(args);
 
options.has("option1");
==> true
 
options.get("option2");
==> {
  key"option2",
  operatorOperator.Gt,
  value"4"
}

Map arguments to a partial type

import { parse } from "args-any";
 
const args = ["-name", "server 1", "-memorySize", "1024" , "-isClustered", "true"];
 
interface Server {
  name: string;
  memorySize: number;
  isClustered: boolean;
  location: string;
}
 
const server = parse(args).asPartial<Server>();
 
==> {
  name"server 1",
  memorySize1024,
  isClusteredtrue
};

Filter a list based on arguments

const servers = [{
  name: "name 1",
  memorySize: 2048
}, {
  name: "name 2",
  memorySize: 2048
}, {
  name: "name 3",
  memorySize: 512
}];
 
const filtered = parse(["-memorySize=2048"]).filter(...servers);
 
==> [{
  name: "name1"
  ...
}, {
  name: "name2"
  ...
}
]

Install

npm i args-any

DownloadsWeekly Downloads

3

Version

1.0.1

License

MIT

Unpacked Size

43.4 kB

Total Files

66

Last publish

Collaborators

  • avatar