Coder Social home page Coder Social logo

filter-objects's People

Contributors

tonybranfort avatar

Stargazers

 avatar

Watchers

 avatar  avatar

filter-objects's Issues

Inherited properties are considered missing; not checked for match

Inherited properties are considered missing; ie, not being checked. This affects both filter and matches. Example:

var props = ["prop1"];
var o = {"prop1":"abc"};
var pObj = Object.create(o); 
var tObj = {"prop1":"abc"};
var f = fos.makeMatchFn(props);
f(pObj, tObj).should.equal(true);    // === > equals FALSE

Depending on your implementation, this may be an issue or may be expected behavior if you don't want inherited properties to be checked.

Inherited properties are considered 'missing' so they match with options matchIfPObjPropMissing, matchIfTObjPropMissing and matchIfBothPropMissing in those respective situations.

getVariablesFn should not be called asynchronously

The getVariablesFn option is a function that takes a callback currently. It should not take a callback as filter-objects is not asynchronous. filter-objects will be modified with a patch version to log a warning if getVariablesFn is not undefined.

The next major version will replace getVariablesFn with variables which will be an object of the form that should be returned by the current getVariablesFn.

Multiple variables on one property may not be replaced correctly

If using variables, the values may not be replaced correctly if you have multiple variables to be replaced in the same property.

      it('it should replace multiple occurrences of different variables', 
        function() {
          // var props = {"prop1":{"variablesInPObj":true,"variablesStartStr":"+"}};
          var props = {
            "prop1":{"variablesInPObj":true,
              "variablesEndStr":"~",
              "variablesStartStr":"+"
            }
          };
          var options = 
            {getVariables:  function(cb) {
              return cb(null, 
              {youngDog: "puppy", youngCat: "kitten", youngSheep:"ewe"}); 
            }};
          var pObj = {"prop1":"+youngDog~WHAT+youngCat~"};   // ISSUE: TWO VARIABLES HERE
          var tObj = {"prop1":"puppyWHATkitten"};
          var f = fos.makeMatchFn(props, options);
          f(pObj, tObj).should.equal(true);               // CURRENTLY RETURNS false
      });

      it('it should replace multiple occurances of different variables', 
        function() {
          // var props = {"prop1":{"variablesInPObj":true,"variablesStartStr":"+"}};
          var props = {
            "prop1":{"variablesInPObj":true,
              "variablesEndStr":"~",
              "variablesStartStr":"~"
            }
          };
          var options = 
            {getVariables:  function(cb) {
              return cb(null, 
              {youngDog: "puppy", youngCat: "kitten", youngSheep:"ewe"}); 
            }};
          var pObj = {"prop1":"~youngDog~WHAT~youngCat~"};   // ISSUE: TWO VARIABLES HERE
          var tObj = {"prop1":"puppyWHATkitten"};
          var f = fos.makeMatchFn(props, options);
          f(pObj, tObj).should.equal(true);           // CURRENTLY RETURNS false
      });

matchIf_ObjPropMissing + regExpMatch can return false positive match

These two options combinations can incorrectly return a positive match if the tObj or pObj is missing respectively:

  • {regExpMatch: true, matchIfTObjPropMissing: false}
  • {regExpMatch: true, regExpReverse: true, matchIfPObjPropMissing: false}

(default for matchIfTObjPropMissing & matchIfPObjPropMissing is false)

Affects both match and filter (makeFilterFn, makeMatchFn).

    it('should return false if a chosen poperty is missing in tObj ' + 
       'including when regExpMatch and pObj has .*',        function() {
          var options = {
            regExpMatch:true, 
            // matchIfTObjPropMissing: false   // default is false
          }; 
          var props = ["prop1",'prop2.cat.tail'];
          var pObj = {"prop1":"abc","prop2":{"cat":{"tail":".*"}}};
          var tObj = {"prop1":"abc","prop2":{"cat":{"nose":"brown"}}};
          var f = fos.makeMatchFn(props,options);
          f(pObj, tObj).should.equal(false);   // IS INCORRECTLY RETURNING true
      });

    it('should return false if a chosen property is missing in pObj ' + 
       'including when regExpMatch, regExpReverse and tObj has .*', 
       function() {
          var options = {
            regExpMatch:true, 
            regExpReverse:true, 
            // matchIfPObjPropMissing: false   // default is false
          }; 
          var props = ["prop1",'prop2.cat.tail'];
          var pObj = {"prop1":"abc","prop2":{"cat":{"nose":"brown"}}};
          var tObj = {"prop1":"abc","prop2":{"cat":{"tail":".*"}}};
          var f = fos.makeMatchFn(props, options);
          f(pObj, tObj).should.equal(false);   // IS INCORRECTLY RETURNING true
      });

Search Through Nested Array Objects

As a user I would love to be able within the array of nested objects to be able to also have this search through arrays of non primitive types, arrays of more nested objects.

IE. [Object: {name: test, colors: [ Object: {first: blue, second: green} ] } ]

This would be really helpful when having complex array of objects within other objects.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.