@xylabs/timer 4.0.1 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,7 +18,11 @@ var update = (newTimeouts = timeouts, delayPassed = 0) => {
18
18
  return;
19
19
  } else {
20
20
  clearTimeout(currentTimeout);
21
- timeouts = newTimeouts.map((timeout) => ({ delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id }));
21
+ timeouts = newTimeouts.map((timeout) => ({
22
+ delay: timeout.delay - delayPassed,
23
+ func: timeout.func,
24
+ id: timeout.id
25
+ }));
22
26
  interval = newInterval;
23
27
  currentTimeout = setTimeout(timerFunc, interval);
24
28
  }
@@ -35,7 +39,11 @@ var timerFunc = () => {
35
39
  var setTimeoutEx = (func, delay) => {
36
40
  assertEx(delay >= 0, () => "delay must be >= 0");
37
41
  const id = `${Date.now()}|${Math.random() * 9999999999}`;
38
- timeouts.push({ delay, func, id });
42
+ timeouts.push({
43
+ delay,
44
+ func,
45
+ id
46
+ });
39
47
  update();
40
48
  return id;
41
49
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/setTimeoutEx.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\n\ninterface TimeoutInfo {\n delay: number\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n func: Function\n id: string\n}\n\nlet timeouts: TimeoutInfo[] = []\nlet currentTimeout: NodeJS.Timeout | undefined\nlet interval = -1\n\nconst reset = () => {\n interval = -1\n clearTimeout(currentTimeout)\n currentTimeout = undefined\n timeouts = []\n}\n\nconst update = (newTimeouts = timeouts, delayPassed = 0) => {\n // if no more timeouts, set back to initial state\n if (newTimeouts.length <= 0) {\n reset()\n } else {\n const newInterval = Math.min(...newTimeouts.map(timeout => timeout.delay))\n\n if (newInterval === interval && currentTimeout !== undefined) {\n // since nothing changed, just return\n return\n } else {\n clearTimeout(currentTimeout)\n timeouts = newTimeouts.map(timeout => ({ delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id }))\n // restart timeout since it needs to be different\n interval = newInterval\n currentTimeout = setTimeout(timerFunc, interval)\n }\n }\n}\n\nconst timerFunc = () => {\n const notFiring = timeouts.filter(timeout => timeout.delay > interval)\n const firing = timeouts.filter(timeout => timeout.delay <= interval)\n\n // call this after getting notFiring and firing since set will change in this call\n update(notFiring, interval)\n\n // trigger the ones that need to be triggered\n for (const timeout of firing) {\n timeout.func()\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const setTimeoutEx = (func: Function, delay: number) => {\n assertEx(delay >= 0, () => 'delay must be >= 0')\n const id = `${Date.now()}|${Math.random() * 9_999_999_999}`\n timeouts.push({ delay, func, id })\n update()\n return id\n}\n\nexport const clearTimeoutEx = (id: string) => {\n timeouts = timeouts.filter(timeout => timeout.id !== id)\n update(timeouts)\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AASzB,IAAI,WAA0B,CAAC;AAC/B,IAAI;AACJ,IAAI,WAAW;AAEf,IAAM,QAAQ,MAAM;AAClB,aAAW;AACX,eAAa,cAAc;AAC3B,mBAAiB;AACjB,aAAW,CAAC;AACd;AAEA,IAAM,SAAS,CAAC,cAAc,UAAU,cAAc,MAAM;AAE1D,MAAI,YAAY,UAAU,GAAG;AAC3B,UAAM;AAAA,EACR,OAAO;AACL,UAAM,cAAc,KAAK,IAAI,GAAG,YAAY,IAAI,aAAW,QAAQ,KAAK,CAAC;AAEzE,QAAI,gBAAgB,YAAY,mBAAmB,QAAW;AAE5D;AAAA,IACF,OAAO;AACL,mBAAa,cAAc;AAC3B,iBAAW,YAAY,IAAI,cAAY,EAAE,OAAO,QAAQ,QAAQ,aAAa,MAAM,QAAQ,MAAM,IAAI,QAAQ,GAAG,EAAE;AAElH,iBAAW;AACX,uBAAiB,WAAW,WAAW,QAAQ;AAAA,IACjD;AAAA,EACF;AACF;AAEA,IAAM,YAAY,MAAM;AACtB,QAAM,YAAY,SAAS,OAAO,aAAW,QAAQ,QAAQ,QAAQ;AACrE,QAAM,SAAS,SAAS,OAAO,aAAW,QAAQ,SAAS,QAAQ;AAGnE,SAAO,WAAW,QAAQ;AAG1B,aAAW,WAAW,QAAQ;AAC5B,YAAQ,KAAK;AAAA,EACf;AACF;AAGO,IAAM,eAAe,CAAC,MAAgB,UAAkB;AAC7D,WAAS,SAAS,GAAG,MAAM,oBAAoB;AAC/C,QAAM,KAAK,GAAG,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,UAAa;AACzD,WAAS,KAAK,EAAE,OAAO,MAAM,GAAG,CAAC;AACjC,SAAO;AACP,SAAO;AACT;AAEO,IAAM,iBAAiB,CAAC,OAAe;AAC5C,aAAW,SAAS,OAAO,aAAW,QAAQ,OAAO,EAAE;AACvD,SAAO,QAAQ;AACjB;","names":[]}
1
+ {"version":3,"sources":["../../src/setTimeoutEx.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\n\ninterface TimeoutInfo {\n delay: number\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n func: Function\n id: string\n}\n\nlet timeouts: TimeoutInfo[] = []\nlet currentTimeout: NodeJS.Timeout | undefined\nlet interval = -1\n\nconst reset = () => {\n interval = -1\n clearTimeout(currentTimeout)\n currentTimeout = undefined\n timeouts = []\n}\n\nconst update = (newTimeouts = timeouts, delayPassed = 0) => {\n // if no more timeouts, set back to initial state\n if (newTimeouts.length <= 0) {\n reset()\n } else {\n const newInterval = Math.min(...newTimeouts.map(timeout => timeout.delay))\n\n if (newInterval === interval && currentTimeout !== undefined) {\n // since nothing changed, just return\n return\n } else {\n clearTimeout(currentTimeout)\n timeouts = newTimeouts.map(timeout => ({\n delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id,\n }))\n // restart timeout since it needs to be different\n interval = newInterval\n currentTimeout = setTimeout(timerFunc, interval)\n }\n }\n}\n\nconst timerFunc = () => {\n const notFiring = timeouts.filter(timeout => timeout.delay > interval)\n const firing = timeouts.filter(timeout => timeout.delay <= interval)\n\n // call this after getting notFiring and firing since set will change in this call\n update(notFiring, interval)\n\n // trigger the ones that need to be triggered\n for (const timeout of firing) {\n timeout.func()\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const setTimeoutEx = (func: Function, delay: number) => {\n assertEx(delay >= 0, () => 'delay must be >= 0')\n const id = `${Date.now()}|${Math.random() * 9_999_999_999}`\n timeouts.push({\n delay, func, id,\n })\n update()\n return id\n}\n\nexport const clearTimeoutEx = (id: string) => {\n timeouts = timeouts.filter(timeout => timeout.id !== id)\n update(timeouts)\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AASzB,IAAI,WAA0B,CAAC;AAC/B,IAAI;AACJ,IAAI,WAAW;AAEf,IAAM,QAAQ,MAAM;AAClB,aAAW;AACX,eAAa,cAAc;AAC3B,mBAAiB;AACjB,aAAW,CAAC;AACd;AAEA,IAAM,SAAS,CAAC,cAAc,UAAU,cAAc,MAAM;AAE1D,MAAI,YAAY,UAAU,GAAG;AAC3B,UAAM;AAAA,EACR,OAAO;AACL,UAAM,cAAc,KAAK,IAAI,GAAG,YAAY,IAAI,aAAW,QAAQ,KAAK,CAAC;AAEzE,QAAI,gBAAgB,YAAY,mBAAmB,QAAW;AAE5D;AAAA,IACF,OAAO;AACL,mBAAa,cAAc;AAC3B,iBAAW,YAAY,IAAI,cAAY;AAAA,QACrC,OAAO,QAAQ,QAAQ;AAAA,QAAa,MAAM,QAAQ;AAAA,QAAM,IAAI,QAAQ;AAAA,MACtE,EAAE;AAEF,iBAAW;AACX,uBAAiB,WAAW,WAAW,QAAQ;AAAA,IACjD;AAAA,EACF;AACF;AAEA,IAAM,YAAY,MAAM;AACtB,QAAM,YAAY,SAAS,OAAO,aAAW,QAAQ,QAAQ,QAAQ;AACrE,QAAM,SAAS,SAAS,OAAO,aAAW,QAAQ,SAAS,QAAQ;AAGnE,SAAO,WAAW,QAAQ;AAG1B,aAAW,WAAW,QAAQ;AAC5B,YAAQ,KAAK;AAAA,EACf;AACF;AAGO,IAAM,eAAe,CAAC,MAAgB,UAAkB;AAC7D,WAAS,SAAS,GAAG,MAAM,oBAAoB;AAC/C,QAAM,KAAK,GAAG,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,UAAa;AACzD,WAAS,KAAK;AAAA,IACZ;AAAA,IAAO;AAAA,IAAM;AAAA,EACf,CAAC;AACD,SAAO;AACP,SAAO;AACT;AAEO,IAAM,iBAAiB,CAAC,OAAe;AAC5C,aAAW,SAAS,OAAO,aAAW,QAAQ,OAAO,EAAE;AACvD,SAAO,QAAQ;AACjB;","names":[]}
package/package.json CHANGED
@@ -1,16 +1,32 @@
1
1
  {
2
- "license": "LGPL-3.0-only",
3
2
  "name": "@xylabs/timer",
3
+ "version": "4.0.3",
4
+ "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
+ "keywords": [
6
+ "xylabs",
7
+ "timer",
8
+ "setTimeout",
9
+ "utility",
10
+ "typescript",
11
+ "esm"
12
+ ],
13
+ "homepage": "https://xylabs.com",
14
+ "bugs": {
15
+ "url": "git+https://github.com/xylabs/sdk-js/issues",
16
+ "email": "support@xylabs.com"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/xylabs/sdk-js.git"
21
+ },
22
+ "license": "LGPL-3.0-only",
4
23
  "author": {
5
- "email": "support@xylabs.com",
6
24
  "name": "XY Labs Development Team",
7
- "url": "https://xylabs.com"
8
- },
9
- "bugs": {
10
25
  "email": "support@xylabs.com",
11
- "url": "https://github.com/xylabs/sdk-js/issues"
26
+ "url": "https://xylabs.com"
12
27
  },
13
- "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
28
+ "sideEffects": false,
29
+ "type": "module",
14
30
  "exports": {
15
31
  ".": {
16
32
  "types": "./dist/neutral/index.d.ts",
@@ -18,37 +34,21 @@
18
34
  },
19
35
  "./package.json": "./package.json"
20
36
  },
21
- "types": "./dist/neutral/index.d.ts",
22
37
  "module": "./dist/neutral/index.mjs",
38
+ "types": "./dist/neutral/index.d.ts",
23
39
  "dependencies": {
24
- "@xylabs/assert": "^4.0.1"
40
+ "@xylabs/assert": "^4.0.3"
25
41
  },
26
42
  "devDependencies": {
27
- "@types/node": "^22.3.0",
28
- "@xylabs/ts-scripts-yarn3": "^4.0.0-rc.15",
29
- "@xylabs/tsconfig": "^4.0.0-rc.15",
43
+ "@types/node": "^22.5.0",
44
+ "@xylabs/ts-scripts-yarn3": "^4.0.0",
45
+ "@xylabs/tsconfig": "^4.0.0",
30
46
  "typescript": "^5.5.4"
31
47
  },
32
48
  "engines": {
33
49
  "node": ">=18"
34
50
  },
35
- "homepage": "https://xylabs.com",
36
- "keywords": [
37
- "xylabs",
38
- "timer",
39
- "setTimeout",
40
- "utility",
41
- "typescript",
42
- "esm"
43
- ],
44
51
  "publishConfig": {
45
52
  "access": "public"
46
- },
47
- "repository": {
48
- "type": "git",
49
- "url": "https://github.com/xylabs/sdk-js.git"
50
- },
51
- "sideEffects": false,
52
- "version": "4.0.1",
53
- "type": "module"
53
+ }
54
54
  }
@@ -30,7 +30,9 @@ const update = (newTimeouts = timeouts, delayPassed = 0) => {
30
30
  return
31
31
  } else {
32
32
  clearTimeout(currentTimeout)
33
- timeouts = newTimeouts.map(timeout => ({ delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id }))
33
+ timeouts = newTimeouts.map(timeout => ({
34
+ delay: timeout.delay - delayPassed, func: timeout.func, id: timeout.id,
35
+ }))
34
36
  // restart timeout since it needs to be different
35
37
  interval = newInterval
36
38
  currentTimeout = setTimeout(timerFunc, interval)
@@ -55,7 +57,9 @@ const timerFunc = () => {
55
57
  export const setTimeoutEx = (func: Function, delay: number) => {
56
58
  assertEx(delay >= 0, () => 'delay must be >= 0')
57
59
  const id = `${Date.now()}|${Math.random() * 9_999_999_999}`
58
- timeouts.push({ delay, func, id })
60
+ timeouts.push({
61
+ delay, func, id,
62
+ })
59
63
  update()
60
64
  return id
61
65
  }
package/xy.config.ts CHANGED
@@ -1,10 +1,8 @@
1
- import { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
1
+ import type { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
2
2
  const config: XyTsupConfig = {
3
3
  compile: {
4
4
  browser: {},
5
- neutral: {
6
- src: true,
7
- },
5
+ neutral: { src: true },
8
6
  node: {},
9
7
  },
10
8
  }