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

[QUESTION] List of numbers ? #33

Open
kapouer opened this issue Mar 26, 2014 · 2 comments
Open

[QUESTION] List of numbers ? #33

kapouer opened this issue Mar 26, 2014 · 2 comments
Labels
Question further information is requested

Comments

@kapouer
Copy link

kapouer commented Mar 26, 2014

Is that possible ?

var opts = {
  "bloo" : [0, 1, 2]
};

It seems --bloo 1 isn't accepted when i do that.

@stevenvachon
Copy link
Contributor

nopt is configured to work with types, not values. So, try:

"bloo" : Number
// or
"bloo" : [Array, Number]

Then handle the value conditions manually:

if (options.bloo > 0 && options.bloo < 3) {
    console.log("success");
}
// or
for (var i=0; i<options.bloo.length; i++) {
    if (options.bloo[i] > 0 && options.bloo[i] < 3) {
        console.log("success");
        break;
    }
}

@mklement0
Copy link
Contributor

@stevenvachon: (As of at least v3.0.1) it does work with values, at least with strings (there's an example in the read-me).

Not supporting it with numbers smells like a bug - unless I'm missing something.

Thus, here's a simple workaround: define your numbers as strings and convert afterward:

var opts = {
  "bloo" : ['0', '1', '2']
};

parsed = nopt(opts);

// Convert to integer after parsing.
if (parsed.bloo) parsed.bloo = parseInt(parsed.bloo, 10);

@darcyclarke darcyclarke changed the title list of numbers ? [QUESTION] List of numbers ? Jul 28, 2022
@darcyclarke darcyclarke added the Question further information is requested label Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants