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

baret.util

v0.3.3

Published

Utilities for working with Baret

Downloads

9

Readme

baret Util · Gitter GitHub stars

A collection of experimental utilities for working with baret.

npm version Build Status Code Coverage

Contents

Reference

This library provides a large number of named exports. Typically one just imports the library as:

import * as U from "baret.util"

Misc

U.seq(value, ...fns) ~> value

U.seq allows one to pipe a value through a sequence of functions. In other words, U.seq(x, fn_1, ..., fn_N) is roughly equivalent to fn_N( ... fn_1(x) ... ). It serves a similar purpose as the ->> macro of Clojure or the |> operator of F# and Elm, for example, or the >| operator defined in a Usenet post by some rando.

For example:

U.seq(1, x => x + 1, x => -x)
// -2

A common technique in JavaScript is to use method chaining: x.fn_1().fn_2(). A problem with method chaining is that it requires having objects with methods. Sometimes you may need to manipulate values that are not objects, like null and undefined, and other times you may want to use functions that are not directly provided as methods and it may not be desirable to monkey patch such methods.

U.seq is designed to work with partially applied curried functions that take the object as their last argument and can be seen as providing a flexible alternative to method chaining.

U.seqPartial(maybeValue, ...fns) ~> maybeValue

U.seqPartial allows one to pipe a value through a sequence of function in such a way that if the value becomes undefined the process is stopped and undefined is returned without calling the remaining functions.

U.scope(() => value) ~> value

U.scope simply calls the given thunk. IOW, U.scope(fn) is equivalent to (fn)(). You can use it to create a new scope at expression level.

For example:

U.scope((x = 1, y = 2) => x + y)
// 3

U.toPartial((...values) => value) ~> (...maybeValues) => maybeValue

U.toPartial takes the given function and returns a curried version of the function that immediately returns undefined if any of the arguments passed is undefined and otherwise calls the given function with arguments.

For example:

U.toPartial((x, y) => x + y)(1, undefined)
// undefined
U.toPartial((x, y) => x + y)(1, 2)
// 3

U.show(value) ~> value

U.show logs the given value to console and returns the value.

U.refTo(settable)(value or null) ~> undefined

U.refTo is designed for getting a reference to the DOM element of a component:

const Component = ({dom = U.variable()}) =>
  <div ref={U.refTo(dom)}>
    ...
  </div>

React calls the ref callback with the DOM element on mount and with null on unmount. However, U.refTo does not write null to the variable. The upside of skipping null and using an initially empty variable rather than an atom is that once the variable emits a value, you can be sure that it refers to a DOM element.

U.cns(...maybeClassName)

U.getProps({prop: settable, ...})

U.setProps({prop: observable, ...})

U.bindProps({ref: eventName, prop: settable, ...})

U.bind({prop: settable, ...})

K

U.template(template of observables)

U.string

U.lift

U.ift(condition, consequent)

U.ifte(condition, consequent, alternative)

U.iftes(condition, consequent, ...[, alternative])

U.actions(...maybeFns)

U.mapCached(x => ..., array)

U.mapIndexed((x, i) => ..., array)

U.indices(array)

U.mapElems((elem, i) => ..., array)

U.mapElemsWithIds(elem => id, (elem, id) => ..., array)

Atom

U.atom(value)

U.variable()

U.molecule(template)

U.holding(() => ...)

U.view(lens, value)

U.set(settable, value)

Bus

U.bus()

U.bus() creates a new observable Bus stream. A Bus stream has the following methods:

  • bus.push(value) to explicitly emit value value,
  • bus.error(value) to explicitly emit error error, and
  • bus.end() to explicitly end the stream after which all the methods do nothing.

baret

TODO: Kefir refereces still here

U.fromKefir()

Context

U.Context

U.withContext

U.WithContext

Kefir

Kefir operations in curried form.

U.changes(observable) ~> observable

U.debounce(milliseconds, observable) ~> observable

U.delay(milliseconds, observable) ~> observable

U.endWith(value, observable) ~> observable

U.mapValue(currentValue => newValue, observable) ~> observable

U.flatMapErrors(error => observable, observable) ~> observable

U.flatMapLatest(value => observable, observable) ~> observable

U.flatMapParallel(value => observable, observable) ~> observable

U.flatMapSerial(value => observable, observable) ~> observable

U.foldPast

U.fromEvents(object, name) ~> observable

U.interval

U.later

U.lazy(() => observable) ~> property

U.never ~> observable

U.on

U.parallel([...observables]) ~> observable

U.sampledBy

U.serially([...observables]) ~> observable

U.sink(observable) ~> observable

U.skipDuplicates(observable) ~> observable

U.skipFirst(count, observable) ~> observable

U.skipUnless(elem => boolean, observable) ~> observable

U.skipWhen(elem => boolean, observable) ~> observable

U.startWith(constant, observable) ~> observable

U.takeFirst(count, observable) ~> observable

U.takeUntilBy

U.throttle(milliseconds, observable) ~> observable

U.toProperty(observable) ~> observable

Ramda

Ramda functions lifted to take Bacon observables.

Math