@straylightagency/utils 1.1.1 → 1.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@straylightagency/utils",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Some JavaScript utilities functions",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -12,7 +12,7 @@
12
12
  * @param {{}} listeners
13
13
  */
14
14
  export default function addEventListeners(element, listeners) {
15
- Object.fromEntries(
15
+ return Object.fromEntries(
16
16
  Object.entries( listeners ).map( ([event, callbackFn]) => {
17
17
  element.addEventListener( event, callbackFn );
18
18
 
package/src/index.js CHANGED
@@ -15,6 +15,9 @@ export { default as has } from "./object/has.js";
15
15
  export { default as clipboard } from "./misc/clipboard.js";
16
16
  export { default as debounce } from "./misc/debounce.js";
17
17
  export { default as nextTick } from "./misc/nextTick.js";
18
+ export { default as seconds } from "./misc/seconds.js";
19
+ export { default as milliseconds } from "./misc/milliseconds.js";
20
+ export { default as restoreBooleanAfter } from "./misc/restoreBooleanAfter.js";
18
21
  export { default as throttle } from "./misc/throttle.js";
19
22
  export { default as functionReviver } from "./misc/reviver.js";
20
23
  export { default as functionReplacer } from "./misc/replacer.js";
@@ -34,14 +37,10 @@ export { default as initial } from "./array/initial.js";
34
37
  export { default as last } from "./array/last.js";
35
38
  export { default as remove } from "./array/remove.js";
36
39
 
37
- import {wait, seconds, milliseconds} from "./misc/wait.js";
38
40
  import {isClass, isObject, isPlainObject} from "./misc/is.js";
39
41
  import {decodeBase64, encodeBase64, isBase64} from "./misc/base64.js";
40
42
 
41
43
  export {
42
- wait,
43
- seconds,
44
- milliseconds,
45
44
  isClass,
46
45
  isObject,
47
46
  isPlainObject,
package/src/misc/index.js CHANGED
@@ -6,15 +6,14 @@ export { default as attempt } from "./attempt.js";
6
6
  export { default as retry } from "./retry.js";
7
7
  export { default as reviver } from "./reviver.js";
8
8
  export { default as replacer } from "./replacer.js";
9
+ export { default as seconds } from "./seconds.js";
10
+ export { default as milliseconds } from "./milliseconds.js";
11
+ export { default as restoreBooleanAfter } from "./restoreBooleanAfter.js";
9
12
 
10
- import {wait, seconds, milliseconds} from "./wait.js";
11
13
  import {isClass, isObject, isPlainObject} from "./is.js";
12
14
  import {decodeBase64, encodeBase64, isBase64} from "./base64.js";
13
15
 
14
16
  export {
15
- wait,
16
- seconds,
17
- milliseconds,
18
17
  isClass,
19
18
  isObject,
20
19
  isPlainObject,
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Stop the main process for a moment defined in milliseconds.
3
+ *
4
+ * @param {number} timeMs
5
+ * @returns {Promise<*>}
6
+ */
7
+ export default function milliseconds(timeMs) {
8
+ return new Promise( resolve => setTimeout( resolve, timeMs ) );
9
+ }
@@ -6,7 +6,8 @@
6
6
  */
7
7
  export default async function nextTick(callbackFn) {
8
8
  return new Promise(
9
- async resolve => requestIdleCallback( () => async () => resolve( await callbackFn() )
9
+ async resolve => requestIdleCallback( () =>
10
+ setTimeout( async () => resolve( await callbackFn() ), 0 )
10
11
  )
11
12
  );
12
13
  }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Change a boolean value then restore that value after a timeout on miliseconds.
3
+ *
4
+ * Works fine with VueJS and signal based frameworks :
5
+ * restoreBooleanAfter( bool => messageSent.value = bool, true, 15_000 );
6
+ *
7
+ * messageSent will be set to "true" than restored to "false" after 15 sec.
8
+ *
9
+ * @param {Function} callbackFn
10
+ * @param {boolean} boolean
11
+ * @param {number} timeoutMs
12
+ */
13
+ export default function restoreBooleanAfter(callbackFn, boolean, timeoutMs) {
14
+ const value = callbackFn( boolean );
15
+
16
+ setTimeout( () => callbackFn( ! value ), timeoutMs );
17
+ }
@@ -0,0 +1,11 @@
1
+ import milliseconds from "./milliseconds.js";
2
+
3
+ /**
4
+ * Stop the main process for a moment defined in seconds.
5
+ *
6
+ * @param {number} time
7
+ * @returns {Promise<*>}
8
+ */
9
+ export default function seconds(time) {
10
+ return milliseconds( time * 1000 );
11
+ }
package/src/object/has.js CHANGED
@@ -1,4 +1,4 @@
1
- import get from "./get";
1
+ import get from "./get.js";
2
2
 
3
3
  /**
4
4
  * Get a value using a dot-notated key string
package/src/misc/wait.js DELETED
@@ -1,31 +0,0 @@
1
- /**
2
- * Stop the main process for a moment defined in milliseconds.
3
- *
4
- * @param {number} timeMs
5
- * @returns {Promise<unknown>}
6
- */
7
- export function wait(timeMs) {
8
- return new Promise( resolve => setTimeout( resolve, timeMs ) );
9
- }
10
-
11
- /**
12
- * Stop the main process for a moment defined in seconds.
13
- *
14
- * @param {number} time
15
- * @returns {Promise<*>}
16
- */
17
- export function seconds(time) {
18
- return wait( time * 1000 );
19
- }
20
-
21
- /**
22
- * Alias to `wait`. Stop the main process for a moment defined in milliseconds.
23
- *
24
- * @param {number} timeMs
25
- * @returns {Promise<*>}
26
- */
27
- export function milliseconds(timeMs) {
28
- return wait( timeMs );
29
- }
30
-
31
- export default wait;