index.d.ts 645 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. Convert a value to an array.
  3. _Supplying `null` or `undefined` results in an empty array._
  4. @example
  5. ```
  6. import arrify = require('arrify');
  7. arrify('🦄');
  8. //=> ['🦄']
  9. arrify(['🦄']);
  10. //=> ['🦄']
  11. arrify(new Set(['🦄']));
  12. //=> ['🦄']
  13. arrify(null);
  14. //=> []
  15. arrify(undefined);
  16. //=> []
  17. ```
  18. */
  19. declare function arrify<ValueType>(
  20. value: ValueType
  21. ): ValueType extends (null | undefined)
  22. ? []
  23. : ValueType extends string
  24. ? [string]
  25. : ValueType extends ReadonlyArray<unknown> // TODO: Use 'readonly unknown[]' in the next major version
  26. ? ValueType
  27. : ValueType extends Iterable<infer T>
  28. ? T[]
  29. : [ValueType];
  30. export = arrify;