Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jonkemp/sort-by-util
Returns a sorted copy of an array, ranked in ascending order by the results of running each value through an iteratee
https://github.com/jonkemp/sort-by-util
array arrays iteratee sort util utility
Last synced: 26 days ago
JSON representation
Returns a sorted copy of an array, ranked in ascending order by the results of running each value through an iteratee
- Host: GitHub
- URL: https://github.com/jonkemp/sort-by-util
- Owner: jonkemp
- License: mit
- Created: 2020-03-17T03:49:22.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-03-26T13:40:07.000Z (over 2 years ago)
- Last Synced: 2024-09-26T17:18:32.410Z (about 1 month ago)
- Topics: array, arrays, iteratee, sort, util, utility
- Language: JavaScript
- Size: 127 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sort-by-util ![Build Status](https://github.com/jonkemp/sort-by-util/actions/workflows/main.yml/badge.svg?branch=master)
> Returns a (stably) sorted copy of an array, ranked in ascending order by the results of running each value through an iteratee. iteratee may also be the string name of the property to sort by (eg. length).
Inspired by `_.sortBy`. 😄
## Install
Install with [npm](https://npmjs.org/package/sort-by-util)
```
$ npm install sort-by-util
```Or [unpkg](https://unpkg.com/sort-by-util/)
```
```
Check out the unit tests on [CodePen](https://codepen.io/jonkemp/full/poJVzxN).
## Usage
```js
const sortBy = require('sort-by-util');const users = [
{ user: 'fred', age: 48 },
{ user: 'barney', age: 36 },
{ user: 'fred', age: 40 },
{ user: 'barney', age: 34 }
];sortBy(users, 'user');
//=> [{ 'user': 'barney', 'age': 36 }, { 'user': 'barney', 'age': 34 }, { 'user': 'fred', 'age': 48 }, { 'user': 'fred', 'age': 40 }]sortBy(users, ({user}) => user);
//=> [{ 'user': 'barney', 'age': 36 }, { 'user': 'barney', 'age': 34 }, { 'user': 'fred', 'age': 48 }, { 'user': 'fred', 'age': 40 }]
```---
| **Like us a lot?** Help others know why you like us! **Review this package on [pkgreview.dev](https://pkgreview.dev/npm/sort-by-util)** | âž¡ | [![Review us on pkgreview.dev](https://i.ibb.co/McjVMfb/pkgreview-dev.jpg)](https://pkgreview.dev/npm/sort-by-util) |
| ----------------------------------------------------------------------------------------------------------------------------------------- | --- | --------------------------------------------------------------------------------------------------------------------- |## API
### sortBy(collection, iteratee)
#### collection
Type: `array`
Default: `none`The array to iterate over.
#### iteratee
Type: `string` or `function` or `object`
Default: `none`The property name, function or object to sort by.
## License
MIT