https://github.com/avoidwork/keysort
Sorts an Array of Objects with SQL ORDER BY clause syntax
https://github.com/avoidwork/keysort
Last synced: 10 months ago
JSON representation
Sorts an Array of Objects with SQL ORDER BY clause syntax
- Host: GitHub
- URL: https://github.com/avoidwork/keysort
- Owner: avoidwork
- License: bsd-3-clause
- Created: 2013-08-28T11:59:01.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2024-04-11T03:45:38.000Z (almost 2 years ago)
- Last Synced: 2024-04-14T09:34:46.744Z (almost 2 years ago)
- Language: JavaScript
- Homepage:
- Size: 611 KB
- Stars: 11
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# keysort
Sorts an Array of Objects with SQL ORDER BY clause syntax.
## Using the module
```javascript
import {keysort} from "keysort";
const arr = [{abc: 123124, xyz: 5}, {abc: 123124, xyz: 6}, {abc: 2, xyz: 5}];
keysort(arr, "abc, xyz"); // [{abc: 2, xyz: 5}, {abc: 123124, xyz: 5}, {abc: 123124, xyz: 6}];
keysort(arr, "abc, xyz desc"); // [{abc: 2, xyz: 5}, {abc: 123124, xyz: 6}, {abc: 123124, xyz: 5}];
```
## Testing
keysort has 100% code coverage with its tests.
```console
-------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------|---------|----------|---------|---------|-------------------
All files | 100 | 80 | 100 | 100 |
keysort.cjs | 100 | 80 | 100 | 100 | 25
-------------|---------|----------|---------|---------|-------------------
```
## API
### keysort(arr = [], order = "", toSorted = false)
Sorts an `Array` of `Objects` with SQL ORDER BY clause syntax. If `toSorted` is `true`, a new sorted `Array` is returned.
## License
Copyright (c) 2023 Jason Mulligan
Licensed under the BSD-3 license.