Socket
Socket
Sign inDemoInstall

stylesheet-writer

Package Overview
Dependencies
4
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    stylesheet-writer

Write properties to style file using selector


Version published
Weekly downloads
2
Maintainers
1
Install size
199 kB
Created
Weekly downloads
 

Readme

Source

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
import * as sw from 'stylesheet-writer'

const style = sw.open('__YOUR_PATH_TO_FILE__')
style.writeProperty('.container', 'color', 'blue') // writeProperty(__SELECTOR__, __PROPERTY_NAME__, __VALUE__)
.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.

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.

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.

Keywords

FAQs

Last updated on 23 Jun 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc