Skip to content

kulakowka/feathers-transform-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

feathers-transform-hook

npm package

NPM version Dependency Status

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()
    })
  ]
})

Example

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"
}

P.S.

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)
    }
  ]
});

About

Feathers hook for transform hook.data parameters

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published