Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@hoist/easyxml
Advanced tools
The purpose of this module is to provide an easy to use function for converting your JS objects into XML. I plan on making it configurable since a lot of different people have different expectations.
Everything in here is CPU bound and without callbacks, so feel free to run it synchronously.
$ npm install easyxml
I was working on a Node.js API, and I wanted to be able to build a single object within each of my actions, and have that object automatically converted into the appropriate response based on request type (JSON, XML). The existing object to XML converters seemed to be lacking. The biggest feature I wanted was that an array of elements with a plural name get a bunch of sub elements with the singular version of the name. This library allows for all of that. Can be configured globally as well as on a per usage basis.
Input Object:
{
items: [{
name: 'one',
_id: 1
}, {
name: 'two',
_id: 2
}, {
name: 'three',
_id: 3
}],
blah: 'http://www.google.com',
when: new Date(),
boolz: true,
nullz: null
}
Example Config:
{
singularizeChildren: true,
underscoreAttributes: true,
rootElement: 'response',
dateFormat: 'ISO', // JS, SQL
indent: 2,
manifest: true
}
Output XML:
<?xml version='1.0' encoding='utf-8'?>
<response>
<items>
<item id="1">
<name>one</name>
</item>
<item id="2">
<name>two</name>
</item>
<item id="3">
<name>three</name>
</item>
</items>
<blah>http://www.google.com</blah>
<when>2012-09-25T18:47:39.485Z</when>
<boolz>true</boolz>
<nullz />
</response>
This project is licensed under the MIT license.
FAQs
A configurable object to XML converter
We found that @hoist/easyxml demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.