@nutshelllab/object-translator

An object translator

Stats

StarsIssuesVersionUpdatedCreatedSize
@nutshelllab/object-translator
000.0.43 years ago3 years agoMinified + gzip package size for @nutshelllab/object-translator in KB

Readme

object translator

An object translator

Install

adding object-translator to package.json yarn 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'
  }
}

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.