diff --git a/README.md b/README.md index 96798a1..5aba088 100644 --- a/README.md +++ b/README.md @@ -116,8 +116,7 @@ considered valid values. For instance, in the example above, the and any other value will be rejected. When parsing unknown fields, `"true"`, `"false"`, and `"null"` will be -interpreted as their JavaScript equivalents, and numeric values will be -interpreted as a number. +interpreted as their JavaScript equivalents. You can also mix types and values, or multiple types, in a list. For instance `{ blah: [Number, null] }` would allow a value to be set to diff --git a/lib/nopt.js b/lib/nopt.js index 9efab7a..223ebfe 100644 --- a/lib/nopt.js +++ b/lib/nopt.js @@ -50,7 +50,7 @@ function nopt (types, shorthands, args, slice) { function clean (data, types, typeDefs) { typeDefs = typeDefs || exports.typeDefs var remove = {} - , typeDefault = [false, true, null, String, Number, Array] + , typeDefault = [false, true, null, String, Array] Object.keys(data).forEach(function (k) { if (k === "argv") return diff --git a/test/basic.js b/test/basic.js index b31dccf..2f9088c 100644 --- a/test/basic.js +++ b/test/basic.js @@ -23,6 +23,14 @@ test("~ path is resolved to $HOME", function (t) { t.end() }) +// https://github.com/npm/nopt/issues/24 +test("Unknown options are not parsed as numbers", function (t) { + var parsed = nopt({"parse-me": Number}, null, ['--leave-as-is=1.20', '--parse-me=1.20'], 0) + t.equal(parsed['leave-as-is'], '1.20') + t.equal(parsed['parse-me'], 1.2) + t.end() +}); + test("other tests", function (t) { var util = require("util") @@ -170,7 +178,7 @@ test("other tests", function (t) { ,{t:["true"]} ,[]] ,["-aoa one -aoa null -aoa 100" - ,{aoa:["one", null, 100]} + ,{aoa:["one", null, '100']} ,[]] ,["-str 100" ,{str:"100"}