This is experiment. Work in progress!
Feathers hook for transform hook.data parameters with string.js
const transformHook = require('feathers-transform-hook')
app.service('/users').before({
create: [
transformHook({
username: data => data.username.toLowerCase().replaceAll(/\s/, ''),
slug: data => data.title.slugify()
})
]
})
Look example folder for more information.
Test request:
curl -H "Accept: application/json" -d "title=Hello world&username= adM in" -X POST http://localhost:3030/users
Server response example:
{
"title": "Hello world",
"username": "admin",
"slug": "hello-world"
}
Now, this hook is just a convenient wrapper over string.js. Therefore, all the same, you can easily do without this hook.
const marked = require('marked')
const S = require('string')
app.service('/articles').before({
create: [
hook => {
let data = hook.data
data.slug = S(data.title).slugify()
data.contentHtml = marked(data.content)
}
]
});