Created
July 1, 2023 11:40
-
-
Save samipshah100/b4cc85082e77c413ffc76165fbffcf0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const crypto = require('crypto'); | |
// this generates a random 20 char string using upto the first 10 chars from the inputString. | |
// this is used to create a workspace id from workspace name so that the workspace namespace can be easily searchable amongst the pinecone vector database namespaces | |
function createRandomWorkspaceIdFromName(inputString) { | |
const alphanumericInput = inputString | |
.replace(/[^a-zA-Z0-9]/g, '') | |
.slice(0, 10); | |
const remainingLength = 20 - alphanumericInput.length; | |
const randomBytes = crypto.randomBytes(remainingLength * 2); | |
const randomAlphanumeric = randomBytes | |
.toString('hex') | |
.slice(0, remainingLength); | |
const id = alphanumericInput + randomAlphanumeric; | |
return id; | |
} | |
export default createRandomWorkspaceIdFromName; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
re