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

@hgargg-0710/flow

v0.0.1

Published

'flow' is a small JavaScript library containing some methods for organizing code with mutating functions in a particular way.

Downloads

4

Readme

flow

'flow' is a tiny library of (effectively) 2 functions that embodies a very basic, but beautiful way of writing and organizing code involving impure functions in a more "composite" fashion.

Ofttimes, one wants to alter the same state several different times:

const object = {
	... // whatever
}

object.a = ... // whatever
object.b = ... // whatever

Define a 'flow', then, as a sequence of nested function calls that allows primitives and two types of functions to be used:

  1. Pure functions (return values dependent only on the arguments, without any side effects)
  2. "Flow"-functions (may have side effects, but must return one of their initial arguments back)

The above code as a 'flow':

const p = (x, p, v) => {
	x[p] => v
	return x
}
p(p({...}, "a", ...), "b", ...)

By utilizing the two, one is able to split one's code (however complex) into multiple different flows, each of which works with a separate set of (possibly) related objects.

In certain applications (such as DOM-manipulation, or other OO APIs), usage of this style may come in very handy indeed, and greatly reduce redundancies and decrease complexity.

The library contains two primary functions for conversion from a "regular" mutating function into a 'flow'-one, as well as some few cases of application of these two functions...

Installation

npm install @hgargg-0710/flow

Documentation

Functions

function convert(f: Function, i?: number): Function

The function to be converted into a "flow" one. The i'th argument is its return value. (By default, i = 0)

NOTE: the function has a (minor) flaw - its produce takes 2 stack frames instead of 1 to complete. May be solved in future releases/alternative provided.

function flow(params: (Function | [Function, number])[]): Function[]

Uses 'convert' on all the values of params, returns array of converted functions.

Submodules

object

function prop(object: object, property: number | string | symbol, value: any): object

A flow-function that sets property on object Returns the object argument.

dom

NOTE: the following functions are only available in a browser context.

function appendparent(element: Element, children: (Node | string)[]): Element

Flow-version of Element.append. Returns element.

function append(element: Element, children: (Node | string)[]): (Node | string)[]

Flow-version of Element.append. Returns children.

function create(document: Document) => (tagName: string, options: object) => Element

Returns a functional version of document.createElement (the resulting function is bound to 'document').

function attribute(element: Element, name: string, value: string) => Element

Flow-version of Element.setAttribute. Returns the initial element.

function text(document: Document) => (data: string) => Text

Returns a functional version of Document.createTextNode (bound to document).

function remove(element: Node, child: Element) => Node

Flow-version of Node.removeChild. Returns element.

function clear(element: Node) => Node

A flow function that removes all the children of element.

function query(x: Element) => (q: string) => Element | null

Returns the first descendant of x satisfying the CSS selector q. (Funcitonal analogue of Element.querySelector)

function mquery(x: Element) => (q: string) => NodeList

Returns the first descendant of x satisfying the CSS selector q. (Funcitonal analogue of Element.querySelector)