@atlassian/forge-conditions
v0.3.5
Published
Support conditions in the forge apps
Readme
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 adminWhere 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',
}
}
}
}
};