feathers-internationalisation-hook
v0.1.0
Published
Parse internationalisation nested data for query and results
Downloads
4
Readme
feathers-internationalisation-hook
Parse internationalisation nested data for query and results
Installation
npm i feathers-internationalisation-hook
Documentation
TBD
Complete Example
Here's an example of using the hooks
Parsing Query
const { parseI18nQuery } = require('feathers-internationalisation-hook')
module.exports = {
before: {
find: [ parseI18nQuery({ fields: ['title', 'description'] }) ]
}
}
// Query:
service.find({ query: { title: 'Post' } })
// Converts to:
params: {
query: {
title: {
en: 'Post'
}
}
}
Parsing Data
const { parseI18nData } = require('feathers-internationalisation-hook')
module.exports = {
before: {
find: [ parseI18nData({ fields: ['title', 'description'] }) ]
}
}
// Create:
service.create({ title: 'Post' })
// Converts to:
params: {
data: {
title: {
en: 'Post'
}
}
}
Parsing Result
const { parseI18nQuery, parseI18nResult } = require('feathers-internationalisation-hook')
module.exports = {
before: {
find: [ parseI18nQuery({ fields: ['title', 'description'], language: 'fr' }) ]
},
after: {
find: [ parseI18nResult({ fields: ['title', 'description'], language: 'fr' }) ]
}
}
// Find:
service.find({ query: { title: 'Lé Post' } })
// Converts this record:
{ id: 1, title: { en: 'The Post', fr: 'Lé Post' } }
// To:
context: {
result: {
data: [
{ id: 1, title: 'Lé Post' }
]
}
}
License
Copyright (c) 2018
Licensed under the MIT license.