Skip to content

Commit

Permalink
feat: handle @fastify/x names to export (#190)
Browse files Browse the repository at this point in the history
* handle @fastify/x names

* Update test/bundlers.test.js

Co-authored-by: Vincent Le Goff <[email protected]>

* rename other kebabo to kebab

Co-authored-by: Vincent Le Goff <[email protected]>
  • Loading branch information
Uzlopak and zekth authored Aug 6, 2022
1 parent e692cc6 commit 36e9271
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
Expand Down
24 changes: 23 additions & 1 deletion test/bundlers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}, {
Expand All @@ -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 kebab-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()
Expand Down

0 comments on commit 36e9271

Please sign in to comment.