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

wasmuth

v2.1.0

Published

Practical, functional utilities that fallback on native implementations as much as possible

Downloads

37

Readme

wasmuth

Build Status

Practical, functional utilities that fallback on native implementations as much as possible.

Why?

I love Ramda. But, some of the naming/semantics is not obvious for those newer to functional programming. Also, filesize (~7kb vs ~50kb 😵). Also, why not fallback to native implementations? Any performance concerns are not actually a bottleneck, and JavaScript VMs will continue to optimize these (map, filter, reduce, some etc.). Also, let me iterate objects without using a differently named export. And, finally, Ramda has a lot of extra functions I never used.

API

Every function is curryable. If it takes 2 arguments and you give it 1, it will return a partially applied function that expects only the 2 argument.


chunk

chunk(len: Number, input: Array): Array

Group an array into smaller arrays.

import chunk from '@wasmuth/chunk'
chunk(2, ['a', 'b', 'c', 'd'])
// => [['a', 'b'], ['c', 'd']]

Source Tests


compose

compose(fnN: Function, ..., fn1: Function): Function

Perform right-to-left function composition. That is, the value of each function (starting on the right), is passed to the next function.

import compose from '@wasmuth/compose'

compose(
  map(n => n + 1),
  Object.values
)({a: 1, b: 2, c: 3})
// => [2, 3, 4]

Source Tests


filter

filter(predicate: Function, input: Array|Object): Array|Object

import filter from '@wasmuth/filter'
const predicate = a => a % 2 === 0
filter(predicate, [1, 2, 3, 4]) // => [2, 4]

You can also filter over objects:

import filter from '@wasmuth/filter'
filter((val, key) => key === 'a' || val === 2, {a: 1, b: 2, c: 3})
// => {a: 1, b: 2}

Source Tests


find

find(predicate: Function, ls: Array): Array|undefined

It returns undefined or the first element of ls satisfying predicate.

import find from '@wasmuth/find'
find(v => v === 'a', ['b', 'a', 'd', 'c'])
// => 'a'

Source Tests


find-index

findIndex(predicate: Function, ls: Array): Array|undefined

It returns undefined or the first index of an element satisfying predicate.

import findIndex from '@wasmuth/find-index'
find(v => v === 'a', ['b', 'a', 'd', 'c'])
// => 1

Source Tests


from-pairs

fromPairs(ls: Array): Object

import fromPairs from '@wasmuth/from-pairs'
fromPairs([['a', 1], ['b', 2]])
// => {'a': 1, 'b': 2}

Source Tests


group-by

groupBy(prop: String, ls: Array): Object

Gather objects based on their value of prop.

import groupBy from '@wasmuth/group-by'
const src = [{a: 1, b: 1}, {a: 1, b: 2}, {a: 2, b: 3}]
groupBy('a', src)
// => {1: [{a: 1, b: 1}, {a: 1, b: 2}], 2: [{a: 2, b: 3}]}

Source Tests


group-prop-by

groupPropBy(valProp: String, prop: String, ls: Array): Object

Gather the value of valProp from each object based on their value of prop.

import groupPropBy from '@wasmuth/group-prop-by'
const src = [{a: 1, b: 1}, {a: 1, b: 2}, {a: 2, b: 3}]
groupPropBy('b', 'a', src)
// => {1: [1, 2], 2: [3]}

Source Tests


includes

includes(search: Any, input: String|Array): Boolean

Just a curryable wrapper that maps to either:

Array.prototype.includes
String.prototype.includes
import includes from '@wasmuth/includes'
includes('c', ['a', 'b', 'c', 'd'])
// => true

Source Tests


join

join(delim: String?, arr: Array): String

Curryable wrapper around native Array.prototype.join.

import join from '@wasmuth/join'
const arr = ['a', 'b', 'c', 'd']

join(arr)
// => 'a,b,c,d'

join()(arr)
// => 'a,b,c,d'

join('-', arr)
// => 'a-b-c-d'

Source Tests


last

join(arr: Array): Any

Return the last element of the given array.

import last from '@wasmuth/last'
const arr = ['a', 'b', 'c', 'd']

last(arr)
// => 'd'

Source Tests


map

map(mapFn: Function, input: Array|Object): Array|Object

Returns the result of calling mapFn on each element in the iterable input. Can be an Array or Object.

import map from '@wasmuth/map'

const double = x => x * 2

map(double, [1, 2, 3])
// => [2, 4, 6]

map((key, val) => key === 'a' ? double(val) : val, {a: 1, b: 2})
// => {a: 2, b: 2}

Source Tests


path

path(path: String|Array, obj: Object): Any

Return the value at the given path, for a given object or array.

import path from '@wasmuth/path'
const obj = {a: {b: 2}}

path(['a', 'b'], obj)
// => 2

path('a.b', obj)
// => 2

Source Tests


path-eq

pathEq(path: String|Array, val: Any, obj: Object): Boolean

Check if the value at a given path, for a given object equals val.

import pathEq from '@wasmuth/path-eq'
const obj = {a: {b: 2}}

pathEq(['a', 'b'], 2, obj)
// => true

pathEq('a.b', 4, obj)
// => false

Source Tests


path-or

pathOr(def: Any, path: String|Array, obj: Object): Any

Return the value at the given path, for a given object or array, or def if falsy.

import pathOr from '@wasmuth/path-or'
const obj = {a: {b: 2}}

pathOr(5, ['x', 'y'], obj)
// => 5

pathOr(11, 'a.b', obj)
// => 2

Source Tests


path-remove

pathRemove(path: String|Array, obj: Object): Any

Remove the value at the given path, for a given object or array.

import pathRemove from '@wasmuth/path-remove'
const obj = {a: {b: 2, c: 3}}

pathRemove(['a', 'b'], obj)
// => {a: {c: 3}}

Source Tests


path-set

pathSet(path: String|Array, def: Any, obj: Object): Any

Set the value on a given path for a given object.

import pathSet from '@wasmuth/path-set'
const obj = {a: {b: 1}}

pathSet(['a', 'b'], 2, obj)
// => {a: {b: 2}}

pathSet('a.b', 3, obj)
// => {a: {b: 3}}

pathSet('0.a.b', 3, [obj])
// => [{a: {b: 3}}]

Source Tests


path-update

pathUpdate(path: String|Array, value: any, obj: Object): Any

Update the value on a given path for a given object.

If the existing path target and the new value are both arrays, concat the value. If the existing path target and the new value are both objects, merge the value.

import pathUpdate from '@wasmuth/path-update'
const obj = {a: {b: 1, c: [10, 20]}}

pathUpdate('a', {d: 2}, obj)
// => {a: {b: 1, c: [10, 20], d: 2}}

pathUpdate('a.b', 3, obj)
// => {a: {b: 3, c: [10, 20]}}

pathUpdate('a.c', 30, obj)
// => {a: {b: 1, c: 30}}

pathUpdate('a.c', [30], obj)
// => {a: {b: 1, c: [10, 20, 30]}}

Source Tests


pick

pick(keys: Array, obj: Object): Object

Return obj with only the keys specified.

import pick from '@wasmuth/pick'

pick(['a', 'c'], {a: 1, b: 2, c: 3})
// => {a: 1, c: 3}

Source Tests


pipe

pipe(fn1: Function, ..., fnN: Function): Function

Perform left-to-right function composition. That is, the value of each function (starting on the left), is passed to the next function.

import pipe from '@wasmuth/pipe'

pipe(
  Object.values,
  map(n => n + 1)
)({a: 1, b: 2, c: 3})
// => [2, 3, 4]

Source Tests


range

range(from: Number, to: Number): Array

Returns a list of numbers from from (inclusive) to to (exclusive).

import range from '@wasmuth/range'
range(0, 6)
// => [0, 1, 2, 3, 4, 5]

Source Tests


reduce

reduce(fn: Function, initVal: Any, arr: Array): Any

Curryable wrapper around native Array.prototype.reduce.

import reduce from '@wasmuth/reduce'
const arr = [1, 2, 3, 4]

reduce((acc, elm) => acc + elm, 0, arr)
// => 10

reduce((acc, elm) => acc + elm, 0)(arr)
// => 10

reduce((acc, elm) => acc + elm)(0)(arr)
// => 10

Source Tests


to-pairs

toPairs(obj: Objectr): Array

import toPairs from '@wasmuth/to-pairs'

toPairs({a: 1, b: 2, c: 3})
// => [['a', 1], ['b', 2], ['c', 3]]

Source Tests