2.0.0 • Published 4 years ago

pattern-case v2.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

Node.js CI

Pattern Matching in Typescript

Fast and efficient pattern matching in Typescript.

test('early exit if the condition has met', () => {
  let executed = false;
  pattern<[number, number, number]>(1, 2, 3)
    .case(1, 2, 3)((a, b, c) => {return 1})
    .case(1, 2, 3)((a, b, c) => {executed = true; return 1})
    .match();
  expect(executed).toBe(false);
});

Fall-through

The function next could be used as a placeholder to continue with the next statement.

test('fall-through if the callback is not provided', () => {
  const result = pattern<[number, number, number]>(1, 2, 3)
    .case(1, 2, 3)(next)
    .case(1, 2, 3)((a, b, c) => {return 1})
    .match();
  expect(result).toBe(1);
});

Happy hacking!

2.0.0

4 years ago

1.5.2

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.8

4 years ago

1.2.7

4 years ago