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

@qpyracuk/xml-builder

v0.1.2

Published

Fast and powerful XML serializer

Downloads

8

Readme

@qpyracuk/xml-builder

Introduction

At work I needed to serialize large data structures in XML, at that time I thought that this was not a problem, because NPM has many ready-made and reliable solutions. But to my great surprise, the search for the required library ended in failure. We won’t point fingers, but... One library produced invalid XML, another broke on large data structures, a third did not understand what was happening at all, and so on.

I tried 7 of the most popular libraries, and absolutely every one of them disappointed me to one degree or another.

We must pay tribute to the developers of xml2js, because this is the only library that was able to at least create XML from a large data structure (She made a little mistake on the arrays, but it was the best result among all)

But the problem with arrays is a small thing compared to the fact that data structures such as Set and Map crashed ANY library.

Therefore, I decided that it was time for another bike, and sat down to write my own XML serializer.

Fortunately, at this moment, I had my wonderful library @qpyracuk/iterator, which made my life much easier. The iterator reliably traverses a data tree in depth and breadth and supports data structures such as Map and Set. Therefore, making XML from this ready-made data is a task for 1 evening, with the help of 5 mugs of coffee.

And now, I am testing this library, and without any problems it converts huge data structures of millions of rows in a fraction of a second. I won’t show off, but I decided to compare the serialization speed with other libraries and... I beat them all!!! This concludes my long speech.

Use it, it's a really good solution!

Installation

This is a JS library available through the npm registry. Before installation, you need to download and install Node.js. Requires Node.js v8.0.0 or higher.

If this is a completely new project, be sure to create a package.json file using the npm init command.

To install the package, enter the npm install @qpyracuk/xml-builder command in the console.

npm install @qpyracuk/xml-builder

Features

  • Support for Map and Set data structures;
  • Pretty output mode;
  • Adjusting tab size in pretty mode;
  • Displaying variable types in XML attributes;
  • High serialization speed;
  • Disabling the XML preamble <?xml ...?>;
  • Changing the encoding.

Quick Start

After installing the package, import the library.

For ESMAScript modules:

import XML from '@qpyracuk/xml-builder';

For CommonJS modules:

const XML = require('@qpyracuk/xml-builder');

Usage example

We create an object that needs to be traversed

const futureXML = {
  primitive: '1',
  object: {
    primitive: 3,
    array: ["1", 2, "three"],
    set: new Set([1, 2, new Map([['key', { field: { value: 100 } }]])]),
    map: new Map([['key', { value: 10 }]])
  }
};

const builder = XML.createBuilder({ pretty: true, typed: true, preamble: true });
const xml = builder.stringify(futureXML);

Options

pretty: boolean

XML output with tabs and line breaks.

typed: boolean

Sign the type of fields of objects or variables.

tab: number | 'tab'

Tab size in spaces if specified as a positive numeric value. Is it possible to specify 'tab' and then all whitespace characters will become \t.

encoding: string

Encoding in XML preamble.

preamble: boolean

Embed XML preamble.

Builder methods

stringify(data: any): string

Serializes data into XML. Yes, it's simple!

In conclusion

This is a very young library, and in the future I plan to create 3 additional libraries for:

  • Parsing - @qpyracuk/xml-parser
  • Validation - @qpyracuk/xml-validator
  • Consolidation - @qpyracuk/xml (A set of utilities for working with ХML)

This will be done so that it is possible to use both all modules together and separately.

I assemble the topscript project so that the package is independent of the libraries, and is a ready-made bundle that can be used in the browser.

But in the project dependencies I specified “iterator”, because I really really want to increase the number of downloads on this library, now I’m the only one using it...

Author

The author of the library is Pobedinskiy David.

Bugs

If you encounter unexpected errors, please let me know. By e-mail [email protected] or in Telegram.

Support the author

If my work has helped you make your life easier, you can support me with your donations.

Boosty

Patreon

Search npm for other libraries with the @qpyracuk prefix. Perhaps you will find something useful for your project.