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

@innodatalabs/xmlfuse-js

v2.0.2

Published

Fusing together two XML markups

Downloads

4

Readme

xmlfuse-js

Build Status npm version

XML representations as a JSON stream. Convenient for content-oriented XML tasks.

This is a JS port of Python package xmlfuse.

Installation

npm i @innodatalabs/xmlfuse-js --save

Building and testing:

make

API

import { fromString, toString } from '@innodatalabs/lxmlx-js';
import { fuse } from '@innodatalabs/xmlfuse-js';

const xml1 = fromString('<span>Hello, <i>world!</i></span>');
const xml2 = fromString('<span><b>Hello</b>, world!</span>');

const xml = fuze(xml1, xml2)
toString(xml) === '<span><b>Hello</b>, <i>world!</i></span>'
// true

Input documents must have exactly the same text

Error is raised if text differs. Whitespace does matter!

Example:

const xml1 = fromString('<span>Hello</span>');
const xml2 = fromString('<span>Good bye</span>');

const xml = fuze(xml1, xml2);
// throws Error('Text is different')

Conflicting markup

Sometimes it is not possible to merge two markups, because tags intersect. In such a case one has a choice:

a. Raise an exception and let caller handle the problem b. Resolve by segmenting one of the markups

We treat first document as master, and second as slave. Master markup is never segmented. If there is a conflict between master and slave markups (and if autoSegment option is true), fuse() will segment slave to make markup consistent.

Example:

const xml1 = fromString('<span>Hel<i>lo, world!</i></span>');
const xml2 = fromString('<span><b>Hello</b>, world!</span>');

const xml = fuze(xml1, xml2);
toString(xml) === '<span><b>Hel<i>lo</i></b></i>, <i>world!</i></span>';
// true

Set autoSegment flag to false to prevent segmentation. Error will be raised instead, if conflict detected.

Ambiguities

When master ans slave markups wrap the same text, there is a nesting ambuguity - which tag should be inner?

We resolve this by consistently trying to put slave markup inside the master. This behavior can be changed by setting the flag preferSlaveInner to false.

Example:

const xml1 = fromString('<span><i>Hello</i>, world!</span>');
const xml2 = fromString('<span><b>Hello</b>, world!</span>');

const xml = fuze(xml1, xml2, {preferSlaveInner: true});
toString(xml) === '<span><b><i>Hello</i></b>, world!</span>';
// true

const xml = fuze(xml1, xml2, {preferSlaveInner: false});
toString(xml) == b'<span><i><b>Hello</b></i>, world!</span>';
// true

Slave top-level tag is dropped

Note that top-level tag from slave is not merged. It is just dropped. If you want it to be merged into the output, set stripSlaveTopTag: false.

fuse() signature

function fuse(xml1, xml2, options) { ... }

Where:

  • xml1 is the master XML document (LXML Element object, see http://lxml.de)
  • xml2 is the slave XML document

Returns fused XML document

Recognized options:

  • preferSlaveInner controls ambigiuty resolution
  • autoSegment allows slave markup segmentation in case of conflicting markup
  • stripSlaveTopTag allows fuse to ignore top-level tag from the slave XML
  • nsmap provides namespace mapping for building the output document (see lxmlx-js doc for more details on namespaces)