css-preprocessor-variables

A plugin for convert css preprocessor file`s variables to json.

Usage no npm install needed!

<script type="module">
  import cssPreprocessorVariables from 'https://cdn.skypack.dev/css-preprocessor-variables';
</script>

README

css-preprocessor-variables

A plugin for convert css preprocessor`s variables to json.

install

>$ npm install css-preprocessor-variables
#or
>$ yarn add css-preprocessor-variables

usage

const getVars: (content: string, options: UserOptions) => Promise<Output>;

example

const getVars = require('css-preprocessor-variables');

getVars('@primary-color: #ffffff;\n @color: #000000', { type: 'less' }).then(({ variable }) => {
    console.log(variables); // { '@primary-color': '#ffffff', 'color': '#000000' }
});

or use it with promise

(async function () {
    const getVars = require('css-preprocessor-variables');

    const { variables } = await getVars('@primary-color: #ffffff;\n @color: #000000', { type: 'less' });

    console.log(variables); // { '@primary-color': '#ffffff', 'color': '#000000' }
})();

More examples in here

options

export interface Options {
    /**
     * Type of parser
     */
    type: 'less';

    /**
     * Format key of variables
     *
     * @default 'default'
     */
    format: 'camelCase' | 'kebabCase' | 'default';

    /**
     * Whether to remove the prefix
     *
     * @default false
     *
     * If true, strip prefix '@' or '


     */
    strip: boolean;

    /**
     * transform variables in current result
     *
     * @default true
     */
    transform: boolean;
}

license

MIT