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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@alpaca-travel/object-assign-reducer

v1.0.4

Published

[![Build Status](https://travis-ci.com/AlpacaTravel/object-assign-reducer.svg?branch=master)](https://travis-ci.com/AlpacaTravel/object-assign-reducer)[![Coverage Status](https://coveralls.io/repos/github/AlpacaTravel/object-assign-reducer/badge.svg?branc

Readme

Object Assign Reducer

Build StatusCoverage StatusMIT

A "hideous" utility to reduce an object assignment of properties into a new state.

This exists for a use case where you wish to apply an object property and automatically remove or update other properties based on a set of rules. In this case, we need to be able to target a number of conditions, such as describing edge-cases and compatible states to apply a criteria based on the resulting object.

A couple of special things:

  • If the supplied rule matches, but then does not transition the object away from a match, it will throw an error
  • Rules are applied continually until there is no further state transitions
const { assign } = require("@alpaca-travel/object-assign-reducer");

// State before
const state = {
  category: "eat",
  subCategory: "restaurant",
  tags: ["tag1"],
};
// Changing state
const changeState = { category: "stay" };

// We want to eliminate the subcategory on change

// Traditional assign has not subtle rules
// Object.assign({}, state, apply);
// { category: stay, subCategory: restaurant }

// Describing rules as collections of match/perform
const rules = [
  {
    // Setup a matching rules to take the before value, and the after value
    // Return true when we want to match against this rule
    match: (before, after) =>
      // Category does has changed
      before.category !== after.category &&
      // Has a subcategory
      before.subCategory &&
      after.subCategory,

    // Perform a modification to the object
    perform: (obj) => {
      // Poor mans clone
      const val = JSON.parse(JSON.stringify(obj));
      delete val.subCategory;
      return val;
    },
  },

  // ... More rules added here
];

const value = assign({ rules })(state, changeState);
// { category: 'stay' }

Fexp-js Lang Feature

This is as a complete language enhancement for fexp-js scripting

const { parse, langs } = require("@alpaca-travel/fexp-js");
const stdLang = require("@alpaca-travel/fexp-js-lang");
const {
  lang: newLangFeatures,
} = require("@alpaca-travel/object-assign-reducer");

// Define this in YAML/JSON, and can be external to your application code
const expr = [
  "reducer-assign",
  // Matcher function
  [
    "fn",
    [
      // All conditions are true in order to perform this action
      "all",
      // Categories don't match
      // fn-arg 0 = before
      // fn-arg 1 = after
      [
        "!=",
        ["get", "category", ["fn-arg", 0]],
        ["get", "category", ["fn-arg", 1]],
      ],
      // They have sub-categories
      ["exists", ["get", "subCategory", ["fn-arg", 0]]],
      ["exists", ["get", "subCategory", ["fn-arg", 1]]],
    ],
  ],
  // Action to remove the sub category
  ["fn", ["remove", "subCategory"]],

  // ... more can go here

  // The context of the second argument
  ["fn-arg", 1],
];

// Fn now contains all the rules
const fn = parse(expr, langs(stdLang, newLangFeatures));

// State before
const state = {
  category: "eat",
  subCategory: "restaurant",
  tags: ["tag1"],
};
// Changing state
const changeState = { category: "stay" };

const result = fn(state, changeState);

// { category: 'eat', tags: ['tag1'] }