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

immfacet

v2.2.0

Published

Faceting library for Immutable.JS collections

Downloads

42

Readme

Immfacet

Simple faceting library for Immutable.js collections on the server or in the browser. Intended for use in applications with small-ish datasets that do not necessarily need (or cannot run) search engines like Lucene, Solr, ElasticSearch, etc. If you need to do anything complicated, you should use one of those.

Other JavaScript faceting libraries are typically coupled with visual components and DOM event interaction. Immfacet makes no assumptions about the kind of faceted browsing system you intend to implement.

Example

const { FacetedClassification } = require('immfacet');

const data = Immutable.fromJS([
  {
    name: 'Diz',
    instrument: 'saxophone',
    sessions: ['a', 'b', 'c']
  },
  {
    name: 'Bird',
    instrument: 'trumpet',
    sessions: ['a', 'b', 'c']
  },
  {
    name: 'Buddy',
    instrument: 'drums',
    sessions: ['c']
  },
  {
    name: 'Monk',
    instrument: 'piano',
    sessions: ['c']
  }
]);

const fc = FacetedClassification(data);

Simple faceting based on fields

fc
  .addFieldFacet('sessions')
  .facets()
/* =>
Immutable.Map({
  sessions: {
    'a': Immutable.Set([
      Immutable.Map({ name: 'Diz', ... }),
      Immutable.Map({ name: 'Bird', ... }),
    ]),

    'b': Immutable.Set([
      Immutable.Map({ name: 'Diz', ... }),
      Immutable.Map({ name: 'Bird', ... }),
    ]),

    'c': Immutable.Set([
      Immutable.Map({ name: 'Diz', ... }),
      Immutable.Map({ name: 'Bird', ... }),
      Immutable.Map({ name: 'Buddy', ... }),
      Immutable.Map({ name: 'Monk', ... }),
    ])
  }
})
*/

Arbitrary faceting functions

const windInstruments = ['saxophone', 'trumpet', 'flute', 'tuba']

fc
  .addFacet('playsWindInstrument', person =>
    windInstruments.indexOf(person.get('instrument') !== -1)
  .facets()
  .get('playsWindInstrument')
/* =>
Immutable.Map({
  true: Immutable.Set([
    Immutable.Map({ name: 'Diz', ... }),
    Immutable.Map({ name: 'Bird', ... }),
  ]),

  false: Immutable.Set([
    Immutable.Map({ name: 'Buddy', ... }),
    Immutable.Map({ name: 'Monk', ... }),
  ])
})
*/
// => { 'true': [1, 2], 'false': [3, 4] }

Faceted Classification API

const fc = FacetedClassification(dataset);

Create a new faceted classification. Dataset must be an instance of an Immutable.Iterable, and every object must be an Immutable.Map with an idField key present.

Creating new facet collections

fc.addFacet(facetName, classifyingFn, opts={ multiValue: false })

Create a new facet collection which will have a facet field with name facetName whose values will be determined by running classifyingFn against every item in the dataset. If multiValue is set to true, results will be treated as iterables, with each value in the iterable a facet value.

fc.addFieldFacet(field, opts={})

Shortcut for adding a new facet based on a field name in the item. Takes the same opts as addFacet.

fc.removeFacet(facetName)

Remove facet with name facetName if it exists.

Retrieving data

fc.facets()

Get the values of each facet field, along with the items they are present in.

Faceted Query API

const fq = FacetedQuery(fc)

Create a new faceted query based off a FacetedClassification.

Creating new facet queries

fq.select({ facetName, values })

Create a new facet collection whose results must match the given values for the facet facetFieldName. Will throw an error if facetFieldName is not an initialized facet field.

fq.deselect({ facetName, values })

The inverse of fq.select. If there is no applied filter that matches the parameters exactly (after values has been converted to an Immutable sequence), then an identical facet collection will be returned.

fq.reset(facetName?)

If passed a field name, clear any selections that have been set for that facet field. If not passed a field name, clear all selections for all facets.

Retrieving data

fq.selectedFacets()

Get the values of each facet field, along with the items they are present in after all selections have been applied. Without any selections, this will return the same value as fc.facets() for the faceted collection that fq is based on.

Get the values of each facet field, along with the items they are present in,

fq.selectedFacetValues()

Get the currently selected facet values for the facet collection (as set with fq.select).

fq.selectedItems()

Get the items matched by the currently applied selections. Without any selections, this will return all items.

License

MIT