index.d.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import {Opts as MinimistOptions} from 'minimist';
  2. export type OptionType = 'string' | 'boolean' | 'number' | 'array' | 'string-array' | 'boolean-array' | 'number-array';
  3. export interface BaseOption<
  4. TypeOptionType extends OptionType,
  5. DefaultOptionType
  6. > {
  7. /**
  8. * The data type the option should be parsed to.
  9. */
  10. readonly type?: TypeOptionType;
  11. /**
  12. * An alias/list of aliases for the option.
  13. */
  14. readonly alias?: string | ReadonlyArray<string>;
  15. /**
  16. * The default value for the option.
  17. */
  18. readonly default?: DefaultOptionType;
  19. }
  20. export type StringOption = BaseOption<'string', string>;
  21. export type BooleanOption = BaseOption<'boolean', boolean>;
  22. export type NumberOption = BaseOption<'number', number>;
  23. export type DefaultArrayOption = BaseOption<'array', ReadonlyArray<string>>;
  24. export type StringArrayOption = BaseOption<'string-array', ReadonlyArray<string>>;
  25. export type BooleanArrayOption = BaseOption<'boolean-array', ReadonlyArray<boolean>>;
  26. export type NumberArrayOption = BaseOption<'number-array', ReadonlyArray<number>>;
  27. type MinimistOption = NonNullable<
  28. | MinimistOptions['stopEarly']
  29. | MinimistOptions['unknown']
  30. | MinimistOptions['--']
  31. >;
  32. export type Options = {
  33. [key: string]:
  34. | OptionType
  35. | StringOption
  36. | BooleanOption
  37. | NumberOption
  38. | DefaultArrayOption
  39. | StringArrayOption
  40. | BooleanArrayOption
  41. | NumberArrayOption
  42. | MinimistOption; // Workaround for https://github.com/microsoft/TypeScript/issues/17867
  43. };
  44. /**
  45. * Write options for [minimist](https://npmjs.org/package/minimist) in a comfortable way. Support string, boolean, number and array options.
  46. */
  47. export default function buildOptions(options?: Options): MinimistOptions;