@sineverba/unique-keys
v1.2.0
Published
Generate unique keys for an array
Downloads
1
Readme
Unique Keys
| CI / CD | Status | | ------- | ------ | | NPM | | | Semaphore CI | | | Circle CI | | | Coverall | | | SonarCloud | |
Generates unique keys for an array.
uniqueKeys
adds unique ID to an object.
Why is it useful?
I use it when I need to iterate on an array, to fix the warning "Each Child in a List Should Have a Unique 'key' Prop"
Installation
npm install @sineverba/unique-keys
Usage
import { uniqueKeys } from "@sineverba/unique-keys";
const data = [
{
key: "fooKey",
value: "fooValue"
},
{
key: "barKey",
value: "barValue"
}
];
const newData = uniqueKeys(data);
console.log(newData);
/**
* It prints
*
* [
{
key: "fooKey",
value: "fooValue",
uniqueKey: "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d"
},
{
key: "barKey",
value: "barValue",
uniqueKey: "710b962e-041c-11e1-9234-0123456789ab"
}
];
*/
Tests
npm run test
for simple test
npm run cover
for coverage