array-types-counter
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

array-types-counter

Simple helper to obtain the count of different array item's types.

Installation

Using npm, npm i array-types-counter.

Using yarn, yarn add array-types-counter.

Usage

Using import

import { countArrayTypes } from 'array-types-counter';

const array = [1, 2, 'three', [1, 2, 3]];

const counts = countArrayTypes(array);

// counts is [{type: 'number', count: 2}, {type: 'string', count: 1}, {type: 'object', count: 1}]

In a CommonJS environment

const { countArrayTypes } = require('array-types-counter');

const array = [1, 2, '3', [1, 2, 3]]; // Strings that can be casted to numbers, count as numbers

const counts = countArrayTypes(array);

// counts is [{type: 'number', count: 3}, {type: 'object', count: 1}]

Table of contents

Functions

Functions

countArrayTypes

countArrayTypes(array: any[]): TypeCount[]

Counts the array's item types

export

Parameters:

Name Type
array any[]

Returns: TypeCount[]

The array item types ordered by count, descending

Defined in: index.ts:34

Readme

Keywords

Package Sidebar

Install

npm i array-types-counter

Weekly Downloads

51

Version

1.0.1

License

MIT

Unpacked Size

14.4 kB

Total Files

15

Last publish

Collaborators

  • alrico88