@nutshelllab/object-translator
v0.0.4
Published
An object translator
Downloads
3
Readme
object translator
An object translator
Install
adding
object-translator
to package.jsonyarn add @nutshelllab/object-translator
Utilisation
import
import Translator from '@nutshelllab/object-translator'
initialize
const translator = new Translator(dictionnary, aliases)
dictionnary sample
{
"etablissement": {
"nom": "name",
"utilisateurs": "users"
},
"utilisateur": {
"nom": "lastName",
"prenom": "firstName",
"civilite": "gender",
"datedenaissance": "birthDate",
"etablissements": "companies"
}
}
aliases sample
{
"etablissement": ["etablissement", "etablissements"],
"utilisateur": ["utilisateur", "utilisateurs"]
}
Use it
You can now use it everywhere you want ! Here is some samples.
String
translator.run('utilisateur', 'nom')
exptected result :
lastName
Object
const object = {
nom: 'Doe',
prenom: 'John',
civilite: 'M',
datedenaissance: '25-02-1994',
unknow: 123
}
translator.run('utilisateur', object)
exptected result :
{
lastName: 'Doe',
firstName: 'John',
gender: 'M',
birthDate: '25-02-1994',
unknow: 123
}
Array
const array = ['nom', 'prenom', 'civilite', 'unknow']
translator.run('utilisateur', array)
exptected result :
['lastName', 'firstName', 'gender', 'unknow']
MultiType Object
const object = {
nom: 'Doe',
etablissements: {
nom: 'Nutshell'
}
}
exptected result :
{
lastName: 'Doe',
companies: {
name: 'Nutshell'
}
}