Socket
Socket
Sign inDemoInstall

js2xml

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js2xml

Convert arbitary javascript to simple XML. Developed for ApiAxle.


Version published
Weekly downloads
58
decreased by-49.57%
Maintainers
2
Weekly downloads
 
Created
Source

About

A very simple library that converts a simple data structure into XML. Doesn't support namespaces or attributes, just very simple output. This allows you to write JSON and XML from the same structure without a middle-man.

It's written in Coffeescript but the JS is included.

Installing

$ npm install js2xml

Usage

var Js2Xml = require("js2xml").Js2Xml;

var person = {
  name: "Phil Jackson",
  mood: "Bored",
  stuff: [ "love, "puppies", 2, 2.3, { one: { two: "three" } } ],
  morestuff: { milkshake: "banana" }
};

var js2xml = new Js2Xml("person", person);
js2xml.toString();

Gives:

<?xml version="1.0" encoding="UTF-8"?>
<person>
  <name>Phil Jackson</name>
  <mood>Bored</mood>
  <stuff>
    <item>love</item>
    <item>puppies</item>
    <item>2</item>
    <item>2.3</item>
    <item>
      <one>
        <two>three</two>
      </one>
    </item>
  </stuff>
  <morestuff>
    <milkshake>banana</milkshake>
  </morestuff>
</person>

Pluralisation of lists

Here's how you might override the pluralisation function to deal with anonymous list items in Coffeescript:

class AppleXml extends Js2Xml
  @map =
    "apples": "apple"

  pluralisation: ( name ) ->
    return @constructor.map[ name ] or "item"

Keywords

FAQs

Package last updated on 12 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc