
Security News
Happy Birthday, Shai-Hulud
It has been one year since Shai-Hulud made its first appearance on npm.
Patterns:
npm i matchacho
import { match } from 'matchacho'
return match(input,
String, (item: string) => [item],
Array, input,
null, [])
for (const directive of directives)
mask |= match<number>(directive,
'private', PRIVATE,
'public', PUBLIC,
'no-cache', NO_CACHE,
0)
return match(Class,
Role, () => new Role(value, this.discovery.roles),
Rule, () => new Rule(value, this.create.bind(this)),
Incept, () => new Incept(value, this.discovery),
() => new Class(value))
throw match(error.code,
'NOT_ACCEPTABLE', () => new UnsupportedMediaType(),
'TYPE_MISMATCH', () => new BadRequest(),
error)
Examples approved by Ed.
return match(value,
// equals
1, () => 'One!',
// instanceof
Readable, (stream) => stream.read(),
Error, (error) => throw error,
// test function
positive, (number) => Math.sqrt(number),
(x) => x < 0, (number) => Math.sqrt(-number),
// regular expression
/(\d+) \+ (\d+)/, (groups) => groups[0] + groups[1],
/(?<left>\d+) \+ (?<right>\d+)/, (groups) => groups.left + groups.right,
// object matching
{ statusCode: 200 }, (response) => response.data,
// array matching
[0, 1], (numbers) => `${numbers[0]} + ${numbers[1]}`,
// nested test function
{ statusCode: (x) => x >= 200 && x < 300 }, (response) => response.data,
// default
(value) => value
)
function positive (value) {
return value > 0
}
See tests.
Alternately, a chaining syntax may be used:
return match(input)
.when(String, (item) => [item])
.when(Array, input)
.when(null, () => [])
.default()
default() must be placed last in the chain, event if no default value is provided.
FAQs
Pattern matching for JavaScript
The npm package matchacho receives a total of 429 weekly downloads. As such, matchacho popularity was classified as not popular.
We found that matchacho 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.

Security News
It has been one year since Shai-Hulud made its first appearance on npm.

Research
/Security News
Operators behind PolinRider used a compromised GitHub account to plant malware in four development versions of a Packagist package with 700,000+ downloads.

Security News
GitHub Actions now supports cache-mode, a least-privilege control on the Actions cache aimed at the cache poisoning technique behind recent compromises.