Chore: Remove Chance.js dependency from runtime code (#113457)

This commit is contained in:
Leon Sorokin
2025-11-06 05:08:31 -06:00
committed by GitHub
parent 6bf5e3303e
commit efd6b250d9
2 changed files with 4 additions and 6 deletions
@@ -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', () => {
@@ -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}`;
}