# yyl-file-replacer

> a file replace plugin for yyl

Latest version **0.6.4** (published 2021-02-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install yyl-file-replacer
pnpm add yyl-file-replacer
yarn add yyl-file-replacer
bun add yyl-file-replacer
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.4 |
| Published | 2021-02-04 |
| First published | 2018-08-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 33.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | jackness |
| Maintainers | jackness |

## Links

- npm: https://www.npmjs.com/package/yyl-file-replacer
- Repository: https://github.com/jackness1208/yyl-file-replacer
- Homepage: https://github.com/jackness1208/yyl-file-replacer#readme
- Issues: https://github.com/jackness1208/yyl-file-replacer/issues
- npm.io page: https://npm.io/package/yyl-file-replacer

## Recent versions

- 0.6.4 (latest) — 2021-02-04
- 0.6.3 — 2020-09-26
- 0.6.2 — 2020-02-23
- 0.6.1 — 2020-02-23
- 0.6.0 — 2020-02-18
- 0.5.0 — 2020-02-02
- 0.5.0-beta1 — 2020-02-02
- 0.4.4 — 2020-02-02
- 0.4.3 — 2020-02-02
- 0.4.2 — 2020-02-02
- 0.4.1 — 2018-10-18
- 0.4.0 — 2018-09-28
- 0.3.1 — 2018-08-21
- 0.3.0 — 2018-08-06
- 0.2.0 — 2018-08-02
- … 1 more at https://npm.io/package/yyl-file-replacer/versions

## README

# yyl-file-replacer
a file replace plugin for yyl

## 安装
```bash
npm i yyl-file-replacer --save
```

## 引入
```js
const replacer = require('yyl-file-replacer')
```
## usage
### htmlPathMatch
```typescript
enum MatchType {
  CSS_PATH = 'css-path',
  JS_PATH = 'js-path',
  HTML_PATH = 'html-path'
}
interface Replacer {
  htmlPathMatch(ctx: string, handle: (matchUrl: string, type: MatchType) => string): string
}
```

#### example
```javascript
const { htmlPathMatch } = require('yyl-file-replacer')
const htmlStr = `
  <link rel="stylesheet" href="./link-href/1.css" type="text/css">
`
const r = []
htmlPathMatch(htmlStr, (matchUrl, type) => {
  r.push(matchUrl)
})
console.log(r) // [./link-href/1.css]
```

### jsPathMatch
```typescript
interface Replacer {
  jsPathMatch(ctx: string, handle: (matchUrl: string, type: MatchType.JS_PATH) => string): string
}
```
#### example
```javascript
const { jsPathMatch } = require('yyl-file-replacer')
const jsStr = `
  const a = __url('path/to/js')
  const b = __html('path/to/html')
`
const r = []
jsPathMatch(jsStr, (url, type, q) => {
  r.push({url, type, q})
)
console.log(r) // [{ url: 'path/to/js', type: '__url', q: '\''}, { url: 'path/to/html', type: '__html', q: '\''}]
```

### cssPathMatch
```typescript
interface Replacer {
  cssPathMatch(ctx: string, handle: (matchUrl: string, type: MatchType.CSS_PATH) => string): string
}
```
#### example
```javascript
const { cssPathMatch } = require('yyl-file-replacer')
const cssStr = `
  body { background: url(path/to/a) }
`
const r = []
cssPathMatch(cssStr, (matchUrl, type) => {
  r.push(matchUrl)
)
console.log(r) // [path/to/a]
```


## 版本信息
[这里](./history.md)

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