From 237d81259fc2aedc8f07bc81359fd145a4975c13 Mon Sep 17 00:00:00 2001 From: Bas Huis Date: Thu, 11 Nov 2021 00:51:44 +0100 Subject: [PATCH] Improve the deprecated message --- README.md | 4 ++-- src/index.js | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8980c0e..d766beb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Patroon -Pattern matching in JavaScript without additional syntax +Pattern matching in JavaScript without additional syntax. [![NPM](https://img.shields.io/npm/v/patroon?color=blue&style=flat-square)](https://www.npmjs.com/package/patroon) [![NPM Downloads](https://img.shields.io/npm/dm/patroon?style=flat-square)](https://www.npmjs.com/package/patroon) @@ -545,7 +545,7 @@ npx nyc check-coverage total: 15 passing: 15 - duration: 1.5s + duration: 703ms ``` diff --git a/src/index.js b/src/index.js index 2226b77..c26f5b2 100755 --- a/src/index.js +++ b/src/index.js @@ -8,7 +8,7 @@ const deprecated = (fn, message) => (...args) => { const typed = deprecated(function typed (Ctor, pattern) { return every(Ctor, pattern) -}, 'replace "typed(Constructor, [pattern])" with "every(Constructor, pattern)"') +}, 'replace "typed" or "t" helpers with "every(Constructor, pattern)"') const isRegExp = is(RegExp) @@ -87,14 +87,12 @@ const patroon = (...list) => { if (isNil(found)) { throw new NoMatchError(`Not able to match any pattern for value ${JSON.stringify(args)}`) } - const [, doFn] = found - - return doFn(...args) + return found[1](...args) } } -function reference (fn) { - return (arg) => fn === arg +function reference (any) { + return value => any === value } module.exports = Object.assign(patroon, {