-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Added support for converting arbitrary fractions #96
base: main
Are you sure you want to change the base?
Conversation
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.
Some minor code style stuff, but generally this looks really cool! Thanks!
"⅜": 3 / 8, | ||
"⅝": 5 / 8, | ||
"⅞": 7 / 8 | ||
const afractions = Object.freeze({ |
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.
Hmm, now I don't quite get the different from afractions
to fractions
? Is it just to have an intermediate variable?
If so, I still don't like that naming by putting a "random" a
in front… like maybe name it even fractionsTemp
or even better put it out of scope completely, so no one can accidentally use the "intermediate/temp" variable.
Like maybe having a function getFractions
or so that defines this inline?
IMHO that would be good.
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.
Both fractions
variables are used. In order to support the new arbitrary fraction replacements, we need the separate numerator and denominator values for these hardcoded Unicode fraction characters, so I had to add an additional variable.
* @returns {string} | ||
*/ | ||
function sentenceCase(text) { | ||
return Array.from(segmenter2.segment(text), ({ segment: [h, ...t] }) => h.toLocaleUpperCase() + t.join("")).join(""); |
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.
h and t … can we find a long name for that?
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.
(also above)
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.
h = head and t = tail.
const result = Object.entries(afractions).find(([, [anumerator, adenominator]]) => anumerator === numerator && adenominator === denominator); | ||
let label; | ||
if (result) { | ||
[label] = result; |
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.
Uhm this syntax looks wild to me… just curious what is that? 😲
Puts it into an array?
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.
This is just using the destructuring assignment syntax. I find it cleaner than writing the equivalent:
label = result[0];
Intl.Segmenter
.RegExp.escape
if available.