https://github.com/rmariuzzo/xml-comment-api
Parse XML comment that provide an API
https://github.com/rmariuzzo/xml-comment-api
xml
Last synced: about 1 year ago
JSON representation
Parse XML comment that provide an API
- Host: GitHub
- URL: https://github.com/rmariuzzo/xml-comment-api
- Owner: rmariuzzo
- License: mit
- Created: 2017-07-27T01:05:47.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-10-15T22:00:57.000Z (over 4 years ago)
- Last Synced: 2025-03-16T03:23:03.919Z (over 1 year ago)
- Topics: xml
- Language: JavaScript
- Size: 98.6 KB
- Stars: 2
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
XML Comment API
Parse XML comment that provide an API
## Installation
```shell
npm install xml-comment-api
```
## Usage
```js
const XmlCommentApi = require('xml-comment-api')
const input = `
# Hello World
`
XmlCommentApi(input).replace('salute', (tag) => `Hi ${tag.attributes.name}`)
// > # Hello World
// Hi Rubens
```
## API
Everything starts by invoking the `XmlCommentApi` function passing the string containgin XML comments.
```js
const XmlCommentApi = require('xml-comment-api')
XmlCommentApi(' ')
```
When `XmlCommentApi` is invoked it will return an object exposing a few methods:
### `find(name: String, options: Object) : Array`
Find all tags by `name`. The `name` by default is case sensitive. The second parameter are `options`.
```js
XmlCommentApi('😘')
.find('salute')
// > [{
// tag: 'salute',
// attributes: undefined,
// contents: '😘',
// start: 15,
// end: 17
// }]
```
### `replace(name: String, options: Object, callback: Function|String) : XmlCommentApiObject`
Find all tags by `name` using `options` and replace the contents of matching tags with the result of the `callback` (when a `Function` is given) or with the `callback` itself (when a `String` is given).
```js
XmlCommentApi('😘')
.replace('salute', '❤️')
.contents()
// > ❤️
```
### `contents() : String`
Return the modified string. Useful when using `replace` to obtain the modified string.
#### License
[MIT](LICENSE)