Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/modules / ___dist / chain-able / lego / makeShape.js
Size: Mime:
"use strict";

const toTestable = require("../src/deps/cast/toFunction");

const keys = require("../src/deps/util/keys");

const preAllocate = require("../src/deps/array/preAllocate");

const forOwn = require("../src/deps/loop/each/forOwn");
/**
 * @param {Object} shape @alias specificationTransformations
 * @return {Object} shape creation
 */


const makeShape = shape => {
  const shapeKeys = keys(shape);
  const specifications = preAllocate(shapeKeys);

  const iteratee = (key, index) => {
    specifications[index] = {
      satisfies: (x, prop) => {
        // shapeKeys[key]
        return toTestable(key)(prop);
      },
      transform: shape[key]
    };
  };

  forOwn(shapeKeys, iteratee);

  const shaped = (value, key) => {
    let evolved = false;
    forOwn(specifications, specification => {
      const transform = specification.transform,
            satisfies = specification.satisfies;

      if (satisfies(value, key)) {
        evolved = transform(value, key); // stop iterating - unless we want multiple transforms...
        // return false
      }
    });
    return evolved;
  };

  return shaped;
};

makeShape.makeShape = makeShape;
module.exports = makeShape;