Skip to content

Latest commit

 

History

History
89 lines (69 loc) · 2.87 KB

File metadata and controls

89 lines (69 loc) · 2.87 KB

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.