Skip to content
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

RT.Comb.Provider.Postgre.Create().ToString("N") JavaScript version. #17

Open
inercya-github opened this issue May 27, 2020 · 1 comment

Comments

@inercya-github
Copy link

I use RT.Comb on the back-end, however I also need it on the browser, so I wrote the following JavaScript function:

function newSequentialGuid() {
  var ms = new Date().getTime().toString(16).padStart(12, "0");
  var a = new Uint8Array(10);
  crypto.getRandomValues(a);
  a[0] = a[0] & 15 | 64;
  a[2] = a[2] & 63 | 128;
  return ms + Array.prototype.map.call(a, x => x.toString(16).padStart(2, "0")).join("");
}

Please, could you confirm it is equivalent to RT.Comb.Provider.Postgre.Create().ToString("N") ?

@richardtallent
Copy link
Owner

I don't use PostgreSql, so I'll have to look into this when I can get some time to run a proper test. If someone else can confirm, that would be great!

I've considered releasing a JavaScript version of this library on npm... I wrote an equivalent function for doing Unix timestamps on MSSQL GUIDs awhile back, so perhaps combining this and that and a few other things, a robust solution can be created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants