index.d.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. declare namespace yn {
  2. interface Options {
  3. /**
  4. Use a key distance-based score to leniently accept typos of `yes` and `no`.
  5. @default false
  6. */
  7. readonly lenient?: boolean;
  8. /**
  9. Default value if no match was found.
  10. @default null
  11. */
  12. readonly default?: boolean | null;
  13. }
  14. interface OptionsWithDefault extends Options {
  15. default: boolean;
  16. }
  17. }
  18. declare const yn: {
  19. /**
  20. Parse yes/no like values.
  21. The following case-insensitive values are recognized: `'y', 'yes', 'true', true, '1', 1, 'n', 'no', 'false', false, '0', 0`
  22. @param input - Value that should be converted.
  23. @returns The parsed input if it can be parsed or the default value defined in the `default` option.
  24. @example
  25. ```
  26. import yn = require('yn');
  27. yn('y');
  28. //=> true
  29. yn('NO');
  30. //=> false
  31. yn(true);
  32. //=> true
  33. yn('abomasum');
  34. //=> null
  35. yn('abomasum', {default: false});
  36. //=> false
  37. yn('mo', {lenient: true});
  38. //=> false
  39. ```
  40. */
  41. (input: unknown, options: yn.OptionsWithDefault): boolean;
  42. (input: unknown, options?: yn.Options): boolean | null;
  43. // TODO: Remove this for the next major release, refactor the whole definition to:
  44. // declare function yn(input: unknown, options: yn.OptionsWithDefault): boolean;
  45. // declare function yn(input: unknown, options?: yn.Options): boolean | null;
  46. // export = yn;
  47. default: typeof yn;
  48. };
  49. export = yn;