generate-compare-function
generate compare function by object paths.
Last updated 2 years ago by hrsh7th .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install generate-compare-function 
SYNC missed versions from official npm registry.

generate-compare-function

generate compare function by object paths.

Note

I created this package.

I hope generate-compare-function is faster than `select with shallow-equals

But real results is no my hopeness ????

So we dont need this package

Sorry, my benchmark script had bug.

I solved this bug, so that made my hoped results.

this package is maybe useful someone!

$ npm run perf

> generate-compare-function@0.0.0 perf /path/to/generate-compare-function
> ts-node ./perf/perf.ts

generate-compare-function x 211,816,366 ops/sec ±1.49% (90 runs sampled)
select function with shallow equals. x 9,756,988 ops/sec ±0.91% (92 runs sampled)
Fastest is generate-compare-function

Usage

generate compare function.

import { generateCompareFunction } from 'generate-compare-function';

const compare = generateCompareFunction([
  ['path', 'to', 'value1'],
  ['path', 'to', 'value2'] // it is not using in this senario. but below senarios works well.
]);

use compare function.

const baseObject = {
  path: {
    to: {
      value1: true
    }
  }
};

const differentObjectAsBase = {
  path: {
    to: {
      value1: false
    }
  }
};

const sameObjectAsBase = {
  path: {
    to: {
      value1: true
    }
  }
};

// true, if passing same object.
expect(compare(baseObject, baseObject)).toBe(true);

// false, if passing different objects thats are not have same value in path to compare.
expect(compare(baseObject, differentObjectAsBase)).toBe(false);

// true, if passing different objects thats are have same value in path to compare.
expect(compare(baseObject, sameObjectAsBase)).toBe(true);

Current Tags

  • 0.0.1                                ...           latest (2 years ago)

1 Versions

  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (13)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |