From efd6b250d9d21dd6c90f5bf36bd82dad42dad769 Mon Sep 17 00:00:00 2001 From: Leon Sorokin Date: Thu, 6 Nov 2025 05:08:31 -0600 Subject: [PATCH] Chore: Remove Chance.js dependency from runtime code (#113457) --- .../provisioning/components/utils/timestamp.test.ts | 4 ++-- .../app/features/provisioning/components/utils/timestamp.ts | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/public/app/features/provisioning/components/utils/timestamp.test.ts b/public/app/features/provisioning/components/utils/timestamp.test.ts index ab7543453dd..805874f631f 100644 --- a/public/app/features/provisioning/components/utils/timestamp.test.ts +++ b/public/app/features/provisioning/components/utils/timestamp.test.ts @@ -8,8 +8,8 @@ describe('generateTimestamp', () => { expect(typeof timestamp).toBe('string'); // Check that the timestamp follows the format YYYY-MM-DD-xxxxx - // where xxxxx is a random string of 5 alphabetic characters - expect(timestamp).toMatch(/^\d{4}-\d{2}-\d{2}-[a-zA-Z]{5}$/); + // where xxxxx is a random string of 5 alpha-num characters + expect(timestamp).toMatch(/^\d{4}-\d{2}-\d{2}-[a-z\d]{5}$/i); }); it('should generate unique timestamps', () => { diff --git a/public/app/features/provisioning/components/utils/timestamp.ts b/public/app/features/provisioning/components/utils/timestamp.ts index a1020951d41..8906cf3e3a7 100644 --- a/public/app/features/provisioning/components/utils/timestamp.ts +++ b/public/app/features/provisioning/components/utils/timestamp.ts @@ -1,11 +1,9 @@ -import { Chance } from 'chance'; - import { dateTime } from '@grafana/data'; /** * Generates a timestamp string in the format YYYY-MM-DD-xxxxx where xxxxx is a random string */ export function generateTimestamp(): string { - const random = new Chance(); - return `${dateTime().format('YYYY-MM-DD')}-${random.string({ length: 5, alpha: true })}`; + const randStr = Math.random().toString(36).substring(2, 7); + return `${dateTime().format('YYYY-MM-DD')}-${randStr}`; }