Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle @fastify/x names to export #190

Merged
merged 3 commits into from
Aug 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
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