npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bell-crow/pipe-core

v1.4.2

Published

process data like a pipeline

Downloads

21

Readme

pipe-core

tag license npm version Build Status Coverage Status

What is pipe-core?

process data like a pipeline

How to use?

the test case code

import { createPipeCore } from '@bell-crow/pipe-core';

const _value = {
  name: 'pipe-core',
  age: 1,
  location: () => 'Asia',
  nick: {
    pipe: 1,
    core: 2
  },
  city: [1, 2, 3]
};

const customStartFunction = {
  getName (value: typeof _value) {
    return value.name;
  },
  getDoubleAge (value: typeof _value) {
    return value.age * 2;
  },
  getLocation (value: typeof _value) {
    return value.location();
  },
  getNick (value: typeof _value) {
    return value.nick;
  },
  getCity (value: typeof _value) {
    return value.city;
  },
  getValue (value: typeof _value) {
    return value;
  }
};

const valueCore = createPipeCore(_value, customStartFunction);

test('test createPipeCore case', async () => {
  await valueCore
    .pipeStart()
    .getDoubleAge(doubleAge => {
      expect(doubleAge).toBe(2);
      return doubleAge / 2;
    })
    .pipe<number>(divideAge => {
      expect(divideAge).toBe(1);
    })
    .getName(name => {
      expect(name).toBe('pipe-core');
      return 'changed-pipe-core';
    })
    .pipe<string>(changedName => {
      expect(changedName).toEqual('changed-pipe-core');
    })
    .getCity(city => {
      expect(city).toEqual([1, 2, 3]);
      return city.reverse();
    })
    .pipe<Array<number>>((changedCity, update) => {
      expect(changedCity).toEqual([3, 2, 1]);
      update({ city: [3, 2, 1] });
    })
    .getCity(city => {
      return city;
    })
    .pipe<Array<number>>(city => {
      expect(city).toEqual([3, 2, 1]);
    })
    .getLocation(location => {
      expect(location).toBe('Asia');
    })
    .pipe<unknown>((val, update) => {
      expect(val).toBeUndefined();
      update({ location: () => 'Europe' });
    })
    .getNick(nick => {
      return {
        pipe: nick.core,
        core: nick.pipe
      };
    })
    .pipe<typeof _value['nick']>((nick, update) => {
      expect(nick).toEqual({
        pipe: 2,
        core: 1
      });
      update({ nick: { pipe: 2, core: 1 } });
    })
    .pipeEnd()
    .then(val => {
      const { location, ...otherVal } = val;
      expect(location()).toBe('Europe');
      expect(otherVal).toEqual({
        name: 'pipe-core',
        age: 1,
        nick: {
          pipe: 2,
          core: 1
        },
        city: [3, 2, 1]
      });
    });
});

Have any explain about the usage?

createPipe is a function to create one 'pipe' value. The pipeStart is the pipe start and the pipeEnd is the pipe end.

await value
  .pipeStart()
  /* some process */
  .pipeEnd();

The first parameter is the value. The second parameter is one piece of the pipe to process this value.

createPipe({
  name: 'crow',
  age: 3
}, {
  getValue(value) {
    return { ...value }
  },
  getName(value) {
    return value.name;
  },
  getAge(value) {
    return value.age;
  }
});

The created pipe is one pipeline. We can do some process based on one piece of the pipe called process function. Every process function could provide two parameters. The first is the real-time value. The second is one function can update the value. The process function could provide a function called pipe. It would receive the return value of the process function. And the first pipe's return value would be the parameter of the secord pipe function. The pipe also supports function to update value.

await value
  .pipeStart() // start the pipe
  .getValue(value => {
      console.log(`value is ${JSON.stringify(value)}`);
      return value.name;
  })
  .pipe<string>(name => console.log(`value.name is ${name}`))
  .getValue((_, update) => {
      // update the value, the update is synchronous
      const value = { name: 'bell-crow', age: 1 };
      update(value as typeof _);
      console.log(`change value: ${JSON.stringify(value)}`);
  })
  .getValue(value => console.log(`changed value is ${JSON.stringify(value)}`))
  .pipeEnd()

TODO

  • support for React state