# stylesheet-writer

> Write properties to style file using selector

Latest version **1.0.1** (published 2019-06-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install stylesheet-writer
pnpm add stylesheet-writer
yarn add stylesheet-writer
bun add stylesheet-writer
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-06-23 |
| First published | 2019-06-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 21.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Adrien Gicquel |
| Maintainers | adriengicquel |
| Keywords | style, stylesheet, css, scss, less |

## Links

- npm: https://www.npmjs.com/package/stylesheet-writer
- Repository: https://github.com/adriengcql/stylesheet-writer
- Homepage: https://github.com/adriengcql/stylesheet-writer#readme
- Issues: https://github.com/adriengcql/stylesheet-writer/issues
- npm.io page: https://npm.io/package/stylesheet-writer

## Dependencies (1)

- [fs-extra](https://npm.io/package/fs-extra.md) ^8.0.1

## 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

- 1.0.1 (latest) — 2019-06-23
- 1.0.0 — 2019-06-14

## README

# Stylesheet Writer

Write properties by selector to css, scss or less files.

Given a selector, a property name and a value, the property will be overwritten or added.


## Quick start

```
npm install stylesheet-writer
```
```js
import * as sw from 'stylesheet-writer'

const style = sw.open('__YOUR_PATH_TO_FILE__')
style.writeProperty('.container', 'color', 'blue') // writeProperty(__SELECTOR__, __PROPERTY_NAME__, __VALUE__)
```

```css
.container {
    color: red;
}
/* --> */
.container {
    color: blue;
}
```


## Methods

### `open(path: string, options?)`

Load the file for the given absolute path (must be `css`, `scss` or `less`).

options: `{ autosave: boolean, autorefresh: boolean }`

### `.writeProperty(selector: string, property: string, value: string)`

Write a property to the opened file.

### `.save()`

Save the opened file.

### `.refresh()`

Reload the opened file.



## Options

### `autosave`

default: `true`

If set to `true`, the file will be written every time you use `writeProperty()`, but for better performances you may want to decide when saving the file.

```js
const style = open('__YOUR_PATH_TO_FILE__', { autosave: false })
// do some work
style.save()
```
[!WARNING]
The file does not stay open, it's just loaded, so if `autorefresh` is set to `false`, any changes made outside will be overwritten when saving.

### `autorefresh`

default: `true`
(disabled if `autosave` is set to `false`)

If set to `true`, each time you use `writeProperty()` the file is read to load most recent change and avoid overwritting, but for better performances you may want to disable that.

```js
const style = open('__YOUR_PATH_TO_FILE__', { autorefresh: false })
// modify file outside
style.refresh()
// do some work
// style.save()
```

[!WARNING]
If `autosave` is set to `false` and `refresh()` is used without saving before, any change made with `writeProperty()` will be lost.

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