@seanwarman/json-form-builder

A tool to create json type objects for quick and standardised input forms

Usage no npm install needed!

<script type="module">
  import seanwarmanJsonFormBuilder from 'https://cdn.skypack.dev/@seanwarman/json-form-builder';
</script>

README

Json Builder

A tool to create json type components for quick and standardised input forms.

Choose the type of builder you want:

const jsonFormBuilder = JsonBuilder('jsonForm');

Then add an array of field types to quickly construct the json object. Adding title-cases to the fields you want to be required:

let jsonForm = jsonFormBuilder(['input', 'Input', 'textarea']);

// jsonForm = [ 
//   { type: 'input',
//     label: '',
//     value: '',
//     required: false,
//     prettyType: 'Text' },
//   { type: 'input',
//     label: '',
//     value: '',
//     required: true,
//     prettyType: 'Text' },
//   { type: 'textarea',
//     label: '',
//     value: '',
//     required: false,
//     prettyType: 'Long Text' } 
// ]

Sanitising

There's also some sanitising tools that come with the builder:

const jsonFormSanitiser = JsonFormBuilder('jsonFormSanitiser');

This will sanitise all values of the jsonForm then convert the whole object to a string ready to go to a MYSQL database.

const data {
    jsonForm: jsonFormSanitiser(jsonForm);
}

The other tools included are:

  • sanitiseValues(Json) - this will sanitise the values without converting the object to a string.
  • sanitiseString(String) - this will simply sanitise any string.