Socket
Socket
Sign inDemoInstall

ts-pattern

Package Overview
Dependencies
Maintainers
1
Versions
151
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-pattern - npm Package Compare versions

Comparing version 3.1.2 to 3.1.3

2

lib/index.d.ts
import type { Pattern, AnonymousSelectPattern, NamedSelectPattern, GuardPattern, NotPattern, GuardFunction } from './types/Pattern';
import type { Match } from './types/Match';
import { __ } from './PatternType';
export declare const when: <a, b extends a = a>(predicate: GuardFunction<a, b>) => GuardPattern<a, b>;
export declare const when: <a, b extends a = never>(predicate: GuardFunction<a, b>) => GuardPattern<a, b>;
export declare const not: <a>(pattern: Pattern<a>) => NotPattern<a>;

@@ -6,0 +6,0 @@ export declare function select(): AnonymousSelectPattern;

@@ -40,3 +40,3 @@ import type { __, PatternType } from '../PatternType';

*/
export declare type Pattern<a> = typeof __ | AnonymousSelectPattern | NamedSelectPattern<string> | GuardPattern<a> | NotPattern<a | any> | WildCardPattern<a> | (a extends Primitives ? a : a extends readonly (infer i)[] ? a extends readonly [infer a1, infer a2, infer a3, infer a4, infer a5] ? readonly [
export declare type Pattern<a> = typeof __ | AnonymousSelectPattern | NamedSelectPattern<string> | GuardPattern<a, a> | NotPattern<a | any> | WildCardPattern<a> | (a extends Primitives ? a : a extends readonly (infer i)[] ? a extends readonly [infer a1, infer a2, infer a3, infer a4, infer a5] ? readonly [
Pattern<a1>,

@@ -43,0 +43,0 @@ Pattern<a2>,

{
"name": "ts-pattern",
"version": "3.1.2",
"version": "3.1.3",
"description": "Typescript pattern matching library",

@@ -44,4 +44,4 @@ "main": "lib/index.js",

"ts-jest": "^26.4.4",
"typescript": "^4.2.2"
"typescript": "^4.2.4"
}
}

@@ -46,3 +46,3 @@ <h1 align="center">ts-pattern</h1>

Pattern Matching is a technique coming from Functional Programming languages to declaratively write conditional code branches based on the structure of a value. This technique has proven itself to be much more powerful and much less verbose than imperative alternatives (if/else/switch statements) especially when branching on complex data structures or on several values.
Pattern Matching is a technique coming from functional programming languages to declaratively write conditional code branches based on the structure of a value. This technique has proven itself to be much more powerful and much less verbose than imperative alternatives (if/else/switch statements) especially when branching on complex data structures or on several values.

@@ -110,4 +110,5 @@ Pattern Matching is implemented in Haskell, Rust, Swift, Elixir and many other languages. There is [a tc39 proposal](https://github.com/tc39/proposal-pattern-matching) to add Pattern Matching to the EcmaScript specification, but it is still in stage 1 and isn't likely to land before several years (if ever). Luckily, pattern matching can be implemented in userland. `ts-pattern` Provides a typesafe pattern matching implementation that you can start using today.

- [Basic Demo](https://codesandbox.io/s/ts-pattern-examples-0s6d8?file=/src/examples/basic.tsx)
- [Gif fetcher app Demo (with React)](https://codesandbox.io/s/ts-pattern-gif-search-demo-n8h4k?file=/src/App.tsx)
- [Reducer Demo (with React)](https://codesandbox.io/s/ts-pattern-reducer-example-c4yuq?file=/src/App.tsx)
- [Untyped Input (API response) Demo](https://codesandbox.io/s/ts-pattern-examples-0s6d8?file=/src/examples/api.tsx)
- [Untyped Input Demo (Handling an API response)](https://codesandbox.io/s/ts-pattern-examples-0s6d8?file=/src/examples/api.tsx)
- [`when` Guard Demo](https://codesandbox.io/s/ts-pattern-examples-0s6d8?file=/src/examples/when.tsx)

@@ -664,3 +665,3 @@ - [`not` Pattern Demo](https://codesandbox.io/s/ts-pattern-examples-0s6d8?file=/src/examples/not.tsx)

#### Object
#### Objects

@@ -832,3 +833,3 @@ A pattern can be an object with sub-pattern properties. In order to match,

console.log(output);
// => 'good'
// => 'πŸ™‚'
```

@@ -835,0 +836,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc