From 2d04c7545157ab7eb185cbe26649887d8395448b Mon Sep 17 00:00:00 2001 From: Lajos Meszaros Date: Thu, 21 Sep 2023 14:39:02 +0200 Subject: [PATCH] feat(scripting/hooks): create useDelay() hook --- package.json | 4 ++++ src/scripting/hooks/index.ts | 1 + src/scripting/hooks/useDelay.ts | 11 +++++++++++ 3 files changed, 16 insertions(+) create mode 100644 src/scripting/hooks/index.ts create mode 100644 src/scripting/hooks/useDelay.ts diff --git a/package.json b/package.json index e9293674..889fb21b 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,10 @@ "default": "./dist/src/scripting/commands/index.js", "types": "./dist/src/scripting/commands/index.d.ts" }, + "./scripting/hooks": { + "default": "./dist/src/scripting/hooks/index.js", + "types": "./dist/src/scripting/hooks/index.d.ts" + }, "./scripting/interfaces": { "default": "./dist/src/scripting/interfaces/index.js", "types": "./dist/src/scripting/interfaces/index.d.ts" diff --git a/src/scripting/hooks/index.ts b/src/scripting/hooks/index.ts new file mode 100644 index 00000000..c266bed0 --- /dev/null +++ b/src/scripting/hooks/index.ts @@ -0,0 +1 @@ +export { useDelay } from '@scripting/hooks/useDelay.js' diff --git a/src/scripting/hooks/useDelay.ts b/src/scripting/hooks/useDelay.ts new file mode 100644 index 00000000..234c4163 --- /dev/null +++ b/src/scripting/hooks/useDelay.ts @@ -0,0 +1,11 @@ +let delayIdx = 0 + +export const useDelay = () => { + let delayOffset = 0 + + return (delayInMs: number = 0) => { + delayOffset += Math.floor(delayInMs) + + return `TIMERdelay${++delayIdx} -m 1 ${delayOffset}` + } +}