# convert-relative

> convert link to relative.转换地址为相对地址

Latest version **1.0.2** (published 2017-03-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install convert-relative
pnpm add convert-relative
yarn add convert-relative
bun add convert-relative
```

## 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.0.2 |
| Published | 2017-03-08 |
| First published | 2017-03-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | laomu1988@qq.com |
| Maintainers | laomu |
| Keywords | convert, relative |

## Links

- npm: https://www.npmjs.com/package/convert-relative
- Repository: https://github.com/laomu1988/convert-relative
- Homepage: https://github.com/laomu1988/convert-relative#readme
- Issues: https://github.com/laomu1988/convert-relative/issues
- npm.io page: https://npm.io/package/convert-relative

## Dependencies (1)

- [cheerio](https://npm.io/package/cheerio.md) ^0.22.0

## Recent versions

- 1.0.2 (latest) — 2017-03-08
- 1.0.1 — 2017-03-08

## README

# 将地址改为相对地址

## demo

```js
var convert = require('convert-relative')

// 转换链接地址
var link = convert.link('/test/test.js', 'http://www.test.com/test/index.html')
console.log(link)
// 将输出 'test.js'

// 转换html，将html内容中的所有引用地址改为相对地址
var result = convert.html('<a href="/test.html">test</a>', 'http://www.test.com/test/index.html')
console.log(result)
/** 将输出
*  {
*     changed: 1,
*     html: '<a href="../test.html">test</a>',
*     links: ['http://www.test.com/test/index.html']
*  }
*
*/

```

## api

* link(link, baseUrl) 转换地址为相对地址
  - @param {string} link: 被转换的地址
  - @param {string} baseUrl: 基础地址
  - @return {string} 转换后的地址

* html(html, baseUrl) 转换html中内容的地址为相对地址
  - @param {string} html: 被转换的html内容
  - @param {string} baseUrl: 基础地址
  - @return {object}
       * changed: 修改的地址个数
       * html:    修改后的文档内容
       * links:  {array} 网页中引用的链接地址（已转换为绝对地址）


## 测试
```
npm run test
```

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