0.1.3 • Published 6 years ago

get-array-types v0.1.3

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Array Types

Get a beautiful string representation of types inside of an Array.

Inspiration

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.

Installation

Simply run

npm install --save get-array-types

Usage

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

License

  • MIT

Happy Javascripting! 〰️