New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

css-patch

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-patch

CSS patch generator.

Source
npmnpm
Version
1.1.2
Version published
Weekly downloads
2
-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

css-patch

npm versionnode versionBuild status - Linux/OSXBuild status - WindowsCodecov

Generating CSS patches (just like a diff).

Reasons to use

Themes generation

The easiest way to make a new theme is just copy the file and change some stuff or if you use preprocessor (such as SCSS, Less, etc.) you can just change some variables and get a new style.

But serving files with big amount of literally the same code is not a good idea, so this is when css-patch can help you.

You can pass 2 stylesheets (original/base and expected) to generateCSSPatch and get a new stylesheet. This new stylesheet is intended to be applied after original one and will have the same effect as if you applied expected one. In other words, the new stylesheet will consist of the resulting "overloads" for the original one.

Extracting difference

Imagine if you have two versions of the same CSS.

You can use this module to get the "difference" between them.

Install

Install via yarn:

yarn add css-patch

Install via npm:

npm i css-patch

Docs

Read the docs on GitHub pages.

For advanced usage see the docs for transformCSS function and CSSTransformerBase class.

Possible caveats

unset

If something existed in original stylesheet missing in expected one, will result of being transformed to <something>: unset;.

Combined rule orders

Logically the same but with a different order combined rules (e.g. .a,.b and .b,.a) will be considered as a different rules.

Merged rules

If rules have exact the same name their declarations would be merged (later appeared declarations will be a higher priority).

For example .a{a:1;c:3;}.a{a:2;b:2;} will be threat as .a{a:2;b:2;c;3}.

Sorting

Declarations are sorted alphabetically.

Usage example

Import

CommonJS

const { generateCSSPatch, } = require('css-patch');

ES6

import { generateCSSPatch, } from 'css-patch';

Use

console.log(
	generateCSSPatch(
		'a{a:1;b:1;}b{b:1;}c{a:1;}d{a:1;}',
		'a{a:1;}b{b:2;}c{a:1;}'
	)
); // 'a{b:unset;}b{b:2;}d{a:unset;}'

Keywords

css

FAQs

Package last updated on 10 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts