@sineverba/unique-keys
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

Unique Keys

CI / CD Status
NPM npm version
Semaphore CI Build Status
Circle CI CircleCI
Coverall Coverage Status
SonarCloud Quality Gate Status

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

Readme

Keywords

Package Sidebar

Install

npm i @sineverba/unique-keys

Weekly Downloads

2

Version

1.2.0

License

MIT

Unpacked Size

4.85 kB

Total Files

5

Last publish

Collaborators

  • sineverba