# easy-konvertor

> easy-konvertor ===========

Latest version **1.0.6** (published 2023-04-22) · ISC license · 0 weekly downloads

## Install

```sh
npm install easy-konvertor
pnpm add easy-konvertor
yarn add easy-konvertor
bun add easy-konvertor
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2023-04-22 |
| First published | 2023-01-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 27.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Alessandro Faggiani |
| Maintainers | a.faggiani |

## Links

- npm: https://www.npmjs.com/package/easy-konvertor
- npm.io page: https://npm.io/package/easy-konvertor

## Dependencies (1)

- [@types/node](https://npm.io/package/@types/node.md) ^18.6.5

## Recent versions

- 1.0.6 (latest) — 2023-04-22
- 1.0.5 — 2023-02-27
- 1.0.4 — 2023-02-27
- 1.0.3 — 2023-02-27
- 1.0.2 — 2023-02-27
- 1.0.1 — 2023-02-27
- 1.0.0 — 2023-01-03

## README

easy-konvertor
===========

Ever had the urge to parse JSON to XML or CSV to JSON? And wanted to access the data in some sane,
easy way? Then easy-konvertor is what you're looking for!

Description
===========

Simple JSON to XML converter.

Installation
============

Simplest way to install `easy-konvertor` is to use [npm](http://npmjs.org), just `npm
install easy-konvertor` which will download easy-konvertor and all dependencies.

Usage
=====

No extensive tutorials required because you are a smart developer! The task of
parsing JSON should be an easy one, so let's make it so! Here's some examples.


Convert a JSON file into XML:
----------------------

```javascript
import { Convertor } from "easy-konvertor";

let xml = Convertor.readJson("<path_file>").convert(FileTypeEnum.XML);
console.log(xml);
```
Convert a pre-loaded JSON string
----------------------

```javascript
import { Convertor } from "easy-konvertor";

const json = `{
        "employees": {
          "employee": [{
              "name": "John",
              "surname": "Dalton",
              "age": 40
            },
            {
              "name": "Harry",
              "surname": "McCormick",
              "age": 45
            }
          ]
        }
      `
let xml = Convertor.json2xml(json);
console.log(xml);
```
This should output the following XML document:
```xml
<employees>
  <employee>
    <name>John</name>
    <surname>Dalton</surname>
    <age>40</age>
  </employee>
  <employee>
    <name>Harry</name>
    <surname>McCormick</surname>
    <age>45</age>
  </employee>
</employees>
```
Use options for XML formatting
----------------------
```javascript
let options = {
                padding: 2,
                XMLHeader: true
               }
Convertor.options(options).json2xml(json);
```
Options:
| Parameter        | Description                                                         | Default |
|------------------|---------------------------------------------------------------------|---------|
| XMLHeader           | If true add the XML XMLHeader                                          | false   |
| padding          | Number of blank for indenting elements.If not present a tab is used |         |
| root             | A string to wrap around the rendered XML document                   |         |

Beautify existing XML string
----------------------
```javascript
import { Convertor } from "easy-konvertor";
let xml = `<employees>
            <employee>
            <name>John</name>
            <surname>Dalton</surname>
            <age>40</age>
            </employee>
            <employee>
            <name>Harry</name>
            <surname>McCormick</surname>
            <age>45</age>
            </employee>
            </employees>`

let pad = "  ";
xml = Convertor.beautifyXml(xml, pad)
```
Format XML with an optional `pad` string. If not present a tab character is used.
The output xml is like this:
```xml
<employees>
  <employee>
    <name>John</name>
    <surname>Dalton</surname>
    <age>40</age>
  </employee>
  <employee>
    <name>Harry</name>
    <surname>McCormick</surname>
    <age>45</age>
  </employee>
</employees>
```
Convert a CSV into JSON
----------------------
```javascript
import { Convertor, FileTypeEnum } from "easy-konvertor";

//Convert a string read from a file
Convertor.readCsv("<file name>").convert(FileTypeEnum.JSON);

//Use 'csvHeader' if the header is not present or you want to override it
Convertor.csvHeader("name;lastname;age").readCsv("<file name>").convert(FileTypeEnum.JSON);
```
Convert a preloaded CSV string into JSON
----------------------
```javascript
import { Convertor, FileTypeEnum } from "easy-konvertor";

//if the header is not present or you want to override it
Convertor.csv2json("<csv string>");
```

---
_Source: https://npm.io/package/easy-konvertor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
