🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

xast-namespaces

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xast-namespaces

Attach namespace information to a xast XML element tree.

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

xast-namespaces

Attach namespace information to a xast XML element tree.

build status codecov npm prettier

This library exposes a function which takes a xast tree and attaches namespace information to each element.

Installation

npm install xast-namespaces

Usage

import { attachNamespaces } from 'xast-namespaces';

const tree = {
  type: 'element',
  name: 'ns:parent',
  attributes: {
    'xmlns:ns': 'https://ns.example',
  },
  children: [
    {
      type: 'element',
      name: 'ns:child',
      attributes: {
        'ns:attr': 'value',
      },
      children: [],
    },
  ],
};

const result = attachNamespaces(tree);
assert.deepStrictEqual(result, {
  type: 'element',
  name: 'ns:parent',
  namespace: 'ns',
  namespaceURI: 'https://ns.example',
  localName: 'parent',
  namespaces: {
    ns: 'https://ns.example',
  },
  attributes: {
    'xmlns:ns': 'https://ns.example',
  },
  namespacedAttributes: [
    {
      type: 'attribute',
      name: 'xmlns:ns',
      namespace: 'xmlns',
      namespaceURI: undefined,
      localName: 'ns',
      value: 'https://ns.example',
    },
  ],
  children: [
    {
      type: 'element',
      name: 'ns:child',
      namespace: 'ns',
      namespaceURI: 'https://ns.example',
      localName: 'child',
      namespaces: {
        ns: 'https://ns.example',
      },
      attributes: {
        'ns:attr': 'value',
      },
      namespacedAttributes: [
        {
          type: 'attribute',
          name: 'ns:attr',
          namespace: 'ns',
          namespaceURI: 'https://ns.example',
          localName: 'attr',
          value: 'value',
        },
      ],
      children: [],
    },
  ],
});

API

attachNamespaces(tree)

Attach XML namespace data to a xast tree.

Options

  • tree The document tree to attach namespace data to. If a xast root is passed, its element child will be used.

Returns

A copy of the tree, but with namespace data attached.

License

MIT © Remco Haszing

Keywords

namespace

FAQs

Package last updated on 25 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts