-
-
Notifications
You must be signed in to change notification settings - Fork 1
Add keyboard layout converter module with 15 language support for shortcut #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,23 @@ | ||
| ## Coding Style & Guidelines | ||
|
|
||
| - Whenever possible, prioritize code readability over code efficiency. | ||
| - Always write code that's short and concise. Make good use of early return techniques, and be careful not to create too much depth in conditional statements or loops. | ||
| - For object-type properties or types or interfaces, always sort in alphabetical order whenever possible. | ||
| - Always keep variable and property names concise but clear. | ||
| - Always maintain a clear separation of concerns. However, be careful not to over-segregate, such as through premature optimization. | ||
| - You should always write your code in a way that makes it easy to unit test. | ||
| - Comments shouldn't be used unless absolutely necessary. Write readable code that can be understood without comments, and only include comments for unavoidable business logic. | ||
| - Variable values should be separated into constants whenever possible. Avoid creating magic numbers. | ||
| - If a complex implementation is required, always consider using a commercial library or tool instead of coding it yourself. | ||
| - Work should always be done agilely, in small units, and in meaningful change units. | ||
| - Instead of rushing to implement it, you should always focus on writing clean code that doesn't create bugs and is easy to maintain. | ||
| - If you feel like there's too much code in a single file, you should first review the overall structure and figure out how to neatly separate the files. | ||
| - Always understand the surrounding code context, and when you see signs of reuse, modularize it to avoid code duplication. | ||
| - The depth of loops and conditional statements should be as minimal as possible. It's best to avoid them altogether. | ||
| - If a function is likely to have more than three arguments, always consider making them object or struct arguments. | ||
|
|
||
| ## TypeScript Coding Guidelines | ||
|
|
||
| - When using TypeScript, avoid using unsafe type systems such as the any type and type assertions whenever possible. | ||
| - Always use Type instead of Interface | ||
| - Always use arrow functions outside of a class. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,143 @@ | ||
| import { | ||
| generateKeyVariants, | ||
| findMatchingShortcut, | ||
| } from "./keyboard-layout-converter"; | ||
|
|
||
| describe("generateKeyVariants", () => { | ||
| it("should return input key with case variations for single character", () => { | ||
| const variants = generateKeyVariants("q"); | ||
| expect(variants).toContain("q"); | ||
| expect(variants).toContain("Q"); | ||
| }); | ||
|
|
||
| it("should include Korean conversion for q key", () => { | ||
| const variants = generateKeyVariants("q"); | ||
| expect(variants).toContain("ㅂ"); | ||
| }); | ||
|
|
||
| it("should include English conversion for Korean key", () => { | ||
| const variants = generateKeyVariants("ㅂ"); | ||
| expect(variants).toContain("q"); | ||
| }); | ||
|
|
||
| it("should return original input for non-single character input", () => { | ||
| const variants = generateKeyVariants("abc"); | ||
| expect(variants).toEqual(["abc"]); | ||
| }); | ||
|
|
||
| it("should return original input for empty string", () => { | ||
| const variants = generateKeyVariants(""); | ||
| expect(variants).toEqual([""]); | ||
| }); | ||
|
|
||
| it("should handle Russian characters", () => { | ||
| const variants = generateKeyVariants("й"); | ||
| expect(variants).toContain("q"); | ||
| }); | ||
|
|
||
| it("should handle Arabic characters", () => { | ||
| const variants = generateKeyVariants("ض"); | ||
| expect(variants).toContain("z"); | ||
| }); | ||
|
|
||
| it("should handle Hebrew characters", () => { | ||
| const variants = generateKeyVariants("ק"); | ||
| expect(variants).toContain("e"); | ||
| }); | ||
|
|
||
| it("should handle German characters", () => { | ||
| const variants = generateKeyVariants("ü"); | ||
| expect(variants).toContain("["); | ||
| }); | ||
|
|
||
| it("should handle Spanish characters", () => { | ||
| const variants = generateKeyVariants("ñ"); | ||
| expect(variants).toContain(";"); | ||
| }); | ||
|
|
||
| it("should handle Greek characters", () => { | ||
| const variants = generateKeyVariants("θ"); | ||
| expect(variants).toContain("u"); | ||
| }); | ||
|
|
||
| it("should handle Japanese hiragana characters", () => { | ||
| const variants = generateKeyVariants("あ"); | ||
| expect(variants).toContain("a"); | ||
| }); | ||
|
|
||
| it("should handle Japanese katakana characters", () => { | ||
| const variants = generateKeyVariants("ア"); | ||
| expect(variants).toContain("a"); | ||
| }); | ||
|
|
||
| it("should handle Chinese characters", () => { | ||
| const variants = generateKeyVariants("你"); | ||
| expect(variants).toContain("你"); | ||
| }); | ||
|
|
||
| it("should handle Hindi Devanagari characters", () => { | ||
| const variants = generateKeyVariants("अ"); | ||
| expect(variants).toContain("a"); | ||
| }); | ||
|
|
||
| it("should handle numbers and special characters", () => { | ||
| const variants = generateKeyVariants("1"); | ||
| expect(variants).toContain("1"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("findMatchingShortcut", () => { | ||
| const shortcuts = ["q", "t", "g", "n"]; | ||
|
|
||
| it("should find exact match for English character", () => { | ||
| const result = findMatchingShortcut("q", shortcuts); | ||
| expect(result).toBe("q"); | ||
| }); | ||
|
|
||
| it("should find match for Korean character mapping to English", () => { | ||
| const result = findMatchingShortcut("ㅂ", shortcuts); | ||
| expect(result).toBe("q"); | ||
| }); | ||
|
|
||
| it("should find match for Russian character mapping to English", () => { | ||
| const result = findMatchingShortcut("й", shortcuts); | ||
| expect(result).toBe("q"); | ||
| }); | ||
|
|
||
| it("should return undefined for non-matching character", () => { | ||
| const result = findMatchingShortcut("x", shortcuts); | ||
| expect(result).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("should return undefined for multi-character input", () => { | ||
| const result = findMatchingShortcut("qt", shortcuts); | ||
| expect(result).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("should handle case insensitive matching", () => { | ||
| const result = findMatchingShortcut("Q", shortcuts); | ||
| expect(result).toBe("q"); | ||
| }); | ||
|
|
||
| it("should handle empty shortcuts array", () => { | ||
| const result = findMatchingShortcut("q", []); | ||
| expect(result).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("should handle shortcuts with undefined values", () => { | ||
| const result = findMatchingShortcut("q", ["q", undefined as any, "t"]); | ||
| expect(result).toBe("q"); | ||
| }); | ||
|
|
||
| it("should match Korean ㅅ with t shortcut", () => { | ||
| const shortcutsWithT = ["s", "t", "g"]; | ||
| const result = findMatchingShortcut("ㅅ", shortcutsWithT); | ||
| expect(result).toBe("t"); | ||
| }); | ||
|
|
||
| it("should match Korean ㄴ with s shortcut", () => { | ||
| const shortcutsWithS = ["s", "t", "g"]; | ||
| const result = findMatchingShortcut("ㄴ", shortcutsWithS); | ||
| expect(result).toBe("s"); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.