Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/reachifyio/dataloader-sort
Sort function for DataLoader to ensure the correct data is returned for the matching keys
https://github.com/reachifyio/dataloader-sort
Last synced: about 1 month ago
JSON representation
Sort function for DataLoader to ensure the correct data is returned for the matching keys
- Host: GitHub
- URL: https://github.com/reachifyio/dataloader-sort
- Owner: reachifyio
- License: mit
- Created: 2017-04-03T18:33:32.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-20T20:57:13.000Z (over 5 years ago)
- Last Synced: 2024-09-15T03:31:52.967Z (3 months ago)
- Language: JavaScript
- Size: 29.3 KB
- Stars: 25
- Watchers: 3
- Forks: 6
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome - dataloader-sort - Sort function for DataLoader to ensure the correct data is returned for the matching keys (JavaScript)
README
# DataLoader Sort
Sort function for DataLoader to ensure the correct data is returned for the matching keys[![npm version](https://badge.fury.io/js/dataloader-sort.svg)](https://badge.fury.io/js/dataloader-sort) [![Build Status](https://travis-ci.org/reachifyio/dataloader-sort.svg?branch=master)](https://travis-ci.org/reachifyio/dataloader-sort) [![Coverage Status](https://coveralls.io/repos/github/reachifyio/dataloader-sort/badge.svg?branch=master)](https://coveralls.io/github/reachifyio/dataloader-sort?branch=master)
## Installation
`npm i -S dataloader-sort`## Notes
* If no match is found it will return `null` for this key
* Includes Flow types## Usage
### Basic Usage
```
import sort from 'dataloader-sort';const keys = [1, 2, 3];
const data = [
{ id: 3, value: 'three' },
{ id: 1, value: 'one' },
{ id: 4, value: 'four' },
];const result = sort(keys, data);
```##### Output
```
[
{ id: 1, value: 'one' },
null,
{ id: 3, value: 'three' },
]
```### Custom Prop Usage
```
const keys = [1, 2, 3];
const data = [
{ other: 3, value: 'three' },
{ other: 1, value: 'one' },
{ other: 2, value: 'two' },
];const result = sort(keys, data, 'other');
```##### Output
```
[
{ other: 1, value: 'one' },
{ other: 2, value: 'two' },
{ other: 3, value: 'three' },
]
```### Object Keys Usage
```
const keys = [
{ userId: 1, messageId: 3 },
{ userId: 2, messageId: 4 },
{ userId: 3, messageId: 9 },
{ userId: 3, messageId: 7 },
{ userId: 1, messageId: 2 },
];
const data = [
{ userId: 1, messageId: 2, value: 'yayy' },
{ userId: 3, messageId: 7, value: 'ya' },
{ userId: 1, messageId: 3, value: 'woot' },
{ userId: 2, messageId: 4, value: 'blue' },
{ userId: 3, messageId: 9, value: 'green' },
];const result = sort(keys, data);
```##### Output
```
[
{ userId: 1, messageId: 3, value: 'woot' },
{ userId: 2, messageId: 4, value: 'blue' },
{ userId: 3, messageId: 9, value: 'green' },
{ userId: 3, messageId: 7, value: 'ya' },
{ userId: 1, messageId: 2, value: 'yayy' },
]
```