1.0.2 • Published 3 years ago

@futank/pipelines v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago
    npm i @futank/pipelines 
        
        or
    
    yarn add @futank/pipelines
    import { pipeline } from '@futank/pipelines'

    const f1 = (num) => num + 2;
    const f2 = (num) => num * 4;
    const f3 = (num) => num / 2;

    const functions = [f1, f2, f3];
    const options = {
        firstArgument: 2
    }

    const pipelineReturn = pipeline(functions, options);

    console.log(pipelineReturn) // 8

Case you need async functions use asyncPipeline

    import { asyncPipeline } from '@futank/pipelines'
    import axios from 'axios'

    const getPokemonList = async () => {
        const { data } = await axios.get(
            'https://pokeapi.co/api/v2/pokemon?limit=5'
        );
        return data;
    };

    const getPokemonNames = (data) => {
        const { results } = data;
        const names = results.map((result) => result.name);
        return names;
    };

    const functions = [getPokemonList, getPokemonNames];

    const pokemons = await asyncPipeline(functions);

    console.log(pokemons); // [ 'bulbasaur', 'ivysaur', 'venusaur', 'charmander', 'charmeleon' ]