From f39eebee8a4eecc195c74a97e74987fb4f220c92 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Thu, 4 Aug 2022 14:22:16 +0200 Subject: [PATCH 1/3] handle @fastify/x names --- plugin.js | 3 +++ test/bundlers.test.js | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/plugin.js b/plugin.js index 7e41cf9..a298df1 100644 --- a/plugin.js +++ b/plugin.js @@ -75,6 +75,9 @@ function checkName (fn) { } function toCamelCase (name) { + if (name[0] === '@') { + name = name.slice(1).replace('/', '-') + } const newName = name.replace(/-(.)/g, function (match, g1) { return g1.toUpperCase() }) diff --git a/test/bundlers.test.js b/test/bundlers.test.js index a48ff5b..57958e4 100644 --- a/test/bundlers.test.js +++ b/test/bundlers.test.js @@ -70,6 +70,28 @@ test('from kebabo-case to camelCase', (t) => { t.end() }) +test('from @-prefixed named imports', (t) => { + const plugin = fp((fastify, opts, next) => { + next() + }, { + name: '@hello/world' + }) + + t.equal(plugin.helloWorld, plugin) + t.end() +}) + +test('from @-prefixed named kebabo-case to camelCase', (t) => { + const plugin = fp((fastify, opts, next) => { + next() + }, { + name: '@hello/my-world' + }) + + t.equal(plugin.helloMyWorld, plugin) + t.end() +}) + test('from kebab-case to camelCase multiple words', (t) => { const plugin = fp((fastify, opts, next) => { next() From 355b87f226d92408b7849f257a6aa55055bc2344 Mon Sep 17 00:00:00 2001 From: Uzlopak Date: Thu, 4 Aug 2022 16:38:48 +0200 Subject: [PATCH 2/3] Update test/bundlers.test.js Co-authored-by: Vincent Le Goff --- test/bundlers.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bundlers.test.js b/test/bundlers.test.js index 57958e4..941bc59 100644 --- a/test/bundlers.test.js +++ b/test/bundlers.test.js @@ -81,7 +81,7 @@ test('from @-prefixed named imports', (t) => { t.end() }) -test('from @-prefixed named kebabo-case to camelCase', (t) => { +test('from @-prefixed named kebab-case to camelCase', (t) => { const plugin = fp((fastify, opts, next) => { next() }, { From f9046758dea75d68e08e157d271a5c89f68d1910 Mon Sep 17 00:00:00 2001 From: Uzlopak Date: Thu, 4 Aug 2022 16:39:44 +0200 Subject: [PATCH 3/3] rename other kebabo to kebab --- test/bundlers.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bundlers.test.js b/test/bundlers.test.js index 941bc59..ac70833 100644 --- a/test/bundlers.test.js +++ b/test/bundlers.test.js @@ -59,7 +59,7 @@ test('support ts named imports', (t) => { t.end() }) -test('from kebabo-case to camelCase', (t) => { +test('from kebab-case to camelCase', (t) => { const plugin = fp((fastify, opts, next) => { next() }, {