Chore: Remove Chance.js dependency from runtime code (#113457)
This commit is contained in:
@@ -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}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user