scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
59 lines (50 loc) • 1.08 kB
text/typescript
import {AbsUUID} from 'scriptable-abstract';
interface UUIDState {
lastGeneratedUUID: string | null;
}
/**
* Mock implementation of Scriptable's UUID global variable
* Provides functionality for generating UUIDs
*
* @implements UUID
*/
export class MockUUID extends AbsUUID<UUIDState> {
static get instance(): MockUUID {
return super.instance as MockUUID;
}
constructor() {
super({
lastGeneratedUUID: null,
});
}
/**
* @inheritdoc
*/
string(): string {
const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
const r = (Math.random() * 16) | 0;
const v = c === 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
this.setState({
lastGeneratedUUID: uuid,
});
return uuid;
}
/**
* @additional
* Get the last generated UUID
*/
getLastGeneratedUUID(): string | null {
return this.state.lastGeneratedUUID;
}
/**
* @additional
* Clear UUID history
*/
clear(): void {
this.setState({
lastGeneratedUUID: null,
});
}
}