
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
ts-matching
Advanced tools
A pattern matching library for typescript with smart type inference.
yarn
yarn add ts-matching
npm
npm install --save ts-matching
matchForimport { matchFor } from 'ts-matching'
import { pipe } from 'fp-ts/function'
type Option<T> = { _tag: 'None' } | { _tag: 'Some', value: T }
const none: Option<never> = { _tag: 'None' }
const some = <T>(value: T): Option<T> => ({ _tag: 'Some', value })
type RemoteData<E, T> = { _tag: 'Loading' } | { _tag: 'Success', value: T } | { _tag: 'Failure', error: E }
const match = matchFor('_tag')
const toMsg = (data: RemoteData<Error, Option<string>>) =>
pipe(
data,
match({
Loading: () => 'loading',
Failure_error: (e) => `error: ${e.message}`,
Success_value_Some_value: (value) => `found ${value}`,
Success_value_None: () => 'not found',
}),
)
assert.strictEqual(toMsg({ _tag: 'Loading' }), 'loading')
assert.strictEqual(toMsg({ _tag: 'Success', value: some('a') }), 'found a')
assert.strictEqual(toMsg({ _tag: 'Success', value: none }), 'not found')
matchWithForimport { matchWithFor } from 'ts-matching'
type Option<T> = { _tag: 'None' } | { _tag: 'Some', value: T }
const none: Option<never> = { _tag: 'None' }
const some = <T>(value: T): Option<T> => ({ _tag: 'Some', value })
type RemoteData<E, T> = { _tag: 'Loading' } | { _tag: 'Success', value: T } | { _tag: 'Failure', error: E }
const match = matchWithFor('_tag')
const toMsg = (data: RemoteData<Error, Option<string>>) => match(data).with({
Loading: () => 'loading',
Failure_error: (e) => `error: ${e.message}`,
Success_value_Some_value: (value) => `found ${value}`,
Success_value_None: () => 'not found'
})
assert.strictEqual(toMsg({ _tag: 'Loading' }), 'loading')
assert.strictEqual(toMsg({ _tag: 'Success', value: some('a') }), 'found a')
assert.strictEqual(toMsg({ _tag: 'Success', value: none }), 'not found')
FAQs
A pattern matching library for typescript with smart type inference.
We found that ts-matching 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.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.