Benign javascript Download

ts-pattern 5.0.4

“The exhaustive Pattern Matching library for TypeScript.”

Contains an unconditional loop headerDeclares TypeScript development dependency
SHA-2569f9bfca8809eb9807cf5dc7637e339b8970baa7e22097084d97423314ec75b89

Evidence

Contains a hardcoded remote HTTP(S) URL lines 1–34
1:8… gn="center">TS-Pattern</h1>
2
3<p align="center">
4The exhaustive Pattern Matching library for <a href="https://github.com/microsoft/TypeScript">TypeScript</a>
5with smart type inference.
6</p>
7
8<p align="center">
9 <a href="https://www.npmjs.com/package/ts-pattern">
10 <img src="https://img.shields.io/npm/dm/ts-pattern.svg" alt="downloads" height="18">
11 </a>
12 <a href="https://www.npmjs.com/package/ts-pattern">
13 <img src="https://img.shields.io/npm/v/ts-pattern.svg" alt="npm version" height="18">
14 </a>
15 <a href="https://github.com/gvergnaud/ts-pattern">
16 <img src="https://img.shields.io/npm/l/ts-pattern.svg" alt="MIT license" height="18">
17 </a>
18</p>
19
20```ts
21import { match, P } from 'ts-pattern';
22
23type Data =
24 | { type: 'text'; content: string }
25 | { type: 'img'; src: string };
26
27type Result =
28 | { type: 'ok'; data: Data }
29 | { type: 'error'; error: Error };
30
31const result: Result = ...;
32
33const html = match(result)
34 .with({ type: 'erro …
At least four Markdown-style heading lines lines 35–42
35:16… 'ok', data: { type: 'text' } }, (res) => `<p>${res.data.content}</p>`)
36 .with({ type: 'ok', data: { type: 'img', src: P.select() } }, (src) => `<img src=${src} />`)
37 .exhaustive();
38```
39
40## About
41
42Write **better** and **safer conditions**. Pattern matching lets you express complex conditions in a single, compact expressio …
Markdown-style heading precedes a code fence lines 318–330
318:45… of your patterns
319- pass it as second parameter to `.with(...)`
320
321#### using P.when(predicate)
322
323```ts
⋯7 lines
Score field with numeric value lines 1040–1062
1040:33… tern';
1041
1042type Input = { score: number };
1043
1044const output = match({ score: 10 })
1045 .with(
1046 {
1047 score: P.when((score): score is 5 => score === 5),
1048 },
1049 (input) => '😐' // input is inferred as { score: 5 }
1050 )
1051 .with({ score: P.when((score) => score < 5) }, () => '😞')
1052 .with({ score: P.when((score) => score > 5) }, () => '🙂')
1053 .run();
1054
1055console.log(output);
1056// => '🙂'
1057```
⋯5 lines
JavaScript emoji console.log call text lines 1333–1344
1333:14… tring.includes('!'), () => '✅')
1334 .otherwise(() => '❌');
1335
1336console.log(fn('Good job! 🎉')); // logs '✅'
1337```
1338
⋯6 lines

Showing the top 5 files — 3 more files (16 regions) not shown.

No evidence locations were recorded for this file. Raw result

Keyboard shortcuts on this page: j for the next sample, k for the previous one, x to go back to the feed, d to download the original bytes, r to re-queue the sample for analysis.