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

@muhammadkasim/xformer

v1.0.12

Published

xFormer provides an extensive set of utilities, a way to define declarative transformation pipelines and a parser to facilitate easier data transformations.

Downloads

18

Readme

XFormer: Easier Data Transformations

XFormer makes data transformations easy on your cognition and hassle-free.

Read complete docs here.

Features

  • Provides an intuitive way to express transformation pipelines
  • Supports a flexible palette of actions
  • Provides 2 ways of describing an action: a string or JSON

Installation

npm i @muhammadkasim/xformer --save

Usage

With Xformer, you can execute a simple pipeline of actions by providing a list of action descriptions to the executePipe method on the imported instance.

import X from '@muhammadkasim/xformer';

const mock_data = [{ a: 1 }, { a: 2 }, { b: 3 }];
X.executePipe(['mergeWithAdd', 'getAvg'], mock_data);

// Returns an object containing the result of executing the pipeline and the
// corresponding result of each step.
// {
//   buffer: [
//     { data: [{a: 1}, {a: 2}, {b: 3}], title: 'Original Data' },
//     { data: {a: 3, b: 3}, title: 'mergeWithAdd' },
//     { data: 3, title: 'getAvg' }
//   ],
//   result: 3
// }

An action can be described either as a string or JSON.

X.executePipe([{ name: 'pickByRegex', params: ['a'] }, 'getAvg'], mock_data); //=> 1.5

Xformer also provides a short hand for passing params when describing an action in string form.

X.executePipe(['pickByRegex(a)', 'getAvg'], mock_data); //=> 1.5

You can perform also perform multiple actions on the same data.

X.executePipe(
  [
    ['pickFrom([0, "a"])', 'pickFrom([2, "b"])'], //=> [1, 3]
    'getAvg'
  ],
  mock_data
); //=> 2

If you need to pass some external values to assist execution of the pipe, you can do so like shown below.

X.executePipe(['mergeWithAdd', 'getRate($.interval)'], mock_data, { interval: 30 }); //=> {a: 0.1, b: 0.1}

You can also group and execute multiple pipelines on the same data. This group of pipelines is called a query and can be a list of pipelines or a JSON structure where value in each key-value pair is a pipeline.

X.execute(
  {
    avg_by_key: ['mergeWithAdd', 'getAvg'],
    rate_by_30: ['mergeWithAdd', 'getRate($.interval)']
  },
  mock_data
);

// Takes a query and data as input and executes all pipelines within the query, with
// each pipeline receiving the provided data.
// {
//     avg_by_key: {
//         buffer: [
//           { data: [{a: 1}, {a: 2}, {b: 3}], title: 'Original Data' },
//           { data: {a: 3, b: 3}, title: 'mergeWithAdd' },
//           { data: 3, title: 'getAvg' }
//         ],
//         result: 3
//     },
//     rate_by_30: {
//         buffer: [
//           { data: [{a: 1}, {a: 2}, {b: 3}], title: 'Original Data' },
//           { data: {a: 3, b: 3}, title: 'mergeWithAdd' },
//           { data: {a: 0.1, b: 0.1}, title: 'getRate($.interval)' }
//         ],
//         result: {a: 0.1, b: 0.1}
//     }
// }