@jrc03c/pause 0.0.5 → 0.0.7

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.
package/build.mjs CHANGED
@@ -10,6 +10,7 @@ function rebuild() {
10
10
  const commands = [
11
11
  `${baseCommand} --platform=node --outfile=dist/pause.require.cjs`,
12
12
  `${baseCommand} --outfile=dist/pause.standalone.cjs`,
13
+ `${baseCommand} --format=esm --outfile=dist/pause.import.mjs`,
13
14
  ]
14
15
 
15
16
  commands.forEach(command => {
@@ -0,0 +1,29 @@
1
+ // src/index.mjs
2
+ function pauseAsync(ms) {
3
+ return new Promise((resolve, reject) => {
4
+ try {
5
+ const start = /* @__PURE__ */ new Date();
6
+ return setTimeout(() => resolve(/* @__PURE__ */ new Date() - start), ms);
7
+ } catch (e) {
8
+ return reject(e);
9
+ }
10
+ });
11
+ }
12
+ function pauseSync(ms) {
13
+ const start = /* @__PURE__ */ new Date();
14
+ let now = /* @__PURE__ */ new Date();
15
+ while (now - start < ms) {
16
+ now = /* @__PURE__ */ new Date();
17
+ }
18
+ return /* @__PURE__ */ new Date() - start;
19
+ }
20
+ if (typeof window !== "undefined") {
21
+ window.pause = pauseAsync;
22
+ window.pauseAsync = pauseAsync;
23
+ window.pauseSync = pauseSync;
24
+ }
25
+ export {
26
+ pauseAsync as pause,
27
+ pauseAsync,
28
+ pauseSync
29
+ };
package/moon.yml CHANGED
@@ -22,3 +22,8 @@ tasks:
22
22
  - --force
23
23
  local: true
24
24
  platform: node
25
+ test:
26
+ command:
27
+ - node
28
+ - src/index.test.mjs
29
+ platform: node
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "prettier": "^3.3.3"
10
10
  },
11
11
  "exports": {
12
- "import": "./src/index.mjs",
12
+ "import": "./dist/pause.import.mjs",
13
13
  "require": "./dist/pause.require.cjs"
14
14
  },
15
15
  "keywords": [
@@ -18,8 +18,9 @@
18
18
  "settimeout"
19
19
  ],
20
20
  "license": "ISC",
21
- "main": "src/index.mjs",
21
+ "main": "./dist/pause.require.cjs",
22
+ "module": "./dist/pause.import.mjs",
22
23
  "name": "@jrc03c/pause",
23
24
  "type": "module",
24
- "version": "0.0.5"
25
+ "version": "0.0.7"
25
26
  }
@@ -19,9 +19,11 @@ let syncTestsAreRunning = true
19
19
  )
20
20
  }
21
21
 
22
- if (elapsed < t) {
22
+ // there should be less than 10ms difference between the given time and the
23
+ // actual elapsed time
24
+ if (Math.abs(elapsed - t) > 10) {
23
25
  throw new Error(
24
- `The function was supposed to wait for ${t}ms, but instead it only waited for ${elapsed}ms!`,
26
+ `The function was supposed to wait for ${t}ms, but instead it waited for ${elapsed}ms!`,
25
27
  )
26
28
  }
27
29
  }