# coa-xml

> xml component for coa

Latest version **1.1.1** (published 2021-10-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install coa-xml
pnpm add coa-xml
yarn add coa-xml
bun add coa-xml
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2021-10-03 |
| First published | 2020-05-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Aex |
| Maintainers | adaex |
| Keywords | coajs, coa, xml |

## Links

- npm: https://www.npmjs.com/package/coa-xml
- Repository: https://github.com/coajs/coa-xml
- npm.io page: https://npm.io/package/coa-xml

## Dependencies (2)

- [xml2js](https://npm.io/package/xml2js.md) ^0.4.23
- [@types/xml2js](https://npm.io/package/@types/xml2js.md) ^0.4.9

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2021-10-03
- 1.1.0 — 2021-06-03
- 1.0.2 — 2021-03-19
- 1.0.1 — 2020-05-24

## README

# coa-xml

[![GitHub license](https://img.shields.io/badge/license-MIT-green.svg?style=flat-square)](LICENSE)
[![npm version](https://img.shields.io/npm/v/coa-xml.svg?style=flat-square)](https://www.npmjs.org/package/coa-xml)
[![npm downloads](https://img.shields.io/npm/dm/coa-xml.svg?style=flat-square)](http://npm-stat.com/charts.html?package=coa-xml)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/coajs/coa-xml/pulls)

一个简单的 XML 和 JS 对象转换库。基于 [xml2js](https://www.npmjs.com/package/xml2js) 做简单封装

## 特点

根据日常实际项目使用情况：

- 整理并内置了一些默认参数，满足绝大多数使用场景
- 统一了异步表现形式，全部返回 Promise
- 内置类型引用，无需额外查看文档，开箱即用，IDE 友好

## 快速开始

### 安装

```shell
yarn add coa-xml
```

### 直接使用

```typescript
import { xml } from 'coa-xml'

// 将JS对象转换成xml字符串
await xml.encode({ name: 'A', gender: 1 }) // <xml><name>A</name><gender>1</gender></xml>

// 将xml字符串转为JS对象
await xml.encode('<xml><name>A</name><gender>1</gender></xml>') // { name: 'A', gender: 1 }
```

### 自定义配置

创建一个自定义实例，该实例的用法和`xml`对象完全一致

```typescript
import { CoaXml } from 'coa-xml'

// 根据自定义配置创建实例
const xml = new CoaXml({ cdata: false })

// 将JS对象转换成xml字符串
await xml.encode({ name: 'A', gender: 1 }) // <xml><name>A</name><gender>1</gender></xml>

// 将xml字符串转为JS对象
await xml.encode('<xml><name>A</name><gender>1</gender></xml>') // { name: 'A', gender: 1 }
```

其中，默认配置为

```typescript
const DefaultOptions = {
  rootName: 'xml',
  explicitArray: false,
  cdata: true,
  headless: true,
  explicitRoot: false,
}
```

更多配置的说明详见 [xml2js](https://www.npmjs.com/package/xml2js#options) 原文

---
_Source: https://npm.io/package/coa-xml · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
