JSPM

count-array-values

1.2.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 698
  • Score
    100M100P100Q113102F
  • License MIT

Count the instances of each value in an array

Package Exports

  • count-array-values

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (count-array-values) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

count-array-values Build Status

Count the instances of each value in an array, ignoring any non-string values.

Installation

npm install count-array-values --save

Usage

var count = require('count-array-values')
count(['foo', 'bar', 'Bar', 451, 'bar', 'bar', 'baz', 'foo', null, undefined])

// [
//   {value: 'bar', count: 3},
//   {value: 'foo', count: 2},
//   {value: 'Bar', count: 1},
//   {value: 'baz', count: 1},
// ]

If you'd like to use a more relevant property name than value, specify it as the second argument when calling the function:

count(['apple', 'banana', 'apple'], 'fruit')

// [
//   {fruit: 'apple', count: 2},
//   {fruit: 'banana', count: 1}
// ]

You can also override the name of the count property:

const packages = ['express', 'lodash', 'express', 'lodash', 'express', 'banana']
count(packages, 'package', 'dependents')

// [
//   {package: 'express', dependents: 3},
//   {package: 'lodash', dependents: 2},
//   {package: 'banana', dependents: 1}
// ]

Tests

npm install
npm test

Dependencies

None

Dev Dependencies

  • standard: JavaScript Standard Style
  • standard-markdown: Test your Markdown files for Standard JavaScript Style™
  • tap-spec: Formatted TAP output like Mocha's spec reporter
  • tape: tap-producing test harness for node and browsers

License

MIT