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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@dev-vortex/rule-decision

v1.0.0

Published

Rule Decision Library

Downloads

8

Readme

Rule Decision Library

This library aims to provide an agnostic and reliable mechanism to decide the applicable value based on defined rules given at a specific moment.

Installation

yarn add @dev-vortex/rule-decision

or

npm install @dev-vortex/rule-decision

Rule definition

A rule RuleCase is composed by:

| Attribute | Description | Default | |:---------:|:------------|:-------:| |validation|Key/Value object where the key represents the validator name and the value is the expected value to validate|| |active|(Optional) boolean value, when false it will set the current case as inactive|undefined| |cases|(optional) An array of RuleCase object type. This will set the sub-rules to be checked.|undefined| |resolve|(optional) The return value in case the case is valid (if not defined the service will return true)|true|

Validators

A validator is a callable function that will return the value to validate.

The return value will be verified against the expected value set in the rule.validation object

Quick Start

  1. Prepare the validator functions to provide them to the validation service function
import type { ValidatorSet } from '@dev-vortex/rule-decision'

...

const getValidators = (values: Record<string, any>): ValidatorSet => ({
   currentMarket: () => values.market || undefined,
   currentCountry: () => values.country || undefined,
   isCreditCard: () => values.cardNumber.indexOf('3') === 0,
   isMastercard: () => values.cardNumber.indexOf('35') === 0,
   isVisa: () => values.cardNumber.indexOf('34') === 0,
})
  1. Define youur rules
import type { RuleCasesCollection } from '@dev-vortex/rule-decision'

...

const creditCardAcceptanceSimple: RuleCasesCollection = [
   {
       active: false,
       validation: { isCreditCard: false },
       resolve: { fee: 0.5 },
   },
   {
       validation: { currentCountry: 'NO', isVisa: true },
       resolve: { availability: false },
   },
   {
       validation: { currentCountry: 'NO', isMastercard: true },
   },
   {
       validation: { currentMarket: 'EU', isMastercard: true },
       resolve: { fee: 0.01 },
   },
   {
       validation: { currentCountry: 'SE', isMastercard: true },
       resolve: { fee: 0.02 },
   },
   {
       validation: { isMastercard: true },
       resolve: { fee: 0.03 },
   },
   {
       validation: { isVisa: true },
       resolve: { fee: 0.04 },
   },
   {
       validation: { isCreditCard: true },
       resolve: { fee: 0.05 },
   },
]
  1. When needed, call the validation service providing the rule collection and the validator set.
import { decideOn } from '@dev-vortex/rule-decision'

...

const decision = decideOn(
    creditCardAcceptanceSimple,
    getValidators({
        market: 'EU',
        cardNumber: '3546367126490263',
    }),
)
  1. Check if the decision is valid (true) or just use the resolved value for the first found case.

How to prepare/read the rule correction

The service will check your collection top to bottom and it will stop on the first successfully validated case.

For this reason, the rule priority matters. and the returned value will either be the resolve value present in the case or the value true (showiing that a case was found).

Any case with active attribute as false will be ignored.

If sub-cases are present in a valiid parent-case, the service will follow and check them returning the resolve value from the validated rule/sub-case.

If the sub-case does not have a resolve value set, the service will return the parent resolve value or true if none exist.