MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / getTelemetrySafeVersion

Function getTelemetrySafeVersion

src/platform/telemetry/helpers.ts:8–32  ·  view source on GitHub ↗
(version: string | Environment['version'])

Source from the content-addressed store, hash-verified

6import { logger } from '../logging';
7
8export function getTelemetrySafeVersion(version: string | Environment['version']): string {
9 if (typeof version === 'string') {
10 try {
11 // Split by `.` & take only the first 3 numbers.
12 // Suffix with '.', so we know we'll always have 3 items in the array.
13 const [major, minor, patch] = `${version.trim()}...`.split('.').map((item) => parseInt(item, 10));
14 if (isNaN(major)) {
15 return '';
16 } else if (isNaN(minor)) {
17 return major.toString();
18 } else if (isNaN(patch)) {
19 return `${major}.${minor}`;
20 }
21 return `${major}.${minor}.${patch}`;
22 } catch (ex) {
23 logger.error(`Failed to parse version ${version}`, ex);
24 return '';
25 }
26 }
27 if (!version) {
28 return '';
29 }
30
31 return `${version.major}.${version.minor}.${version.micro}`;
32}
33
34/**
35 * Safe way to send data in telemetry (obfuscate PII).

Calls 3

mapMethod · 0.80
toStringMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected