MCPcopy Index your code
hub / github.com/deepnote/deepnote / sanitizePythonVariableName

Function sanitizePythonVariableName

packages/blocks/src/blocks/python-utils.ts:15–33  ·  view source on GitHub ↗
(
  name: string,
  options: Partial<{ disableEmptyFallback: boolean }> = {}
)

Source from the content-addressed store, hash-verified

13}
14
15export function sanitizePythonVariableName(
16 name: string,
17 options: Partial<{ disableEmptyFallback: boolean }> = {}
18): string {
19 let sanitizedVariableName = name
20 // Convert whitespace to underscores
21 .replace(/\s+/g, '_')
22 // Remove invalid characters
23 .replace(/[^0-9a-zA-Z_]/g, '')
24 // Remove invalid leading characters
25 .replace(/^[^a-zA-Z_]+/g, '')
26
27 // Set a default value
28 if (sanitizedVariableName === '' && !options.disableEmptyFallback) {
29 sanitizedVariableName = 'input_1' // We don't want to call it just `input` to avoid name clashes
30 }
31
32 return sanitizedVariableName
33}

Calls

no outgoing calls

Tested by

no test coverage detected