Skip to content

Instantly share code, notes, and snippets.

@jmiramant
Created March 2, 2022 18:32
Show Gist options
  • Save jmiramant/c17a73d75033f8e0ab2e1a9f5053e946 to your computer and use it in GitHub Desktop.
Save jmiramant/c17a73d75033f8e0ab2e1a9f5053e946 to your computer and use it in GitHub Desktop.
var UID_GEN = {
stringBuilder: function (projNum, sowNum, uid) {
  var id = (uid) ? uid.toUpperCase() : "";
  return id + "-" + projNum + "." + sowNum;
},
generateUID: function (projNum, sowNum, exisitngId) {
var pNum, sNum;
projNum ? pNum = projNum : pNum = "01";
sowNum ? sNum = sowNum : sNum = "01";
    if (exisitngId) return this.stringBuilder(pNum, sNum, exisitngId);
    var uid          = '';
    var characters       = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    var charactersLength = characters.length;
    for ( var i = 0; i < 6; i++ ) {
      uid += characters.charAt(Math.floor(Math.random() * charactersLength));
    }
    //Write persitence layer to S3 and call verification
    return this.stringBuilder(pNum, sNum, uid);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment