# to

> load/convert between xml,json,yaml formats

Latest version **0.2.9** (published 2012-12-12) · 0 weekly downloads

## Install

```sh
npm install to
pnpm add to
yarn add to
bun add to
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.9 |
| Published | 2012-12-12 |
| First published | 2012-09-08 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.8.0 |
| Dependencies | 5 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 30 |
| Author | el aras |
| Maintainers | truepattern, openmason |
| Keywords | converter, convertor, json, xml, yaml |

## Links

- npm: https://www.npmjs.com/package/to
- Repository: https://github.com/openmason/to
- npm.io page: https://npm.io/package/to

## Dependencies (5)

- [handy](https://npm.io/package/handy.md) >= 0.0.11
- [js-yaml](https://npm.io/package/js-yaml.md) >= 1.0.2
- [optimist](https://npm.io/package/optimist.md) >= 0.3.5
- [htmlparser](https://npm.io/package/htmlparser.md) >= 1.7.6
- [underscore](https://npm.io/package/underscore.md) >= 1.4.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.2.9 (latest) — 2012-12-12
- 0.2.8 — 2012-12-09
- 0.2.7 — 2012-12-09
- 0.2.6 — 2012-11-01
- 0.2.5 — 2012-10-17
- 0.2.4 — 2012-10-15
- 0.2.3 — 2012-10-14
- 0.2.2 — 2012-09-30
- 0.2.1 — 2012-09-30
- 0.2.0 — 2012-09-30
- 0.1.2 — 2012-09-30
- 0.1.1 — 2012-09-24
- 0.1.0 — 2012-09-14
- 0.0.3 — 2012-09-14
- 0.0.2 — 2012-09-14
- … 1 more at https://npm.io/package/to/versions

## README

[![build status](https://secure.travis-ci.org/openmason/to.png)](http://travis-ci.org/openmason/to)

# to.js
collection of convertors.
Comes with command line options to use the convertors along with a library version that can be used within programs as well.

# Solves
  * read input formats json, xml, yaml 
  * converts the document to internal javascript object form
  * write output as json, yaml documents
  * only input xml is handled (no output xml yet)

## Installation

    $ npm install -g to
    $ npm install to

## Usage

Command line:

     # reads xml file and prints it in yml
     $ to -i examples/sample.xml -o .yaml
     
     # reads yaml and prints it in json
     $ to -i examples/sample.yml -o .json

Within your program:

    var to = require('to');
    
    # Load yaml
    var yamldoc = to.format.yaml.load('config.yaml');
    
    # print doc in yaml 
    var doc = ...;
    console.log(to.format.yaml.stringify(doc));

 * refer to examples directory for xml, json, yaml code

## Example
For a sample input xml:

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">    
    <dummy>
    <value>15</value>
    <value>35</value>
    <value>5</value>
    <value>4784</value>
    <value>one more</value>
    <h>decent</h>
    <h>list</h>
    <h>another</h>
    <object>value</object>
    <inner>
      <h1>value</h1>
      <li>got</li>
      <li>milk</li>
    </inner>
   </dummy>

Output in json:

    {
      "dummy": {
        "value": [
          "15",
          "35",
          "5",
          "4784",
          "one more"
        ],
        "h": [
          "decent",
          "list",
          "another"
        ],
        "object": "value",
        "inner": {
          "h1": "value",
          "li": [
            "got",
            "milk"
          ]
        }
      }
    }
    
    # to try this example
    $ to -i examples/sample1.xml -o .json

Output in yaml:

    dummy: 
      value: 
        - 15
        - 35
        - 5
        - 4784
        - "one more"
      h: 
        - decent
        - list
        - another
      object: value
      inner: 
        h1: value
        li: 
          - got
          - milk

    # to try this example
    $ to -i examples/sample1.xml -o .yaml

## Todo
 * Input html (be forgiving with bad html)
 * Input markdown 
 * Output xml
 * Output html
 * add unit tests
 * allow beautification params for all outputs 

## Test cases
To execute full test cases

    $ make

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