Skip to content

Repository files navigation

@nsnanocat/xml

XML / JSON 转换器,支持普通 XML 和 <plist>。属性写成 @name,文本节点写成 #

XML / JSON converter with plist support. Attributes are stored under @name, and text nodes under #.

Install

发布源:

npm install @nsnanocat/xml
npm config set @nsnanocat:registry https://npm.pkg.github.com
# GitHub Packages requires a token with package read access.
# echo "//npm.pkg.github.com/:_authToken=YOUR_GITHUB_PAT" >> ~/.npmrc
npm install @nsnanocat/xml

Usage

import XML from "@nsnanocat/xml";

const xml = '<root foo="bar"><child>text</child></root>';
const json = XML.parse(xml);
const output = XML.stringify(json);

console.log(json);
console.log(output);
import XML from "@nsnanocat/xml";

const plist = XML.parse("<plist><dict><key>n</key><integer>1</integer></dict></plist>");
// { plist: { n: 1n } }

API

XML.parse(xml, reviver?)

Parse XML into a JSON-like object. <plist> is handled specially and plist integers are returned as BigInt.

XML.stringify(json, tab?)

Serialize a JSON-like object back to XML. Pass "" for compact output or a tab string to replace indentation.

XML.about()

Print the package name and version.

Development

Published package entry point: XML.mjs. XML.beta.mjs stays in the repo as the verbose beta build.

npm run format
npm run lint
npm test
npm run typecheck
npm run check
npm pack --dry-run

License

Apache-2.0

About

an XML / JSON [ parse | stringify ] to JSON / XML Converter based JavaScript

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages