Skip to content

saulhardman/parse-css-custom-properties

Repository files navigation

Parse CSS Custom Properties

Release Actions Status

A JavaScript module to parse CSS Custom Properties from CSS files into a JavaScript Object.

Example Usage

/* input.css */
:root {
  --example-custom-property: 2rem;
}
import parseCssCustomProperties, {
  sync as parseCustomCssPropertiesSync,
} from '@saulhardman/parse-css-custom-properties';

(async () => {
  const customProperties = await parseCssCustomProperties(['input.css']);

  console.log(customProperties);
  // { '--example-custom-property': '2rem' }
})();

const customProperties = parseCustomCssPropertiesSync(['input.css']);

console.log(customProperties);
// { '--example-custom-property': '2rem' }

Installation

Configure npm client:

# .npmrc
@saulhardman:registry=https://npm.pkg.github.com
# .yarnrc
"@saulhardman:registry" "https://npm.pkg.github.com"

Note: If you'd like this package to be available via the npm package registry as well as the GitHub Package Registry then please create an issue.

Using npm:

> npm install --save-dev @saulhardman/parse-css-custom-properties

Using Yarn:

> yarn add --dev @saulhardman/parse-css-custom-properties

Arguments

patterns

Type: Array Default: []

An array of glob patterns that match the CSS files to parse.

options

Type: Object Default: { globOptions: undefined }

Options

globOptions

Type: Object Default: undefined

Options passed to glob.

License

MIT © Saul Hardman