
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
case-match
Advanced tools
JavaScript case matching utility. With TypeScript support.
The match function takes a value, and a list of cases, and returns either the first case that matches, or an exception otherwise.
import match from 'case-match';
const type = 'foo';
const result = match(type, {
foo: 42,
bar: 43,
baz: 44,
});
result === 42;
A case result can be either a plain value, or a function:
const fruit = 'orange';
const result = match(fruit, {
apple: 'Apple Pie',
orange: () => 'Orange Juice',
});
result === 'Orange Juice';
A default case can be specified as fallback. A special symbol match.default is available to use as the key for the default case.
const fruit = 'pear';
const result = match(fruit, {
apple: 'Apple Pie',
orange: 'Orange Juice',
[match.default]: fruit => processOther(fruit),
});
If no case matches, and no fallback is given, an exception is thrown.
You can create your own custom match function. For example, let's say we have a React application that makes use of actions that conform to the Flux Standard Action (FSA) protocol. We could create a matcher as follows:
import { matcher } from 'case-match';
const match = matcher(subject => ({
discriminator: subject.type,
body: subject,
}));
const action = { type: 'CREATE_USER', error: false, payload: { name: 'John' } };
const result = match(action, {
CREATE_USER: ({ error, payload }) => doSomethingWith(payload),
});
We supply a couple of common matchers out of the box:
match: generic matchermatchType: match on objects with a type propertymatchSingleKey: match on objects with a single property, e.g. { MY_TYPE: { value: 42 } }import { matchType, matchSingleKey } from 'case-match';
const action = { type: 'CREATE_USER', error: false, payload: { name: 'John' } };
matchType(action, {
CREATE_USER: ({ error, payload }) => doSomethingWith(payload),
});
matchSingleKey({ CREATE_USER: { name: 'John' } }, {
CREATE_USER: user => doSomethingWith(user),
});
FAQs
JavaScript case matching library.
The npm package case-match receives a total of 5 weekly downloads. As such, case-match popularity was classified as not popular.
We found that case-match demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.