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

objtree

v0.1.24

Published

Yusuki Kawasaki's ObjTree.js adapted for execution under Node.js by Ron Ranauro

Downloads

488

Readme

ObjTree

Overview

Based on the original version is XML.ObjTree developed by Yusuke Kawasaki. ObjTree.js is a parser/generater for XML source code and JavaScript objects. We modified it by testing for node.js and adding xmldom, which emulates browser data structures on the server side. In this way ObjTree.js can be used in server applications and in the browser. We changed nothing in Yusuke's code, though we include his documentation here for convenience.

##Methods

Initialize and return a new ObjTree object.

Example:

xotree = new ObjTree()

Load an XML document using the supplied string and return its JavaScript object converted.

Example:

objtree_xml = '
<?xml version="1.0" encoding="UTF-8"?>
<family name="Kawasaki">
<father>Yasuhisa</father>
<mother>Chizuko</mother>
<children>
<girl>Shiori</girl>
<boy>Yusuke</boy>
<boy>Kairi</boy>
</children>
</family>';

var xotree_out = xotree.parseXML( objtree_xml );

Result:

xctree_out == 
{
  'family': {
       '-name':    'Kawasaki',
       'father':   'Yasuhisa',
       'mother':   'Chizuko',
       'children': {
           'girl': 'Shiori',
           'boy': [
               'Yusuke',
               'Kairi'
           ]
       }
   }
}
  • How to get the attribute of an element:

Example:

xotree_out.family['-name'];

Result:

Kawasaki
  • How to get the text of an element:

Example:

xotree_out.family.father
xotree_out.family.children.boy[1]

Result:

Yasuhisa
Kairi

Set the prefix character which is inserted before each attribute names. Default is '-'.

Example:

xotree.attr_prefix = '@';
xotree_out = xotree.parseXML( objtree_xml );
xotree_out.family['@name'];

Result:

Kawasaki

Specify a list of element names which should always be forced into an array representation. The default value is null.

Example:

xotree.force_array = ['boy', 'father'];
xotree_out = xotree.parseXML( objtree_xml );
xotree_out.family.father //is an array now
xotree_out.family.father[0]

Result:

['Yasuhisa']
Yasuhisa

 xctree_out == 
{
  'family': {
       '-name':    'Kawasaki',
       'father':   ['Yasuhisa'],
       'mother':   'Chizuko',
       'children': {
           'girl': 'Shiori',
           'boy': [
               'Yusuke',
               'Kairi'
           ]
       }
   }
}
xotree.soft_arrays = true; 

Parse a JavaScript object tree and returns its XML source string generated.

Example:

var xml_out = xotree.writeXML( objtree_json )

Result:

xml_out =='
<?xml version="1.0" encoding="UTF-8"?>
<family name="Kawasaki">
<father>Yasuhisa</father>
<mother>Chizuko</mother>
<children>
<girl>Shiori</girl>
<boy>Yusuke</boy>
<boy>Kairi</boy>
</children>
</family>';

##Install

The source code is available for download from GitHub. Besides that, you can also install using Node Package Manager npm:

npm install objtree

##License

Copyright (c) 2005-2006 Yusuke Kawasaki. All rights reserved. This program is free software; you can redistribute it and/or modify it under the Artistic license. Or whatever license I choose, which I will do instead of keeping this documentation like it is.