-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ecdc80
commit 9a7f19e
Showing
5 changed files
with
53 additions
and
1 deletion.
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
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,38 @@ | ||
import { describe, expect, test } from "@jest/globals"; | ||
import { stringToCSSUnicode } from "./stringToCSSUnicode"; | ||
|
||
describe("stringToCSSUnicode", () => { | ||
test("converts basic ASCII characters correctly", () => { | ||
expect(stringToCSSUnicode("Hello")).toBe("\\48\\65\\6c\\6c\\6f"); | ||
}); | ||
|
||
test("converts space character correctly", () => { | ||
expect(stringToCSSUnicode(" ")).toBe("\\20"); | ||
}); | ||
|
||
test("converts a string with special characters", () => { | ||
expect(stringToCSSUnicode("!@#$%^&*()_+")).toBe( | ||
"\\21\\40\\23\\24\\25\\5e\\26\\2a\\28\\29\\5f\\2b" | ||
); | ||
}); | ||
|
||
test("converts non-ASCII characters (e.g., accented letters)", () => { | ||
expect(stringToCSSUnicode("éåäö")).toBe("\\e9\\e5\\e4\\f6"); | ||
}); | ||
|
||
test("converts emojis correctly", () => { | ||
expect(stringToCSSUnicode("😀😃😄")).toBe("\\1f600\\1f603\\1f604"); | ||
}); | ||
|
||
test("handles an empty string", () => { | ||
expect(stringToCSSUnicode("")).toBe(""); | ||
}); | ||
|
||
test("converts a string with mixed character types", () => { | ||
expect(stringToCSSUnicode("Aa1!😀")).toBe("\\41\\61\\31\\21\\1f600"); | ||
}); | ||
|
||
test("converts characters outside the Basic Multilingual Plane", () => { | ||
expect(stringToCSSUnicode("𠮷")).toBe("\\20bb7"); | ||
}); | ||
}); |
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,7 @@ | ||
export const stringToCSSUnicode = (text: string): string => | ||
Array.from(text) | ||
.map((char: string) => { | ||
const codePoint = char.codePointAt(0); | ||
return codePoint !== undefined ? `\\${codePoint.toString(16)}` : ""; | ||
}) | ||
.join(""); |