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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nodable/base-output-builder

v1.0.5

Published

Base output builder for flexible-xml-parser

Readme

Base Output Builder

Base output builder is the base class to create output builders for @nodable/flexible-xml-parser.

Installation

npm install @nodable/base-output-builder

Usage

import { BaseOutputBuilder, commonValueParsers } from '@nodable/base-output-builder';

class MyOutputBuilder extends BaseOutputBuilder {
  constructor(options) {
    super(options);
  }
}

class MyBuilder extends BaseOutputBuilder {
  constructor(options, builderOptions, valParsers, matcher) {
    super(readonlyMatcher);
    this.options = {
      ...builderOptions,
      ...parserOptions,
      //my builder specific options
    }
  }
  // override addTag, addAttribute, closeTag, addValue ... methods
}

// 2. Wrap it in a factory object that XMLParser knows how to call
const MyBuilderFactory = {
  constructor(builderOptions) {
    this.options = buildOptions(builderOptions);
    this.valParsers = commonValueParsers();
  }

  registerValueParser(name, parser) {
    // implement if you need to register named value parsers on this factory
    this.valParsers[name] = parserInstance;
  },

  getInstance(parserOptions, matcher) {
    return new MyBuilder(parserOptions, this.options, this.valParsers, matcher);
  },
};

You can also modify the bhaviour of value parsers bundled with base-output-builder by passing options.

import { numberParser } from '@nodable/base-output-builder';
import { XmlParser } from '@nodable/flexible-xml-parser';

const numberParserInstance = new numberParser({ hex: true, leadingZeros: true, eNotation: true });

const myBuilderFactory = new MyBuilderFactory({
  tags: {
    valParsers: ['entity', 'number', 'boolean', 'trim', 'currency']
  },
  attributes: {
    valParsers: ['entity', 'number', 'boolean', 'trim', 'currency']
  }
});
myBuilderFactory.registerValueParser('number', numberParserInstance); //overrides default settings

const parser = new XmlParser({
  OutputBuilder: myBuilderFactory
});

This package provides following value parsers

  • number: This uses strnum package to parser strings in number
  • boolean: This parses boolean strings in boolean values
  • trim: trim the input string
  • joint: join the input string
  • currency: parse currency
  • Entity: parse entities

Entity Parser

Entity Parser is used to parse entities in the input string. There are total 4 types of entities.

Category 1

  1. Default : Entities which are natively supported by XML. apos, lt, gt, quot are supported.
  2. SYSTEM: System specific entites like HTML. When set space, cent, pound, yen, euro, copy, reg, inr, numeric, and hexadecimal entites are supported.

Category 2 3. INPUT: Input specific entites. These entities are provided by the user as input to the parser. Parser reads these entites and pass to output builder using the method addInputEntities. 4. EXTERNAL: These entities are set by programmaer in code. These are recommended over INPUT entities for security reasons.

import { EntitiesValueParser } from "@nodable/base-output-builder"

const evp = new EntitiesValueParser({
  docType: true
});
const builder = new CompactObjBuilder();
builder.registerValueParser("entity", evp);

const parser = new XMLParser({
  doctypeOptions: { enabled: true },
  OutputBuilder: builder
});
const result = parser.parse(`<!DOCTYPE root [
  <!ENTITY brand "FlexParser">
]><root><name>&brand;</name></root>`);

Following options are supported

  • default: true/false/object. Default is true. If true, XML entities are parsed. If false, XML entities are not parsed. If object, custom XML entities are parsed.
  • html: true/false/object. Default is false. If true, HTML entities are parsed. If false, HTML entities are not parsed. If object, custom HTML entities are parsed.
  • external: true/false. Default is true. If true, external entities are parsed. If false, external entities are not parsed.
const evpOn = new EntitiesValueParser({ default: true, external: true });
    evpOn.addEntity("copy", "©");
  • maxTotalExpansions: number. Default is 0. Maximum number of entity expansions allowed per document.
  • maxExpandedLength: number. Default is 0. Maximum number of characters added by entity expansion per document.

Custom Value Parsers

Custom parsers receive (val, context) where context carries { elementName, elementValue, elementType, matcher, isLeafNode }:

class PriceParser {
  parse(val, context) {
    return context.elementName === 'price' ? parseFloat(val) : val;
  }
}

Register a reusable custom parser by name via CompactObjBuilder:

import { CompactBuilderFactory } from '@nodable/compact-builder';

const builderFactory = new CompactBuilderFactory({
  tags: {
    valueParsers: ['price', 'entity', 'number', 'boolean', 'trim', 'currency']
  }
);
builderFactory.registerValueParser('price', new PriceParser());

const parser = new XMLParser({
  OutputBuilder: builderFactory,
});