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 🙏

© 2026 – Pkg Stats / Ryan Hefner

focalize

v0.2.3

Published

A functional lens framework for JavaScript

Readme

Focalize

Functional Lenses for Javascript

Focalize provides a composable set of functionality to handle immutable data updates.

Example

In order to update state immutably we might use the object spread operator and map / reduce over arrays as follows:

// vanilla-reducer.js
export const reducer = (state = {}, action) => {
  switch (action.type) {
    case 'FIRE':
      return {
        ...state,
        departments: (state.departments || []).map(department => ({
          ...department,
          employees: (department.employees || []).map(employee =>
            (employee.staffId === event.staffId) ? ({
              ...employee,
              terminated: true
            }) : employee)
        }))
      });
    default:
      return state;
  }
};

Focalize increases readibility by providing a composable API that can be used to both query and update data immutably. The same example using Focalize becomes.

// lensed-reducer.js
import { prop, select, every, compose } from 'focalize';

export const reducer = (state = {}, action) => {
  switch (action.type) {
    case 'FIRE':
      return compose(
        prop('terminated'),
        select(employee => employee.staffId === event.staffId),
        prop('employees'),
        every(),
        prop('department')
      ).set(state, true);
    default:
      return state;
  }
};

Also note that in the top example if the employee does not exist or is already terminated we still end up with a new state object.

Focalize performs updates economically, we retain the existing objects if no changes are required, and hence we can use state === result to check for changes.

import { reducer as lensedReducer } from './lensed-reducer';

const state = {
  departments: [
    {
      name: 'Research',
      employees: [
        {
          staffId: '101',
          name: 'Francis',
          terminated: false
        },
        {
          staffId: '123'
          name: 'Bob',
          terminated: true
        }
      ]
    }
  ]
};

// Bob already terminated, no changes required
assert(lensedReducer(state, {
  type: 'FIRE',
  staffId: '123'
}) === state); // => OK!

For more examples see the test folder for basic and advanced usage as well as usage for each operator.

References