@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 +1 -0
- package/dist/pause.import.mjs +29 -0
- package/moon.yml +5 -0
- package/package.json +4 -3
- package/src/index.test.mjs +4 -2
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
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"prettier": "^3.3.3"
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
|
12
|
-
"import": "./
|
|
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": "
|
|
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.
|
|
25
|
+
"version": "0.0.7"
|
|
25
26
|
}
|
package/src/index.test.mjs
CHANGED
|
@@ -19,9 +19,11 @@ let syncTestsAreRunning = true
|
|
|
19
19
|
)
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
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
|
|
26
|
+
`The function was supposed to wait for ${t}ms, but instead it waited for ${elapsed}ms!`,
|
|
25
27
|
)
|
|
26
28
|
}
|
|
27
29
|
}
|