-
-
Notifications
You must be signed in to change notification settings - Fork 38
Inquiry about Number Parsing in minimist #79
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
Comments
I am using test program
This is expected behaviour because a digit can be used as the short flag for an option. So
I was not able to reproduce this.
These are expected behaviours. The option argument gets recognised as a number and converted to a number. The
|
Thank for response :) For case1, I noticed that there are two ways to assign a value to x: I use same test program, can reproducible case3. So in cases like case5 and case6, even if double quotes |
Although I think the actual standard allows you to keep or omit equals signs, I think the proper thing is to never use them with single-dashed options, and always use them with double-dashed options. |
There are four forms for supplying the option-argument for an argument with Minimist. The parsing result is usually the same, except for option-arguments that start with a
Three reasons for choosing one form over another:
|
The difference is likely what shell you are using and how it processes the arguments BEFORE they reach minimist. Try logging out the arguments in your test program. For example, you can see why the quotes make no difference for me using const argv = require('minimist')(process.argv.slice(2));
console.log(process.argv);
console.log(argv); $ node main.js -x="0123"
[ '-x=0123' ]
{ _: [], x: 123 } |
I understand the design and selection method for choosing parameters, thank you :) About float parse, you're right that only encounter this issue on PowerShell in Windows VSCode. Other terminals at Windows like CMD and git-bash.exe can parse it correctly. About quotes to covert number to string, I agree that if the double quotes are stripped by the shell, it becomes impossible to determine whether the value should be treated as a number or a string. |
Hi,
While working with
minimist
, I noticed a few parsing behaviors that might be either limitations or intentional design choices. I would appreciate clarification on whether the following are expected behaviors, and whether there's a recommended approach to handle them.Environment
Cases
1. Negative number not parsed correctly when not using
=
Expected:
Actual:
2. Negative number parsed correctly only when using = syntax
This works correctly and gives:
Note: It would be more convenient if negative numbers could be handled the same way in both cases, without needing = syntax.
3. Float values not parsed correctly
Expected:
Actual:
4. Negative number parsed correctly only when not using = syntax
This works correctly and gives:
5. If only number stringified numbers lose their leading zeros
node main.js --name "0123"
Expected:
Actual:
6. If only number stringified numbers lose their leading zeros even using = syntax
node main.js --name="0123"
Expected:
Actual:
7. If use leading zeros number plus chars parsed correctly
node main.js --name "0123kk"
This works correctly and gives:
8. If use leading zeros number plus chars and using using = syntax parsed correctly
node main.js --name="0123kk"
This works correctly and gives:
The text was updated successfully, but these errors were encountered: