
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
inlineswitch
Advanced tools
A flexible inline switch statement with pattern matching for TypeScript/JavaScript
A flexible inline switch statement with pattern matching for TypeScript/JavaScript.
npm install inlineswitch
import { inlineSwitch } from "inlineswitch";
const result = inlineSwitch(
value,
[
[5, (v) => `Exact match: ${v}`],
[[1, 2, 3], (v) => `Array match: ${v}`],
[(v) => v > 10, (v) => `Predicate match: ${v}`],
],
(v) => `Default: ${v}` // Optional default handler
);
// Exact value matching
const dayName = inlineSwitch(
dayNumber,
[
[0, () => "Sunday"],
[1, () => "Monday"],
[2, () => "Tuesday"],
[3, () => "Wednesday"],
[4, () => "Thursday"],
[5, () => "Friday"],
[6, () => "Saturday"],
],
() => "Invalid day"
);
// Array matching
const fruitCategory = inlineSwitch(
fruit,
[
[["apple", "pear"], () => "pome"],
[["peach", "plum", "cherry"], () => "drupe"],
[["grape", "blueberry"], () => "berry"],
],
() => "other"
);
// Predicate function matching
const sizeCategory = inlineSwitch(length, [
[(v) => v < 10, () => "small"],
[(v) => v >= 10 && v < 100, () => "medium"],
[(v) => v >= 100, () => "large"],
]);
import { switchValue } from "inlineswitch";
// Simpler syntax for value-only checks
const result = switchValue(
color,
["red", () => "#FF0000"],
["green", () => "#00FF00"],
["blue", () => "#0000FF"]
);
inlineSwitch<T, R>(value: T, cases: SwitchCase<T, R>[], defaultHandler?: CaseHandler<T, R>): R | undefinedThe main function that implements pattern matching.
value: The value to match against case patternscases: An array of case patterns and their handlersdefaultHandler: Optional default handler if no cases matchswitchValue<T, R>(value: T, ...cases: Array<[T | T[], CaseHandler<T, R>]>): R | undefinedA shorthand version for simple value-only checks.
type CasePattern<T> = T | T[] | ((value: T) => boolean);
type CaseHandler<T, R> = (value: T) => R;
type SwitchCase<T, R> = [CasePattern<T>, CaseHandler<T, R>];
The library throws a DuplicateCaseError when duplicate case values are detected.
MIT
FAQs
A flexible inline switch statement with pattern matching for TypeScript/JavaScript
We found that inlineswitch demonstrated a healthy version release cadence and project activity because the last version was released less than 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.