
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
PatMatJS is a Javascript Pattern matching utility developed in typescript that can be used standalone in the browser, in node or as ES module.
npm install --save patmatjs or reference it from CDN in the browser<script src="https://unpkg.com/patmatjs@3.0.0/dist/browser/index.js" type="application/javascript"></script>match function const financialStatus = match(42)
.caseGreaterEqualThan(1000000, "I'm rich!")
.caseLessThan(0, "I'm ruined")
.default("I keep trying");
console.log(financialStatus); // outputs I keep trying
const {match} = require("patmatjs");
const isEven = match(2)
.case(n => n % 2 === 0, true)
.default(false);
console.log(isEven); // outputs true
import {match} from "patmatjs";
const areWeInTheFuture = match(new Date())
.caseNewerThan(new Date(2050, 0, 1), true)
.default(false);
console.log(areWeInTheFuture); // outputs false
If you are using typescript or an IDE with autocompletion, just write match. and explore all the options available. Basically you have cases for every javascript primitive type + instance checks. Almost every case method has a companion method ended in "If"; This allows to put an extra predicate if the case is not enough. To end the match expression use default method.
import {match} from "patmatjs";
class FatalError {
constructor(readonly id: string, readonly date: Date) {}
}
class Warning {
constructor(readonly title: string, readonly message: string) {}
}
class MailMessage {
constructor(readonly sender: string, readonly subject: string, readonly message: string) {}
}
type Whatever =
FatalError |
Warning |
MailMessage;
const info = getInfo(); // returns type Whatever
const infoDetails = match(info)
.caseInstanceIf(FatalError, e => e.id === 404 => `No content found at ${e.date.toISOString()}`)
.caseInstance(FatalError, e => `Error #${e.id} received`)
.caseInstance(Warning, w => `Warning ${w.title}: ${w.message}`)
.caseInstance(MailMessage, m => `You received a message from ${m.sender}`)
.default("Unknown information received");
import {match} from "patmatjs";
const a = 0.2;
const b = 0.4;
const c = 0.6;
const whatHappens = match(a+b)
.caseEqual(c, "This number is 0.6")
.caseAlmostEqual(c, "The number is not exactly 0.6, but it is very close") // <-- this will match
.default("This number is not 0.6 at all");
import {match} from "patmatjs";
function isSomething(x) {
throw "Error!"; // <-- look at this
}
const value = match(x)
.case(isSomething, "This is something") // <-- custom tests doesn't raise exceptions, they simple return false
.default("This is nothing");
import {match} from "patmatjs";
const twice = match("hello world")
.withReturnType<number|string>()
.caseString(s => `${s}${s}`)
.caseNumber(n => n*2)
.default(0);
FAQs
Javascript pattern matching utility backed by typescript
The npm package patmatjs receives a total of 1 weekly downloads. As such, patmatjs popularity was classified as not popular.
We found that patmatjs 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
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.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.