Skip to content

Commit 5d96c57

Browse files
committed
fix readme
1 parent c56289f commit 5d96c57

File tree

3 files changed

+112
-4
lines changed

3 files changed

+112
-4
lines changed

README.md

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,68 @@
1-
# CSS Layers
1+
# css-layer-tree
22

3-
Discover the composition of your CSS `@layer`s
3+
Lay out the composition of your CSS `@layer` architecture. See which layers are used, where they are defined and how they are nested.
44

5-
WORK IN PROGRESS | CHECK BACK SOON
5+
## Installation
6+
7+
```
8+
npm install @projectwallace/css-layer-tree
9+
```
10+
11+
## Usage
12+
13+
```js
14+
import { get_tree } from '@projectwallace/css-layer-tree'
15+
16+
let css = `
17+
@import url("test.css") layer;
18+
@import url("test.css") LAYER(test);
19+
@layer anotherTest {
20+
@layer moreTest {
21+
@layer deepTest {}
22+
}
23+
};
24+
/* anonymous @layer */
25+
@layer {}
26+
`
27+
28+
let tree = get_tree(css)
29+
```
30+
31+
This example would result in this `tree`:
32+
33+
```js
34+
;[
35+
{
36+
name: '__anonymous-1__',
37+
locations: [{ line: 2, column: 3, start: 3, end: 33 }],
38+
children: [],
39+
},
40+
{
41+
name: 'test',
42+
locations: [{ line: 3, column: 3, start: 36, end: 72 }],
43+
children: [],
44+
},
45+
{
46+
name: 'anotherTest',
47+
locations: [{ line: 4, column: 3, start: 75, end: 148 }],
48+
children: [
49+
{
50+
name: 'moreTest',
51+
locations: [{ line: 5, column: 4, start: 99, end: 144 }],
52+
children: [
53+
{
54+
name: 'deepTest',
55+
locations: [{ line: 6, column: 5, start: 121, end: 139 }],
56+
children: [],
57+
},
58+
],
59+
},
60+
],
61+
},
62+
]
63+
```
64+
65+
## Related projects
66+
67+
- [Online CSS Layers visualizer](https://www.projectwallace.com/css-layers-visualizer) - See this library in action online!
68+
- [CSS Analyzer](https://github.com/projectwallace/css-analyzer) - The best CSS analyzer that powers all analysis on [projectwallace.com](https://www.projectwallace.com)

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"layer",
4949
"layers",
5050
"composition",
51-
"architecture"
51+
"architecture",
52+
"tree"
5253
],
5354
"prettier": {
5455
"semi": false,

test/global.spec.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,48 @@ test('handles CSS without layers', () => {
1010
assert.equal(get_tree('@media all { body { color: red; } }'), [])
1111
})
1212

13+
test('mixed imports and layers', () => {
14+
let actual = get_tree(`
15+
@import url("test.css") layer;
16+
@import url("test.css") LAYER(test);
17+
@layer anotherTest {
18+
@layer moreTest {
19+
@layer deepTest {}
20+
}
21+
};
22+
/* anonymous @layer */
23+
@layer {}
24+
`)
25+
let expected = [
26+
{
27+
name: '__anonymous-1__',
28+
locations: [{ line: 2, column: 3, start: 3, end: 33 }],
29+
children: []
30+
},
31+
{
32+
name: 'test',
33+
locations: [{ line: 3, column: 3, start: 36, end: 72 }],
34+
children: []
35+
},
36+
{
37+
name: 'anotherTest',
38+
locations: [{ line: 4, column: 3, start: 75, end: 148 }],
39+
children: [
40+
{
41+
name: 'moreTest',
42+
locations: [{ line: 5, column: 4, start: 99, end: 144 }],
43+
children: [
44+
{
45+
name: 'deepTest',
46+
locations: [{ line: 6, column: 5, start: 121, end: 139 }],
47+
children: []
48+
}
49+
]
50+
}
51+
]
52+
}
53+
]
54+
assert.equal(actual, expected)
55+
})
56+
1357
test.run()

0 commit comments

Comments
 (0)