feathers-transform-hook

0.1.2 • Public • Published

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

Package Sidebar

Install

npm i feathers-transform-hook

Weekly Downloads

4

Version

0.1.2

License

MIT

Last publish

Collaborators

  • kulakowka