3.0.1 • Published 7 years ago
parse-css-sides v3.0.1
parse-css-sides
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 testThis will run the tests in watch mode.
$ npm run coverThis will run tests and generate a code coverage report. Anything less than 100% coverage will throw an error.