Skip to content

Commit

Permalink
Remove the string hash dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
emilos committed Sep 13, 2024
1 parent ef6bbca commit b04b46d
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 25 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { join } = require("path")
const { readFileSync } = require("fs")
const csstree = require("css-tree")
const toHash = require("string-hash")

function compile(path) {
const fn = require(path)
Expand Down Expand Up @@ -268,6 +267,11 @@ const tag = (a, b, c) => {
}
}

let number = 1
function sequence() {
return number++
}

function css(inputs) {
let result = ""
for (let i = 0, ilen = inputs.length; i < ilen; i += 1) {
Expand All @@ -279,7 +283,7 @@ function css(inputs) {
result += input
}
}
const hash = toHash(result).toString(36).substr(0, 5)
const hash = sequence()
const tree = csstree.parse(result)
const classes = {}

Expand Down
13 changes: 1 addition & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@
]
},
"dependencies": {
"css-tree": "^3.0.0",
"string-hash": "^1.1.3"
"css-tree": "^3.0.0"
},
"prettier": {
"semi": false
Expand Down
2 changes: 1 addition & 1 deletion test/components/a/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ test("#components/a: it returns a component with css", () => {
},
"foo"
),
'<a class="link_1f29w foo" href="/bar" target="_blank">foo</a>'
'<a class="link_1 foo" href="/bar" target="_blank">foo</a>'
)
})
4 changes: 2 additions & 2 deletions test/components/accordion/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ test("#components/accordion: it returns a component with css", () => {
const { template } = compile(join(__dirname, "./index.js"))

const html = template({ title: "foo" }, "bar")
assert(html.includes('<h3 class="accordion_1pc2b">foo</h3>'))
assert(html.includes('<div class="content_1pc2b hidden_1pc2b">bar</div>'))
assert(html.includes('<h3 class="accordion_1">foo</h3>'))
assert(html.includes('<div class="content_1 hidden_1">bar</div>'))
})
8 changes: 4 additions & 4 deletions test/components/arrow/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ test("#components/arrow: it returns a component with css", () => {

assert.deepEqual(
template({ direction: "top" }),
'<span class="arrow_19kjp top_19kjp"></span>'
'<span class="arrow_1 top_1"></span>'
)
assert.deepEqual(
template({ direction: "right" }),
'<span class="arrow_19kjp right_19kjp"></span>'
'<span class="arrow_1 right_1"></span>'
)
assert.deepEqual(
template({ direction: "bottom" }),
'<span class="arrow_19kjp bottom_19kjp"></span>'
'<span class="arrow_1 bottom_1"></span>'
)
assert.deepEqual(
template({ direction: "left" }),
'<span class="arrow_19kjp left_19kjp"></span>'
'<span class="arrow_1 left_1"></span>'
)
})
2 changes: 1 addition & 1 deletion test/pages/landing/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ test("#pages/landing: it returns a page with css", async () => {

assert.deepEqual(
template({ language: "en" }),
'<!DOCTYPE html><html lang="en"><head><title>Landing page</title><style>body{background:#ccc;font-family:"Lato"}.button_1lo7m{color:red}.button_1lo7m:hover{color:blue}</style></head><body><button class="button_1lo7m">Bar</button></body></html>'
'<!DOCTYPE html><html lang="en"><head><title>Landing page</title><style>body{background:#ccc;font-family:"Lato"}.button_2{color:red}.button_2:hover{color:blue}</style></head><body><button class="button_2">Bar</button></body></html>'
)
})
2 changes: 1 addition & 1 deletion test/pages/styleguide/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test("#pages/styleguide: it returns a page with css", async () => {
const html = template({ language: "pl" })
assert(
html.includes(
"@media only screen and (max-width:767px){.sidebar_ake0o{display:none}}"
"@media only screen and (max-width:767px){.sidebar_1{display:none}}"
)
)
assert(!html.includes("undefined"))
Expand Down

0 comments on commit b04b46d

Please sign in to comment.