# postcss-replace

> PostCSS plugin for replacing strings.

Latest version **2.0.1** (published 2023-03-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install postcss-replace
pnpm add postcss-replace
yarn add postcss-replace
bun add postcss-replace
```

## 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 | 2.0.1 |
| Published | 2023-03-21 |
| First published | 2017-10-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | ^12 \|\| ^14 \|\| >=16 |
| Dependencies | 2 |
| Unpacked size | 21 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 28 |
| Author | Gridonic |
| Maintainers | axooh, dschenk, jfierz |
| Keywords | postcss, css, postcss-plugin, replace, strings |

## Links

- npm: https://www.npmjs.com/package/postcss-replace
- Repository: https://github.com/gridonic/postcss-replace
- Homepage: https://github.com/gridonic/postcss-replace#readme
- Issues: https://github.com/gridonic/postcss-replace/issues
- npm.io page: https://npm.io/package/postcss-replace

## Dependencies (2)

- [kind-of](https://npm.io/package/kind-of.md) ^6.0.3
- [object-path](https://npm.io/package/object-path.md) ^0.11.8

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2023-03-21
- 2.0.0 — 2022-02-14
- 1.1.3 — 2021-03-02
- 1.1.2 — 2020-04-14
- 1.1.1 — 2020-04-14
- 1.1.0 — 2019-10-21
- 1.0.8 — 2019-09-13
- 1.0.7 — 2019-07-12
- 1.0.6 — 2019-04-12
- 1.0.5 — 2019-03-11
- 1.0.4 — 2019-01-28
- 1.0.3 — 2018-04-11
- 1.0.2 — 2018-03-21
- 1.0.1 — 2017-12-11
- 1.0.0 — 2017-10-30

## README

# PostCSS Replace [<img src="http://postcss.github.io/postcss/logo.svg" alt="PostCSS" width="90" height="90" align="right">][PostCSS] 

[![NPM Version][npm-img]][npm-url]
[![Build Status][cli-img]][cli-url]
[![Coverage Status][cov-img]][cov-url]
[![Licensing][lic-img]][lic-url]
[![Changelog][log-img]][log-url]

[PostCSS] plugin for replacing strings.

**Write this:**

```css
/* CustomCSS Library v{{ version }} */
.foo {
  content: "{{ author }}";
}
```

**And get this:**

```css
/* CustomCSS Library v1.3.7 */
.foo {
  content: "Gridonic";
}
```

## Installation

`$ npm install postcss-replace`

## Usage

```JS
postcss([ require('postcss-replace') ])
```

See [PostCSS](https://github.com/postcss/postcss) docs for [examples regarding usage](https://github.com/postcss/postcss#usage).

## Options

### `pattern`

- Type: `string` | `RegEx`
- Default: `'{{\\s?([^\\s]+?)\\s?}}'`

The default pattern will replace strings in the format of `{{ myExampleKey }}`. Adjust this pattern if you want 
something different, for example `/_([^\s]+?)_/` to match strings like `_myExampleKey_`.

### `commentsOnly`

- Type: `boolean`
- Default: `false`

By default the plugin will replace strings in comments _and_ values. Turn this to `true` if you _only_ want to replace strings 
in comments.

### `data`

- Type: `object`
- Default: `{}`

This is the key → value object that provides the data for the plugin for replacing strings.

- If the key `replaceAll` is provided all matched strings will be replaced by the given value
e.g:
`data: { replaceAll: 'replace all matched strings with this text' }` 

## Testing

Tests can be run via the following command:

`$ npm run test`

We use mutant-testing to test the resilience of our tests. 
Stryker can be run via the following command:

`$ npm run test:mutate`

[npm-url]: https://www.npmjs.com/package/postcss-replace
[npm-img]: https://img.shields.io/npm/v/postcss-replace.svg
[cli-url]: https://travis-ci.org/gridonic/postcss-replace
[cli-img]: https://travis-ci.org/gridonic/postcss-replace.svg
[lic-url]: LICENSE
[lic-img]: https://img.shields.io/npm/l/postcss-replace.svg
[log-url]: CHANGELOG.md
[log-img]: https://img.shields.io/badge/changelog-md-blue.svg
[cov-url]: https://coveralls.io/github/gridonic/postcss-replace?branch=master
[cov-img]: https://coveralls.io/repos/github/gridonic/postcss-replace/badge.svg?branch=master

[PostCSS]: https://github.com/postcss/postcss

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