Get a beautiful string representation of types inside of an Array.
To be completely fair, none. I needed a tiny, zero dependency package for a project that would do this, so I decided to create one.
Simply run
npm install --save get-array-types
const ArrayTypes = require('get-array-types')
console.log(ArrayTypes([1, 2, 3, 'Hello', 'World']).toString())
//=> Array<number|string>
console.log(ArrayTypes([1, 'Hello', 2, 'World']).elementTypes())
//=> ['number', 'string']
console.log(ArrayTypes([1, 2, 3]).isOfSingleType())
//=> true
console.log(ArrayTypes([1, 2, 'Oops.']).isOfSingleType())
//=> false
get-array-types
also provides a useful utility function, isArray
.
Use it as follows:
const isArray = require('get-array-types').isArray
console.log(isArray('Hello World.'))
//=> false
console.log(isArray([1, 2, 3]))
//=> true
- MIT
Happy Javascripting! 〰️