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

nuclear-transform

v1.0.1

Published

Tiny library for "on the go" nuclearjs getter transformation/reduce

Downloads

9

Readme

nuclear-transform

Dependencies status Build status

Library for Nuclearjs Getter composition. It composes Getters in a way that allows you to transform the data in intermediate steps without multiple round trips through reactor.evaluate method.

Usage

import { transform } from 'nuclear-transform';
import reactor from './reactor';  // your reactor instance
import { getter1, getter2, getter3, keypath1 } from './getters';  // import your Getters and|or keypaths

const firstTransform = transform([
  getter1,
  keypath1,
  getter2,
  // as normal getter; this function gets called with data returned from specified Getters and|or keypaths before it
  // difference is that it can transform the data and return it as the usual getter
  (g1, k1, g2) => {... return someArray },
  // function returned array so we can further transform it
  someArray => { ... return someArray.map(() => ...); },
  // function returns transformed array
  // pull in additional data
  getter3,
  // process transformed array and additional data to get new value
  (mappedArray, g3) => { ... return newValue ) },
  // finally output the desired value
  newValue => newValue.length, // finally return reduced value
]);

// reactor.evaluate(firstTransform)

export default firstTransform;

Nesting composed getters

import firstTransform from './firstTransform'
// import getters and functions...

const secondTransform = transform([
  firstTransform, // reuse transformed getter
  keypath2,  // pull in additional data
  getter4,   // pull in additional data
  func1, //  return value base on fT, k2, g4
  getter5,  // pull in additional data
  getter6,  // pull in additional data
  (f1, g5, g6) => { ….return value on last 3 parameters}, // final result
]);

// reactor.evaluate(secondTransform)

One reactor.evaluate call and you get exactly the data you need. You can combine existing getters and keypaths with universal filter/transform functions to maximize code reuse.

Types allowed in transform list

  • 1st element must be KeyPath or Getter
  • last element must be a function
  • KeyPaths, Getters and functions

Features

  • every function gets the data from KeyPaths and Getters that precede it, including the data from previous function call as parameters
  • functions that transform values share the same context so it's possible to save state/flags between them for more complex decision making
  • since return value is a regular Getter it can be combined inside other transforms

Why?

It simplifies composing Getters that conditionally or dynamically(based on other inputs) return some data.

Composing Getters using nothing else but original Getter syntax can be hard to grasp when you want to get reduced data with just one call to reactor.evaluate. This problem can be solved using multiple approaches, none of which is all that great.

How it works

It puts KeyPaths and Getters on a list until it stumbles on a function. Then it wraps traversed elements to a Getter and sets it as the 1st element of a new Getter that it starts to build. This process repeats until the last function(last item) is reached and we are left with the one "fat" Getter.

Old version

This one had a slightly different approach on composing Getters and can be found here

License

MIT © popc0rn