parse-css-sides
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

parse-css-sides

NPM version npm license Travis Build Status codecov Downloads Minified size Gzip size Unicorn Approved

npm

This package exports a default function that parses CSS sides (e.g., the value of margin, padding and border declarations).

Originally created for PostCSS plugins.

Installation

$ npm install parse-css-sides [--save[-dev]]

Usage

JavaScript

import parseSides from 'parse-css-sides';
const sides = parseSides('0 5% 10px');
/**
 * {
 *   top: '0',
 *   right: '5%',
 *   bottom: '10px',
 *   left: '5%',
 * }
 **/

All 4 sides are always returned and are always strings.

Note: if !important is found, an additional important: true will be added to the result.

TypeScript

This is a TypeScript project with generated type definitions included. There is an additional ISides interface that is exported if you need it for whatever reason. It just defines the shape of the result:

interface ISides {
    top: string
    right: string
    bottom: string
    left: string
    important?: boolean
}

Testing

$ npm test

This will run the tests in watch mode.

$ npm run cover

This will run tests and generate a code coverage report. Anything less than 100% coverage will throw an error.

/parse-css-sides/

    Package Sidebar

    Install

    npm i parse-css-sides

    Weekly Downloads

    1,592

    Version

    3.0.1

    License

    MIT

    Unpacked Size

    8.08 kB

    Total Files

    7

    Last publish

    Collaborators

    • jedmao