node package manager
Don’t reinvent the wheel. Reuse code within your team. Create a free org »

confer-js

Confer JS

Confer-JS is a tiny library that compares two ordered lists of objects and gives out the matched results.

Installation

 npm install confer-js

Example usage

Using an Object structure

var confer = require('confer-js');
// Given a list of lists
var listOfLists = {
  list1: [{ e: 'element'}, 2, 'anotherElement'],
  list2: [{ e: 'element'}, 1, 'anotherElement'],
  list3: [{ e: 'element'}, 2],
}
 
// We want to find all lists with these elements in this order
var findList = [{ e: 'element'}, 2]
var result = confer(listOfLists, findLists)

Using an Array of Arrays structure

Confer-js also supports an array of array structure, if that is the case, the usage will be as follows:

var confer = require('confer-js');
// Given a list of lists
var listOfLists = [
  [{ e: 'element'}, 2, 'anotherElement'],
  [{ e: 'element'}, 1, 'anotherElement'],
  [{ e: 'element'}, 2]
]
 
// We want to find all lists with these elements in this order
var findList = [{ e: 'element'}, 2]
var result = confer(listOfLists, findLists)

Results

The result will contain a list matching the given data or an empty object or array, depending what was passed to the function:

// When listOfLists is an object.
{
  list1: [{ e: 'element'}, 2, 'anotherElement'],
  list3: [{ e: 'element'}, 2],
}
// When listOfLists is an array.
[
  [{ e: 'element'}, 2, 'anotherElement'],
  [{ e: 'element'}, 2]
]