Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.
/ css-collapse-values Public archive

Collapse CSS values into their shortest form.

License

Notifications You must be signed in to change notification settings

jamen/css-collapse-values

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

css-collapse-values NPM version Build Status

Collapse CSS values into their shortest form.

Given property values that behave similar to margin:

.foo { margin: 10px 5px 10px 5px; }
/* collapsed: */
.foo { margin: 10px 5px; }

Collapse them into their shortest form using this module:

const collapse = require('collapse');

collapse(['1px', '2px', '1px', '2px']);
// => ['1px', '2px']

collapse(['2em', '4em', '6em', '4em']);
// => ['2em', '4em', '6em']

collapse(['10%', '30%', '10%']);
// => ['10%', '30%']

Uses css-truncate-values to get the shortest possible results.

Installation

$ npm install --save css-collapse-values

API

collapse(values)

Collapse the values, always returning an array.

  • values (Array): An array of 4 or less CSS number values. (i.e. ['1em', '2em', '1em'])
collapse(['10px', '10px', '10px', '10px'])
// => ['10px']

collapse(['-0.10em', '05px', '-0.100em', '5.0px']);
// => ['-.1em', '5px']

Also See

postcss-collapse: A postcss version of this.

css-truncate-values: Truncate CSS numbers while retaining the original value.

css-strip-units: Strip the unit off a CSS number.

License

MIT © Jamen Marz

About

Collapse CSS values into their shortest form.

Resources

License

Stars

Watchers

Forks

Packages

No packages published