Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
22 changes: 22 additions & 0 deletions test/bundlers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down