array-functions
A set of frequently used functions for working with arrays, for sorting, filtering or checking the state of an array
Functions
filterBySameKeyValue
Filters an array of objects so that the value of a given key occurs only once in the array.
import { filterBySameKeyValue } from '@plq/array-functions'
const array = [
{ id: 1, name: 'Alice' },
{ id: 2, name: 'Bob' },
{ id: 3, name: 'Alice' },
]
console.log(filterBySameKeyValue(array, 'name'))
getKeyValue
Returns the array of values of a given key from an array of objects.
import { getKeyValue } from '@plq/array-functions'
const array = [
{ id: 1, name: 'Alice' },
{ id: 2, name: 'Bob' },
{ id: 3, name: 'Alice' },
]
console.log(getKeyValue(array, 'name'))
sortBy
Sorts an array of objects by a given key.
import { sortBy } from '@plq/array-functions'
const array = [
{ id: 1, name: 'Alice' },
{ id: 3, name: 'Alice' },
{ id: 2, name: 'Bob' },
]
console.log(sortBy(array, 'id'))
console.log(sortBy(array, 'id', 'asc'))
isSorted
Checks if an array of objects is sorted by a given key.
import { isSorted } from '@plq/array-functions'
const array = [
{ id: 1, name: 'Alice' },
{ id: 2, name: 'Bob' },
{ id: 3, name: 'Alice' },
]
console.log(isSorted(array, 'id'))
console.log(isSorted(array, 'id', 'asc'))
console.log(isSorted(array, 'name', 'asc'))
getUniqueValues
Returns an array of unique values from an array of objects.
import { getUniqueValues } from '@plq/array-functions'
const array = [
{ id: 1, name: 'Alice' },
{ id: 2, name: 'Bob' },
{ id: 3, name: 'Alice' },
]
console.log(getUniqueValues(array, 'name'))
Development
Install dependencies
npm install
Lint
We use ESLint and @typescript-eslint/eslint-plugin to lint our code.
Check out .eslintrc.json
npm run lint
Run tests
We use Jest to test our code.
npm test
Build
We use TypeScript to build our code.
npm run build
Dev check list