-
Notifications
You must be signed in to change notification settings - Fork 588
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
.toString(36) not properly/fully implemented #527
Comments
This is actually documented as incomplete here happy to accept PRs |
I actually will provide some code, that comes very close to the original JS function. But it still requires some work. |
I will not PR just yet, as the current implementation is not correct, and therefore shall not be merged. Here the code:
Current output:
(seems to be an error in the |
@stevenh Ok lol just found the error. It seems to match now ;)
Result:
@ALL feel free to look over it and improve it performance and structure wise ;) This was from a (react/tsx I guess) JS snippet, that I found on GitHub that implemented .toString(36) as part of its Twitter/X-ID to Token conversion part. The input of this function takes a Twitter/X-ID and gives you a token which lets you access some data of the post. |
Here a nicer implementation with
Please notice that this works fine for toString(36), but might not work as well for other lengths, as this was made by me for toString(36) explicitly. But with not much effort it very likely can be adjusted to the general |
Cool feel free to get a PR, easier to look at there |
Currently it is just a replacement for But as they all have different implementations I guess there needs to be a differenciator. Also: I overworked it again. No precision is neede anymore. |
I also encountered this error:
https://stackoverflow.com/a/52524228
I was about to implement this TS function:
in golang and wanted to use JS interpreter as validation. But it does not work as expected.
When I run it for the a twitter ID, it does just generate the first "part" of the result.
Everything after and including the dot, is missing (the dot gets removed anyway), but the token after the dot is missing as well.
Expected result:
4dh7jvecqt6
actual result:
4dh
Here what this function does:
floatNum := (num / 1e15) * math.Pi
base36
0
&.
)That is all. But this tool, does not do this properly, it converts the string to an int and converts the int to base36. Which is missing some operations.
The text was updated successfully, but these errors were encountered: