From 251c98f28476c1d864e6f81c02df14f0f61cdb06 Mon Sep 17 00:00:00 2001 From: jbondc Date: Mon, 16 Feb 2015 10:46:08 -0500 Subject: [PATCH] nopt typings --- nopt/nopt-tests.ts | 20 ++++++++++++++++++++ nopt/nopt.d.ts | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 nopt/nopt-tests.ts create mode 100644 nopt/nopt.d.ts diff --git a/nopt/nopt-tests.ts b/nopt/nopt-tests.ts new file mode 100644 index 0000000000..1e2fb60a5c --- /dev/null +++ b/nopt/nopt-tests.ts @@ -0,0 +1,20 @@ +/** +* Maintained by: jbondc +*/ + +/// +/// + +import nopt = require("nopt"); + +nopt({"--foo" : String}) + +nopt({ "--foo": String }, { "-f": "--foo"}) +nopt({ "--foo": String }, { "-f": ["--foo", "-d"] }) + +nopt({ "--foo": String }, { "-f": ["--foo", "-d"] }, ["test me --foo arg"]) +var cmd = nopt({ "--foo": String }, { "-f": ["--foo", "-d"] }, ["test me --foo arg"], 2) + +console.log(cmd.argv.cooked) +console.log(cmd.argv.original) +console.log(cmd.argv.remain) diff --git a/nopt/nopt.d.ts b/nopt/nopt.d.ts new file mode 100644 index 0000000000..01e439821e --- /dev/null +++ b/nopt/nopt.d.ts @@ -0,0 +1,46 @@ +// Type definitions for nopt 3.0.1 +// Project: https://github.com/npm/nopt +// Definitions by: jbondc +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "nopt" { + + interface CommandData { + [key: string]: string + } + + interface TypeDefs { + [key: string]: TypeInfo + } + + interface TypeInfo { + type: Object + validate: (data: CommandData, k: string, val: string) => boolean + } + + module nopt { + export function clean(data: CommandData, types: FlagTypeMap, typeDefs?: TypeDefs): string + export var typeDefs: TypeDefs + } + + interface FlagTypeMap { + [k: string]: Object + } + + interface ShortFlags { + [k: string]: string[]|string + } + + function nopt(types: FlagTypeMap, shorthands?: ShortFlags, args?: string[], slice?: number): OptionsParsed + + interface OptionsParsed { + [k: string]: any + argv: { + remain: string[] + cooked: string[] + original: string[] + } + } + + export = nopt +} \ No newline at end of file