@withvoid/melting-pot
Version:
A react utility library
22 lines (18 loc) • 559 B
JavaScript
/**
* @description Takes in an array of functions, pipes their result
* @example pipe('Adeel Imran', onCapital, onRemoveSpaces); // ADEELIMRAN
* @param {...any} funcs
* @returns String
* @author Adeel Imran
*/
const initialState = {
value: '',
toPipe: [() => {}],
};
const pipe = ({ value = initialState.value, toPipe = initialState.toPipe } = initialState) => {
if (typeof value !== 'string') {
throw Error('Function pipe() Should be a string only');
}
return toPipe.reduce((result, cf) => cf(result), value);
};
export default pipe;