-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Usage: ```js import { format, minify } from '@projectwallace/format-css' let minified = minify('a {}') // which is an alias for let formatted_mini = format('a {}', { minify: true }) ```
- Loading branch information
1 parent
413ba3f
commit a768c7d
Showing
3 changed files
with
111 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { suite } from "uvu" | ||
import * as assert from "uvu/assert" | ||
import { minify } from "../index.js" | ||
|
||
let test = suite("Minify") | ||
|
||
test('empty rule', () => { | ||
let actual = minify(`a {}`) | ||
let expected = `a{}` | ||
assert.equal(actual, expected) | ||
}) | ||
|
||
test('simple declaration', () => { | ||
let actual = minify(`:root { --color: red; }`) | ||
let expected = `:root{--color:red;}` | ||
assert.equal(actual, expected) | ||
}) | ||
|
||
test('simple atrule', () => { | ||
let actual = minify(`@media (min-width: 100px) { body { color: red; } }`) | ||
let expected = `@media (min-width: 100px){body{color:red;}}` | ||
assert.equal(actual, expected) | ||
}) | ||
|
||
test('empty atrule', () => { | ||
let actual = minify(`@media (min-width: 100px) {}`) | ||
let expected = `@media (min-width: 100px){}` | ||
assert.equal(actual, expected) | ||
}) | ||
|
||
test("formats multiline values on a single line", () => { | ||
let actual = minify(` | ||
a { | ||
background: linear-gradient( | ||
red, | ||
10% blue, | ||
20% green,100% yellow); | ||
} | ||
`); | ||
let expected = `a{background:linear-gradient(red, 10% blue, 20% green, 100% yellow);}`; | ||
assert.equal(actual, expected); | ||
}) | ||
|
||
test('Vadim Makeevs example works', () => { | ||
let actual = minify(` | ||
@layer what { | ||
@container (width > 0) { | ||
ul:has(:nth-child(1 of li)) { | ||
@media (height > 0) { | ||
&:hover { | ||
--is: this; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`) | ||
let expected = `@layer what{@container (width > 0){ul:has(:nth-child(1 of li)){@media (height > 0){&:hover{--is:this;}}}}}` | ||
assert.equal(actual, expected) | ||
}) | ||
|
||
test('minified Vadims example', () => { | ||
let actual = minify(`@layer what{@container (width>0){@media (min-height:.001px){ul:has(:nth-child(1 of li)):hover{--is:this}}}}`) | ||
let expected = `@layer what{@container (width > 0){@media (min-height: .001px){ul:has(:nth-child(1 of li)):hover{--is:this;}}}}` | ||
assert.equal(actual, expected) | ||
}) | ||
|
||
test.run() |