Vetting the cargo
Vetting the cargo
Posted Jun 13, 2022 12:59 UTC (Mon) by larkey (guest, #104463)In reply to: Vetting the cargo by ballombe
Parent article: Vetting the cargo
However, just as the original comment disregarded how well or badly npm-leftpad works, I chose to do so as well.
Which I demonstrated by plugging in example strings into the code given. So if there is something not-well-defined, then it's the behavior of the original comments code in the quite common case of feeding something outside of the C locale.
Regardless, although I'm not an expert in this area, I'd say even this is well-defined albeit not what's wanted. The result depends on the compilation environment, that is, how the Compiler translates the source from the respective character set into byte arrays. From there on, everything works "as intended", the first string is 3 bytes "wide, the second 2, the last just 1. Hence a padding of 0, 1 and 2 bytes conversely.
I'm obviously aware of how this is not how things work, I'm merely demonstrating how lacking the above code is and that there is a merit in using a library for this task, and that this doesn't discredit the engineer. Don't use npm-leftpad though.
