File size: 707 Bytes
72b5f86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Names typed by users (functions, variables, params) may contain spaces and
// special characters. When a name is emitted into generated code it is
// URL-encoded, then each `%` is escaped as `\u0025` so the percent sign is
// representable in the output text. E.g. "my variable" -> "my\u002520variable".
export function encodeName(name: string): string {
  return encodeURIComponent(String(name ?? '')).replace(/%/g, '\\u0025');
}

// Encode a comma-separated list of names (used for legacy param fields).
export function encodeNameList(list: string): string {
  return String(list ?? '')
    .split(',')
    .map((p) => p.trim())
    .filter((p) => p.length > 0)
    .map(encodeName)
    .join(', ');
}