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

@genesislcap/foundation-filters

v14.370.0

Published

Genesis Foundation Filters

Readme

Genesis Foundation Filters

lerna TypeScript

foundation-filters provides a collection of client-side filters, including:

These can be run in isolation or as part of a chain using the runner function.

Client-side filters generally take primitive input parameters, and return true or false based on these values. They may also access runtime data or state to provide an outcome. They can be used for simple tasks like array or input filtering, or for more advanced use cases - such as driving feature flags, behaviors, directives, etc.

Filters can be chained using the utilities provided in this package to handle more complex scenarios. When a filter is used without all the input parameters needed, Genesis logs a warning and returns true by convention so that the chain can continue. This is currently controlled at an individual filter level, and may change in time.

:::important It's important to highlight that filters are purposefully decoupled from any effect, like pairing with a when() directive or custom-effect logic. This flexibility allows these filters to be reused for numerous purposes. :::

Usage

Each filter is provided in two flavours:

  1. Function
import { timeWindowFilter } from '@genesislcap/foundation-filters';
...
const outcome = timeWindowFilter('Sun Sep 25 2022 16:51:55 GMT+0000', 'Fri Nov 25 2022 17:51:55 GMT+0000');
  1. DI Injected
import { TimeWindow } from '@genesislcap/foundation-filters';
...
@TimeWindow timeWindow: TimeWindow;
...
const outcome = this.timeWindow.filter({
  start: 'Sun Sep 25 2022 16:51:55 GMT+0000',
  end: 'Fri Nov 25 2022 17:51:55 GMT+0000',
});

The function version is pretty self-explanatory, and you may be wondering why you would use the DI injected version. The reason is at the point of calling a filter, either directly or indirectly as (say) part of a chain, you may not know what data or state from the application it needs to provide its outcome. The DI versions encapsulate this complexity, which aids later refactoring, and leaves callers free to pass only primitive input parameters where possible.

DI use cases

import { UserTargeting } from '@genesislcap/foundation-filters';
...
@UserTargeting userTargeting: UserTargeting;
...
const outcome = this.userTargeting.filter({
  profiles: ['ADMIN']
});

Here we've used the UserTargeting filter without the need to provide the current user or other data points to the underlying function directly. If we source the current user from changes over time, the author of the filter can refactor centrally.

All DI-based filters implement the ClientFilter interface; however, they may provide other APIs for convenience to abstract underlying implementation details. For example, UserTargeting provides a hasAdminProfile API, so the previous example can be re-written as:

import { UserTargeting } from '@genesislcap/foundation-filters';
...
@UserTargeting userTargeting: UserTargeting;
...
const outcome = this.userTargeting.hasAdminProfile();

This is quite a simplistic example, but we hope it helps to highlight that common parameters can be predefined in the filters themselves where needed. It is also worth mentioning that DI-based filters are registered as transient, meaning you will get a new instance for every dependency request or container.get(). The ClientFilterRunner used to run chained filters is also transient.

Client Filter Runner

A ClientFilterRunner will return true when all the filters in the array pass.

import { ClientFilterRunner } from '@genesislcap/foundation-filters';
...
@customElement({
  name: 'runner-example',
  template: html`
    <template>
      ${when(
        (x) => x.seasonsGreetings,
        html`
          <happy-christmas-chome-users></happy-christmas-chome-users>
        `
      )}
      ${when(
        (x) => x.santasShift,
        html`
          <working-hard-or-hardly-working>Santa!</working-hard-or-hardly-working>
        `
      )}
    </template>
  `,
})
class RunnerExample extends FASTElement {
  @ClientFilterRunner runner: ClientFilterRunner;
  /**
   * This getter will remain reactive to any observable state each filter may use. Filters can be defined with strong
   * typings as shown, or they can be simply loaded in from json files etc. Here we've defined the chain in the element,
   * but you could inject a ClientFilterRunner into a store fragment to centralise and share such logic. Here we're
   * targeting non-admin users on chrome between Christmas and New Year.
   */
  get seasonsGreetings() {
    return this.runner.run([
      {
        name: 'userTargeting',
        parameters: {
          profiles: ['USER'],
        },
      },
      {
        name: 'userAgent',
        parameters: {
          browsers: ['Chrome']
        },
      },
      {
        name: 'timeWindow',
        parameters: {
          start: '2022-12-25',
          end: '2022-12-31',
        },
      }]);
  }

  get santasShift() {
    return this.runner.run([
      {
        name: 'userTargeting',
        parameters: {
          username: ['santa'],
        },
      },
      {
        name: 'timeWindow',
        parameters: {
          start: '2022-12-24',
          end: '2022-12-25',
        },
      }]);
  }
}

Installation

To enable this module in your application, follow the steps below.

  1. Add @genesislcap/foundation-filters as a dependency in your package.json file. Whenever you change the dependencies of your project, ensure you run the $ npm run bootstrap command again. You can find more information in the package.json basics page.
{
  ...
  "dependencies": {
    ...
    "@genesislcap/foundation-filters": "latest"
    ...
  },
  ...
}

API Docs

License

Note: this project provides front-end dependencies and uses licensed components listed in the next section; thus, licenses for those components are required during development. Contact Genesis Global for more details.

Licensed components

Genesis low-code platform