The package validates provided conditions against provided data. It compares the static data and supports few basic logical operations such as:
- and
- or
- not
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.
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',
}
}
}
}
};