-
Notifications
You must be signed in to change notification settings - Fork 14
Optional number elongation #18
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,6 +108,14 @@ const BIDI_MAP = { | |
| Z: "Z" | ||
| }; | ||
|
|
||
| const EVEN_NUMBER_MAP = { | ||
| 0: '⁰', | ||
| 2: '²', | ||
| 4: '⁴', | ||
| 6: '⁶', | ||
| 8: '⁸' | ||
| }; | ||
|
|
||
| const strategies = { | ||
| accented: { | ||
| prefix: "", | ||
|
|
@@ -126,30 +134,40 @@ const strategies = { | |
| }; | ||
|
|
||
| const psuedoLocalizeString = (string, options = { strategy: "accented" }) => { | ||
| let opts = strategies[options.strategy]; | ||
| let strategyOptions = strategies[options.strategy]; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice rename :) |
||
|
|
||
| let pseudoLocalizedText = ""; | ||
| for (let character of string) { | ||
| if (opts.map[character]) { | ||
| const convertedCharacter = strategyOptions.map[character] | ||
| const characterAsInt = parseInt(character) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can move this inline to line 146. !isNaN(parseInt(character))imo it's still totally legible and we avoid executing parseInt for every character if Now that I think about it do we need to parseInt? would options.elongateNumbers &&
EVEN_NUMBER_MAP[character]not be enough? |
||
|
|
||
| if ( | ||
| options.elongateNumbers && | ||
| !isNaN(characterAsInt) && | ||
| EVEN_NUMBER_MAP[character] | ||
| ) { | ||
| // Duplicate even numbers with superscript variations | ||
| pseudoLocalizedText += character + EVEN_NUMBER_MAP[character]; | ||
| } else if (convertedCharacter) { | ||
| const cl = character.toLowerCase(); | ||
| // duplicate "a", "e", "o" and "u" to emulate ~30% longer text | ||
| // Duplicate "a", "e", "o" and "u" to emulate ~30% longer text | ||
| if ( | ||
| opts.elongate && | ||
| strategyOptions.elongate && | ||
| (cl === "a" || cl === "e" || cl === "o" || cl === "u") | ||
| ) { | ||
| pseudoLocalizedText += opts.map[character] + opts.map[character]; | ||
| } else pseudoLocalizedText += opts.map[character]; | ||
| pseudoLocalizedText += convertedCharacter.repeat(2); | ||
| } else pseudoLocalizedText += strategyOptions.map[character]; | ||
| } else pseudoLocalizedText += character; | ||
| } | ||
|
|
||
| // If this string is from the DOM, it should already contain the pre- and postfix. | ||
| if ( | ||
| pseudoLocalizedText.startsWith(opts.prefix) && | ||
| pseudoLocalizedText.endsWith(opts.postfix) | ||
| pseudoLocalizedText.startsWith(strategyOptions.prefix) && | ||
| pseudoLocalizedText.endsWith(strategyOptions.postfix) | ||
| ) { | ||
| return pseudoLocalizedText; | ||
| } | ||
| return opts.prefix + pseudoLocalizedText + opts.postfix; | ||
| return strategyOptions.prefix + pseudoLocalizedText + strategyOptions.postfix; | ||
| }; | ||
|
|
||
| module.exports = psuedoLocalizeString; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There will be conflicts on this line after rebase, I think the best fix is
to keep deep defaults and avoid
can not find elongateNumbers of undefinedErrors in edge cases!