Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #24 #34

Merged
merged 1 commit into from
Jun 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/nopt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"}
Expand Down