Skip to content

Commit

Permalink
replace String.slice() with stringBySlice
Browse files Browse the repository at this point in the history
  • Loading branch information
bartveneman committed Sep 27, 2024
1 parent 7f9e881 commit ed828b5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-expect-error Typing of css-tree is incomplete
import parse from 'css-tree/parser'
import stringByteSlice from 'string-byte-slice'

const SPACE = ' '
const EMPTY_STRING = ''
Expand Down Expand Up @@ -64,7 +65,7 @@ export function format(css, { minify = false } = {}) {
function substr(node) {
let loc = node.loc
if (!loc) return EMPTY_STRING
return css.slice(loc.start.offset, loc.end.offset)
return stringByteSlice(css, loc.start.offset, loc.end.offset)
}

/** @param {import('css-tree').Rule} node */
Expand Down
12 changes: 11 additions & 1 deletion package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"vite-plugin-dts": "^4.0.0-beta.1"
},
"dependencies": {
"css-tree": "^3.0.0"
"css-tree": "^3.0.0",
"string-byte-slice": "^3.0.0"
},
"files": [
"dist"
Expand All @@ -53,4 +54,4 @@
"printWidth": 140,
"singleQuote": true
}
}
}

0 comments on commit ed828b5

Please sign in to comment.