{"id":27154938,"url":"https://github.com/coajs/coa-xml","last_synced_at":"2025-07-08T15:06:04.274Z","repository":{"id":46194925,"uuid":"266163918","full_name":"coajs/coa-xml","owner":"coajs","description":"一个简单的XML和JS对象转换库","archived":false,"fork":false,"pushed_at":"2023-06-29T11:26:59.000Z","size":121,"stargazers_count":0,"open_issues_count":3,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-06T03:02:41.806Z","etag":null,"topics":["coa","coa-xml","coajs","xml","xml2js"],"latest_commit_sha":null,"homepage":"https://npmjs.org/coa-xml","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coajs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-05-22T17:00:53.000Z","updated_at":"2021-11-08T08:54:35.000Z","dependencies_parsed_at":"2025-06-06T03:02:47.883Z","dependency_job_id":"4552212a-717b-4ec6-b3af-8d1d68a8d490","html_url":"https://github.com/coajs/coa-xml","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/coajs/coa-xml","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coajs%2Fcoa-xml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coajs%2Fcoa-xml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coajs%2Fcoa-xml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coajs%2Fcoa-xml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coajs","download_url":"https://codeload.github.com/coajs/coa-xml/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coajs%2Fcoa-xml/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264292935,"owners_count":23586062,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coa","coa-xml","coajs","xml","xml2js"],"created_at":"2025-04-08T18:56:29.923Z","updated_at":"2025-07-08T15:06:04.251Z","avatar_url":"https://github.com/coajs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# coa-xml\n\n[![GitHub license](https://img.shields.io/badge/license-MIT-green.svg?style=flat-square)](LICENSE)\n[![npm version](https://img.shields.io/npm/v/coa-xml.svg?style=flat-square)](https://www.npmjs.org/package/coa-xml)\n[![npm downloads](https://img.shields.io/npm/dm/coa-xml.svg?style=flat-square)](http://npm-stat.com/charts.html?package=coa-xml)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/coajs/coa-xml/pulls)\n\n一个简单的 XML 和 JS 对象转换库。基于 [xml2js](https://www.npmjs.com/package/xml2js) 做简单封装\n\n## 特点\n\n根据日常实际项目使用情况：\n\n- 整理并内置了一些默认参数，满足绝大多数使用场景\n- 统一了异步表现形式，全部返回 Promise\n- 内置类型引用，无需额外查看文档，开箱即用，IDE 友好\n\n## 快速开始\n\n### 安装\n\n```shell\nyarn add coa-xml\n```\n\n### 直接使用\n\n```typescript\nimport { xml } from 'coa-xml'\n\n// 将JS对象转换成xml字符串\nawait xml.encode({ name: 'A', gender: 1 }) // \u003cxml\u003e\u003cname\u003eA\u003c/name\u003e\u003cgender\u003e1\u003c/gender\u003e\u003c/xml\u003e\n\n// 将xml字符串转为JS对象\nawait xml.decode('\u003cxml\u003e\u003cname\u003eA\u003c/name\u003e\u003cgender\u003e1\u003c/gender\u003e\u003c/xml\u003e') // { name: 'A', gender: 1 }\n```\n\n### 自定义配置\n\n创建一个自定义实例，该实例的用法和`xml`对象完全一致\n\n```typescript\nimport { CoaXml } from 'coa-xml'\n\n// 根据自定义配置创建实例\nconst xml = new CoaXml({ cdata: false })\n\n// 将JS对象转换成xml字符串\nawait xml.encode({ name: 'A', gender: 1 }) // \u003cxml\u003e\u003cname\u003eA\u003c/name\u003e\u003cgender\u003e1\u003c/gender\u003e\u003c/xml\u003e\n\n// 将xml字符串转为JS对象\nawait xml.decode('\u003cxml\u003e\u003cname\u003eA\u003c/name\u003e\u003cgender\u003e1\u003c/gender\u003e\u003c/xml\u003e') // { name: 'A', gender: 1 }\n```\n\n其中，默认配置为\n\n```typescript\nconst DefaultOptions = {\n  rootName: 'xml',\n  explicitArray: false,\n  cdata: true,\n  headless: true,\n  explicitRoot: false,\n}\n```\n\n更多配置的说明详见 [xml2js](https://www.npmjs.com/package/xml2js#options) 原文\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoajs%2Fcoa-xml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoajs%2Fcoa-xml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoajs%2Fcoa-xml/lists"}