Repository URL to install this package:
|
Version:
1.2.1 ▾
|
"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;