Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unique-key-js

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unique-key-js

Object comparison utility that provides uniqueness information about the keys within an array of objects.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

JS Object Key Information

This is a 0dep JS module/class that provides 'uniqueness' information about the keys within an array of objects. Particularly useful in searching / sorting / filtering applications or for general object comparison.

Installation

user@machine> npm i unique-key-js -S

- or -

simply include UniqueKey.js in your project and src/package/import/require it as necessary.

Usage

UniqueKey.js exports a factory class as a module, UniqueKey

const UniqueKey = require('./UniqueKey')
console.log('More Detailed Key Info : ', UniqueKey.getInfoAboutKeys(people))
console.log('Keys with Unique Values : ', UniqueKey.getKeysWithUniqueValues(people))

Example

const UniqueKey = require('./UniqueKey')

const people = [{
  "department":"Content Management",
  "deskphone" : "+1-234-456-7890",
  "displayname" : "Sherell Marcusen",
  "email" : "smarcusen@somedomain.com",
  "employee_id" : "5819",
  "firstname" : "Sherell ",
  "lastname" : "Marcusen",
  "location" : "LAX",
  "mobile" : "+1-123-234-3456",
  "picture" : "http://lorempixel.com/400/400/people/1/",
  "title" : "Content Manager"
},
{
  "department" : "Content Management",
  "deskphone" : "+1-234-456-5678",
  "displayname" : "Dian Chough",
  "email" : "dchough@somedomain.com",
  "employee_id" : "5790",
  "firstname" : "Dian ",
  "lastname" : "Chough",
  "location" : "LAX",
  "mobile" : "+1-123-234-5678",
  "picture" : "http://lorempixel.com/400/400/people/7/",
  "title" : "Content Manager"
},
{
  "department": "Content Management",
  "deskphone" : "+1-234-456-6789",
  "displayname" : "Ernie Dangler",
  "email" : "edangler@somedomain.com",
  "employee_id" : "5979",
  "firstname" : "Ernie ",
  "lastname" : "Dangler",
  "mobile" : "+1-123-234-4567",
  "picture" : "http://lorempixel.com/400/400/people/3/",
  "title" : "Content Management Supervisor"
}]

console.log('More Detailed Key Info : ', UniqueKey.getInfoAboutKeys(people))
console.log('Keys with Unique Values : ', UniqueKey.getKeysWithUniqueValues(people))

Example Output

Given the array of objects :

[{
  "department":"Content Management",
  "deskphone" : "+1-234-456-7890",
  "displayname" : "Sherell Marcusen",
  "email" : "smarcusen@somedomain.com",
  "employee_id" : "5819",
  "firstname" : "Sherell ",
  "lastname" : "Marcusen",
  "location" : "LAX",
  "mobile" : "+1-123-234-3456",
  "picture" : "http://lorempixel.com/400/400/people/1/",
  "title" : "Content Manager"
},
{
  "department" : "Content Management",
  "deskphone" : "+1-234-456-5678",
  "displayname" : "Dian Chough",
  "email" : "dchough@somedomain.com",
  "employee_id" : "5790",
  "firstname" : "Dian ",
  "lastname" : "Chough",
  "location" : "LAX",
  "mobile" : "+1-123-234-5678",
  "picture" : "http://lorempixel.com/400/400/people/7/",
  "title" : "Content Manager"
},
{
  "department": "Content Management",
  "deskphone" : "+1-234-456-6789",
  "displayname" : "Ernie Dangler",
  "email" : "edangler@somedomain.com",
  "employee_id" : "5979",
  "firstname" : "Ernie ",
  "lastname" : "Dangler",
  "mobile" : "+1-123-234-4567",
  "picture" : "http://lorempixel.com/400/400/people/3/",
  "title" : "Content Management Supervisor"
}]

a response would look like

{ unique_keys:
   [ 'department',
     'deskphone',
     'displayname',
     'email',
     'employee_id',
     'firstname',
     'lastname',
     'mobile',
     'picture',
     'title',
     'location' ],
  department:
   { is_unique: false,
     all_values:
      [ 'Content Management',
        'Content Management',
        'Content Management' ],
     unique_values: [ 'Content Management' ] },
  deskphone:
   { is_unique: true,
     all_values: [ '+1-234-456-6789', '+1-234-456-5678', '+1-234-456-7890' ],
     unique_values: [ '+1-234-456-6789', '+1-234-456-5678', '+1-234-456-7890' ] },
  displayname:
   { is_unique: true,
     all_values: [ 'Ernie Dangler', 'Dian Chough', 'Sherell Marcusen' ],
     unique_values: [ 'Ernie Dangler', 'Dian Chough', 'Sherell Marcusen' ] },
  email:
   { is_unique: true,
     all_values:
      [ 'edangler@somedomain.com',
        'dchough@somedomain.com',
        'smarcusen@somedomain.com' ],
     unique_values:
      [ 'edangler@somedomain.com',
        'dchough@somedomain.com',
        'smarcusen@somedomain.com' ] },
  employee_id:
   { is_unique: true,
     all_values: [ '5979', '5790', '5819' ],
     unique_values: [ '5979', '5790', '5819' ] },
  firstname:
   { is_unique: true,
     all_values: [ 'Ernie ', 'Dian ', 'Sherell ' ],
     unique_values: [ 'Ernie ', 'Dian ', 'Sherell ' ] },
  lastname:
   { is_unique: true,
     all_values: [ 'Dangler', 'Chough', 'Marcusen' ],
     unique_values: [ 'Dangler', 'Chough', 'Marcusen' ] },
  mobile:
   { is_unique: true,
     all_values: [ '+1-123-234-4567', '+1-123-234-5678', '+1-123-234-3456' ],
     unique_values: [ '+1-123-234-4567', '+1-123-234-5678', '+1-123-234-3456' ] },
  picture:
   { is_unique: true,
     all_values:
      [ 'http://lorempixel.com/400/400/people/3/',
        'http://lorempixel.com/400/400/people/7/',
        'http://lorempixel.com/400/400/people/1/' ],
     unique_values:
      [ 'http://lorempixel.com/400/400/people/3/',
        'http://lorempixel.com/400/400/people/7/',
        'http://lorempixel.com/400/400/people/1/' ] },
  title:
   { is_unique: false,
     all_values:
      [ 'Content Management Supervisor',
        'Content Manager',
        'Content Manager' ],
     unique_values: [ 'Content Management Supervisor', 'Content Manager' ] },
  location:
   { is_unique: false,
     all_values: [ 'LAX', 'LAX' ],
     unique_values: [ 'LAX' ] } }

Keywords

FAQs

Package last updated on 13 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc