1.1.0 • Published 3 years ago

css-preprocessor-variables v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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