object-transformer-model

Basicly my need where => I have x field with some of them wich are multi select, once every field is filled i need to create dynamicly an array of models for the server to match the api schema. I built this in mind of not taking in account the keys of my specific need so it can be used with anything.

Usage no npm install needed!

<script type="module">
  import objectTransformerModel from 'https://cdn.skypack.dev/object-transformer-model';
</script>

README

OBJECT-TRANSFORMER

WIP - WORK IN PROGRESS

Basicly my need where => I have x field with some of them wich are multi select, once every field is filled i need to create dynamicly an array of models for the server to match the api schema. I built this in mind of not taking in account the keys of my specific need so it can be used with anything.

try it

# npm
$ npm install object-transformer

# yarn
$ yarn add object-transformer

Example

This is some kinda of case i ran into, each hobbies should be a single element in the database... !

const getModels = require('object-transformer');

const selectFromForm = {
  name: 'André Gomes',
  age: '25',
  hobbies: ["Gaming", "Reading", "Programming", "Music"],
}

const models = getModels(selectFromForm);
/*
RESULT : 
  [
    {
      hobbies: 'Gaming',
      name: 'André Gomes',
      age: '25'
    },
    {
      hobbies: 'Reading',
      name: 'André Gomes',
      age: '25'
    },
    {
      hobbies: 'Programming',
      name: 'André Gomes',
      age: '25'
    },
    {
      hobbies: 'Music',
      name: 'André Gomes',
      age: '25'
    }
  ] 
*/

Contribution

PR's and feedback are welcome !