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

reactabular-resolve

v7.0.0

Published

Data resolution utilities for Reactabular

Downloads

57

Readme

Sometimes your rows might come in a nested format or it might have a representation that maps to the underlying value. A name split to first and last parts is an example of the former. Country code to country mapping is an example of the latter.

API

Reactabular provides resolve module for handling with these cases. The system relies on an iterator that accepts rows and then transforms it using a resolver.

resolve.resolve

({ columns: <columns>, method: <resolver function>}) => <rows> => <rows>

The resolve iterator accepts columns and a method. When applied with rows, it will return resolved rows. A resolver function accepts a function with signature like this: ({ rowData, rowIndex, column }) => <resolved row>.

resolve.index

({ rowData, rowIndex }) => <resolved row>

resolve.index attached rowIndex at _index field of the returned row. This can be handy information to have for optimization purposes (reactabular-tree) but most often you don't have to use this one.

resolve.nested

({ rowData, column }) => <resolved row>

The nested resolver digs rows from a property: 'name.first' kind of definition and maps the received value to property name. It replaces the original value with the resolved one.

resolve.byFunction

(path: <string>) => ({ rowData, column }) => <resolved row>

The byFunction resolver accepts a path from where to look for a resolving function. It could be column.cell.resolve for example and you can use a nested definition for getting it from your column definition.

Instead of replacing the original value, byFunction generates _<property> kind of field to the resulting rows. Other functionality of Reactabular can use this hint and use the underscore field for user facing portions while using actual values for logic that relies on that.

Combining Resolvers

If you want to combine resolvers, you can achieve it like this.

const resolver = resolve({
  columns,
  method: ({ rowData, column }) => byFunction('cell.resolve')({
    rowData: nested({ rowData, column }),
    column
  })
});

Resolution Example

The following example shows how you to resolve nested values.

Example:

/*
import { resolve } from 'reactabular';
*/

const columns = [
  {
    property: 'color',
    header: {
      label: 'Color'
    }
  },
  {
    header: {
      label: 'Name'
    },
    children: [
      {
        property: 'name.first',
        header: {
          label: 'First Name'
        }
      },
      {
        property: 'name.last',
        header: {
          label: 'Last Name'
        }
      }
    ]
  },
  {
    header: {
      label: 'About'
    },
    children: [
      {
        property: 'company',
        header: {
          label: 'Company'
        }
      },
      {
        property: 'sentence',
        header: {
          label: 'Sentence'
        }
      }
    ]
  }
];

const rows = [
  {
    id: 1,
    color: 'red',
    name: {
      first: 'John',
      last: 'Johnson'
    },
    company: 'John Inc.',
    sentence: 'consequatur nihil minima corporis omnis nihil rem'
  },
  {
    id: 2,
    color: 'blue',
    name: {
      first: 'Mike',
      last: 'Mikeson'
    },
    company: 'Mike Inc.',
    sentence: 'a sequi doloremque sed id quo voluptatem voluptatem ut voluptatibus'
  }
];

<ul>{
  resolve.resolve(
    { columns, method: resolve.nested }
  )(rows).map((d, i) =>
    <li key={`value-${i}`}>{JSON.stringify(d, null, 2)}</li>
  )
}</ul>

See Also