@atlassian/forge-conditions
TypeScript icon, indicating that this package has built-in type declarations

0.3.3 • Public • Published

Forge conditions

The package validates provided conditions against provided data. It compares the static data and supports few basic logical operations such as:

  • and
  • or
  • not

How to use

Import doesMeetConditions and invoke it with two arguments to get a boolean result:

doesMeetConditions({}, {}) // true
doesMeetConditions({}, { isAdmin: false }) // true, no conditions
doesMeetConditions({ isAdmin: true }, { isAdmin: false }) // false, condition requires an admin

Where the first argument defines what conditions have to be met, and the second one is a static data.

In case a top-level operation isn't specified, the and operation is applied. It may be changed by specifying another operation though.

A full example of usage

import { doesMeetConditions } from '@atlassian/forge-conditions';

const conditions = {
  isLoggedIn: true,
  or: {
    isAdmin: true,
    anotherProp: ['this', 'or', 'whatever'],
  }
};

const staticContext = {
  isLoggedIn: true,
  isAdmin: false,
  anotherProp: 'this',
};

// true, because isLoggedIn matches and one of the `or` conditions matched as well
doesMeetConditions(conditions, staticContext);

All supported operations can be nested if needed:

const conditions = {
  or: {
    isLoggedIn: true,
    not: {
      anotherProp: ['O_GOD_NOT_THIS_OH_NO_HELP_NOOOOOO'],
      and: {
        isAdmin: true,
        not: {
          issueType: 'Bug',
        }
      }
    }
  }
};

Readme

Keywords

none

Package Sidebar

Install

npm i @atlassian/forge-conditions

Weekly Downloads

2

Version

0.3.3

License

SEE LICENSE IN LICENSE.txt

Unpacked Size

27.5 kB

Total Files

22

Last publish

Collaborators

  • atlassianartifactteam