Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Support an "includes" rule type #13

@mayank23

Description

@mayank23

Hola! 😃

It would be nice if flipr supported an "includes" rule type.

For example, a rule which just checks if the value passed to it is included in the extractedInput. Could also create another rule for shallow prop checks in objects , e.g) has.

E.g)

foodPreference:
  values:
    - value: You Like Apples
      food: apple
    - value: You Like Oranges
      food: orange

Rule Definition

{
  type: 'includes',
  input: (input) => input.foodsList,
  propertyName: 'food'
}

execute-rule-includes.js

'use strict';

var _ = require('lodash');

module.exports = executeRuleIncludes;

var MATCH_FOUND = true;

function executeRuleIncludes(input, rule, values, cb) {
  var firstMatch = _.find(values, function(value){
    var property = value[rule.property];
    if(_.isUndefined(property))
      return false;
    return _.includes(input, property);
  });
  if(firstMatch)
    cb(MATCH_FOUND, firstMatch.value);
  else
    cb();
}

Finally, we would need to update

if(!_.isString(result) && !_.isBoolean(result) && !_.isNumber(result))
to allow arrays an maybe assert that an array is returned by the input function for an 'includes' rule.

we can list out the exact semantics in the README for each rule so it's easier to see how values are compared by flipr

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions