在 JavaScript 中将字符串转换为更短且唯一的内容
所以我目前正在寻找这个 ruby 实现:
Base64.urlsafe_encode64([Digest::MD5.hexdigest('example.com').to_i(16)].pack("N")).sub(/==\n?$/, '')
example.com 字符串被转换为“SY5Rcg”,这实际上是我想要完成的事情。有什么建议吗?我知道由于缺少 pack 方法,无法在 js 中创建 ruby 实现,但这没关系。我只是在寻找类似的东西。
So I'm currently looking in this ruby implementation:
Base64.urlsafe_encode64([Digest::MD5.hexdigest('example.com').to_i(16)].pack("N")).sub(/==\n?$/, '')
The example.com string is converted to "SY5Rcg", which is actually the thing that i'm trying to accomplish. Any suggestions? I know that the ruby implementation can not be created in js since the lack of pack method, but that's ok. I'm just looking for something similar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这本质上是不可能的。
较短长度的字符串较少;你不能保证唯一性。
That's inherently impossible.
There are fewer shorter-length strings; you cannot guarantee uniquness.