npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@raydeck/jxon

v3.0.1

Published

A complete, bidirectional, JXON library

Downloads

47

Readme

JXON Build Status

A complete, bidirectional, JXON (lossless JavaScript XML Object Notation) library. Packed as UMD.

Implementation of Mozilla's JXON code. Head over to MDN for Documentation.

Example:

{name: 'myportal'} 
<name>myportal</name>

{user: {
    username: 'testUser1',
    password: 'yolo',
    enabled: true
}}
<user>
  <username>testUser1</username>
  <password>yolo</password>
  <enabled>true</enabled>
</user>

{tag: {
    $type: 'regular'
    $blacklist: false
    _: 'Backbase'
}}
<tag type="regular" blacklist="false">Backbase</tag>

{dogs: {
    name: ['Charlie', {$nick: 'yes', _:'Mad Max'}]
}}
<dogs>
    <name>Charlie</name>
    <name nick="yes">Mad Max</name>
</dogs>

API

.config(cnf)

Overrides default configuration properties

  • cnf - Object with configuration properties.

Defaults:

valueKey: '_',
attrKey: '$',
attrPrefix: '$',
lowerCaseTags: false,
trueIsEmpty: false,
autoDate: false,
ignorePrefixedNodes: false,
parseValues: false,
parserErrorHandler: undefined

.stringToJs(xmlString)

Converts XML string to JS object.

  • xmlString - XML string to convert to JXON notation JS object

.jsToString(obj)

Converts JS object to XML string.

  • obj - JS object in JXON notation to convert to XML string

.xmlToJs(xmlDocument, verbosity, freeze, nestedAttributes)

Converts XML document to JS object. Alias: JXON.build

  • xmlDocument - The XML document to be converted into JavaScript Object.
  • verbosity - Optional verbosity level of conversion, from 0 to 3. It is almost equivalent to our algorithms from #4 to #1 (default value is 1, which is equivalent to the algorithm #3).
  • freeze - Optional boolean expressing whether the created object must be freezed or not (default value is false).
  • nestedAttributes - Optional boolean expressing whether the the nodeAttributes must be nested into a child-object named keyAttributes or not (default value is false for verbosity levels from 0 to 2; true for verbosity level 3).

Example:

var myObject = JXON.build(xmlDoc);

.jsToXml(obj, namespaceURI, qualifiedNameStr, documentType)

Converts JS object to XML document. Alias: JXON.unbuild

  • obj - The JavaScript Object from which you want to create your XML Document.
  • namespaceURI - Optional DOMString containing the namespace URI of the document to be created, or null if the document doesn't belong to one.
  • qualifiedNameStr - Optional DOMString containing the qualified name, that is an optional prefix and colon plus the local root element name, of the document to be created.
  • documentType - Optional DocumentType of the document to be created. It defaults to null.

Example:

var myObject = JXON.unbuild(myObject);

.stringToXml(xmlString)

Wrapper over DOMParser.parseFromString, converts string to XML document.

  • xmlString - XML string to convert to XML document

.xmlToString(xmlObj)

Wrapper over XMLSerializer.serializeToString, converts XML document to string.

  • xmlObj - XML document to convert to XML string

.each(obj, callback[, thisArg])

Helper method to iterate node(s).
In case that there is only one children node, JXON will return object. For multiple children it will return array. This method will always iterate nodes as array.

  • obj - array or object to iterate
  • callback - function to execute for each element
  • thisArg - optional. Value to use as this when eecuting callback

Example:

var jx = jxon.stringToJs('<val>foo</val>');
jxon.each(jx.val, function(val) {
    assert(val, 'foo');
});

CHANGELOG

2.0.0

changes from version 1.x to 2.0 include:

  • (breaking) more usefull default settings (see above)
  • (breaking) stringify Dates to ISO format instead of GMT
  • improved xml namespace handling on node and browsers
  • renamed main source file to jxon.js