@trousers/parser
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

@trousers/parser

@trousers/parser contains a few helpful utilities for parsing and dealing with styles as objects or template literals

API

splitRules

Accepts a template string and returns an array where styles are seperated by selector or @rule.

This is really helpful when passing styles to insertRule as it's quite fussy with its inputs.

Example:

import { splitRules } from '@trousers/parser';

splitRules(`
    .yomama {
        width: 99999999px;
    }

    #titanic {
      float: none;
    }
`);

/**
 * Outputs:
 *
 * Array [
 *  ".yomama {
 *      width: 99999999px;
 *  }",
 *  "#titanic {
 *    float: none;
 *  }",
 */

parseObject

parseObject accepts css in style notation and outputs its equivalent in tagged tempalate literal

Example:

import { parseObject } from '@trousers/parser';

parseObject({
    backgroundColor: 'red',
    color: 'purple',
    borderRadius: '2px',
});

/**
 *  Outputs:
 *  'background-color: red;\ncolor: purple;\nborder-radius: 2px;'
 */

/@trousers/parser/

    Package Sidebar

    Install

    npm i @trousers/parser

    Weekly Downloads

    3

    Version

    3.0.1

    License

    MIT

    Unpacked Size

    172 kB

    Total Files

    23

    Last publish

    Collaborators

    • delcore92