Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.md 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # minimist-options ![test](https://github.com/vadimdemedes/minimist-options/workflows/test/badge.svg)
  2. > Write options for [minimist](https://npmjs.org/package/minimist) and [yargs](https://npmjs.org/package/yargs) in a comfortable way.
  3. > Supports string, boolean, number and array options.
  4. ## Installation
  5. ```
  6. $ npm install --save minimist-options
  7. ```
  8. ## Usage
  9. ```js
  10. const buildOptions = require('minimist-options');
  11. const minimist = require('minimist');
  12. const options = buildOptions({
  13. name: {
  14. type: 'string',
  15. alias: 'n',
  16. default: 'john'
  17. },
  18. force: {
  19. type: 'boolean',
  20. alias: ['f', 'o'],
  21. default: false
  22. },
  23. score: {
  24. type: 'number',
  25. alias: 's',
  26. default: 0
  27. },
  28. arr: {
  29. type: 'array',
  30. alias: 'a',
  31. default: []
  32. },
  33. strings: {
  34. type: 'string-array',
  35. alias: 's',
  36. default: ['a', 'b']
  37. },
  38. booleans: {
  39. type: 'boolean-array',
  40. alias: 'b',
  41. default: [true, false]
  42. },
  43. numbers: {
  44. type: 'number-array',
  45. alias: 'n',
  46. default: [0, 1]
  47. },
  48. published: 'boolean',
  49. // Special option for positional arguments (`_` in minimist)
  50. arguments: 'string'
  51. });
  52. const args = minimist(process.argv.slice(2), options);
  53. ```
  54. instead of:
  55. ```js
  56. const minimist = require('minimist');
  57. const options = {
  58. string: ['name', '_'],
  59. number: ['score'],
  60. array: [
  61. 'arr',
  62. {key: 'strings', string: true},
  63. {key: 'booleans', boolean: true},
  64. {key: 'numbers', number: true}
  65. ],
  66. boolean: ['force', 'published'],
  67. alias: {
  68. n: 'name',
  69. f: 'force',
  70. s: 'score',
  71. a: 'arr'
  72. },
  73. default: {
  74. name: 'john',
  75. f: false,
  76. score: 0,
  77. arr: []
  78. }
  79. };
  80. const args = minimist(process.argv.slice(2), options);
  81. ```
  82. ## Array options
  83. The `array` types are only supported by [yargs](https://npmjs.org/package/yargs).
  84. [minimist](https://npmjs.org/package/minimist) does _not_ explicitly support array type options. If you set an option multiple times, it will indeed yield an array of values. However, if you only set it once, it will simply give the value as is, without wrapping it in an array. Thus, effectively ignoring `{type: 'array'}`.
  85. `{type: 'array'}` is shorthand for `{type: 'string-array'}`. To have values coerced to `boolean` or `number`, use `boolean-array` or `number-array`, respectively.
  86. ## License
  87. MIT © [Vadim Demedes](https://vadimdemedes.com)