@dr.pogodin/js-utils 0.0.12 → 0.0.14

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/LICENSE.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # MIT License
2
2
 
3
- _Copyright © 2023, Dr. Sergey Pogodin_
4
- &mdash; <doc@pogodin.studio> (https://dr.pogodin.studio) \
3
+ _Copyright &copy; 2023&ndash;2025, Dr. Sergey Pogodin_
4
+ &mdash; <doc@pogodin.studio> (https://dr.pogodin.studio)
5
5
 
6
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  of this software and associated documentation files (the "Software"), to deal
package/babel.config.js CHANGED
@@ -1,3 +1,5 @@
1
+ // Babel is used for Jest testing.
2
+
1
3
  module.exports = {
2
4
  presets: [
3
5
  ['@babel/preset-env', { targets: { node: 'current' } }],
package/build/Barrier.js CHANGED
@@ -1,5 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
1
  var STATE;
4
2
  (function (STATE) {
5
3
  STATE["PENDING"] = "PENDING";
@@ -29,7 +27,7 @@ var STATE;
29
27
  *
30
28
  * Docs: https://dr.pogodin.studio/docs/react-utils/docs/api/classes/Barrier
31
29
  */
32
- class Barrier extends Promise {
30
+ export default class Barrier extends Promise {
33
31
  constructor(executor) {
34
32
  let resolveRef;
35
33
  let rejectRef;
@@ -88,4 +86,3 @@ class Barrier extends Promise {
88
86
  return res;
89
87
  }
90
88
  }
91
- exports.default = Barrier;
package/build/Emitter.js CHANGED
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Emitter = void 0;
4
1
  /**
5
2
  * Simple listeneable data Emitter.
6
3
  */
7
- class Emitter {
4
+ export class Emitter {
8
5
  constructor() {
9
6
  this.p_listeners = [];
10
7
  }
@@ -53,4 +50,3 @@ class Emitter {
53
50
  this.p_listeners.splice(idx, 1);
54
51
  }
55
52
  }
56
- exports.Emitter = Emitter;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,15 +7,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const Barrier_1 = __importDefault(require("./Barrier"));
10
+ import Barrier from './Barrier';
16
11
  /**
17
12
  * Implements a simple semaphore for async code logic.
18
13
  */
19
- class Semaphore {
14
+ export default class Semaphore {
20
15
  constructor(ready = false) {
21
16
  // "true" when the drain queue process is running (and thus no need to start
22
17
  // a new one).
@@ -55,7 +50,7 @@ class Semaphore {
55
50
  waitReady() {
56
51
  return __awaiter(this, arguments, void 0, function* (seize = false) {
57
52
  if (!this.p_ready || this.p_queue.length) {
58
- const barrier = new Barrier_1.default();
53
+ const barrier = new Barrier();
59
54
  this.p_queue.push(barrier);
60
55
  yield barrier;
61
56
  if (seize)
@@ -77,7 +72,7 @@ class Semaphore {
77
72
  return __awaiter(this, void 0, void 0, function* () {
78
73
  this.p_draining = true;
79
74
  while (this.p_ready && this.p_queue.length) {
80
- this.p_drainLock = new Barrier_1.default();
75
+ this.p_drainLock = new Barrier();
81
76
  this.p_queue[0].resolve();
82
77
  yield this.p_drainLock; // eslint-disable-line no-await-in-loop
83
78
  this.p_queue.shift();
@@ -87,4 +82,3 @@ class Semaphore {
87
82
  });
88
83
  }
89
84
  }
90
- exports.default = Semaphore;
package/build/index.js CHANGED
@@ -1,28 +1,5 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.withRetries = exports.Semaphore = exports.Barrier = void 0;
21
- var Barrier_1 = require("./Barrier");
22
- Object.defineProperty(exports, "Barrier", { enumerable: true, get: function () { return __importDefault(Barrier_1).default; } });
23
- __exportStar(require("./Emitter"), exports);
24
- var Semaphore_1 = require("./Semaphore");
25
- Object.defineProperty(exports, "Semaphore", { enumerable: true, get: function () { return __importDefault(Semaphore_1).default; } });
26
- __exportStar(require("./time"), exports);
27
- var withRetries_1 = require("./withRetries");
28
- Object.defineProperty(exports, "withRetries", { enumerable: true, get: function () { return __importDefault(withRetries_1).default; } });
1
+ export { default as Barrier } from './Barrier';
2
+ export * from './Emitter';
3
+ export { default as Semaphore } from './Semaphore';
4
+ export * from './time';
5
+ export { default as withRetries } from './withRetries';
package/build/time.js CHANGED
@@ -1,23 +1,17 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.timer = exports.Timer = exports.YEAR_MS = exports.DAY_MS = exports.HOUR_MS = exports.MIN_MS = exports.SEC_MS = void 0;
7
- const Barrier_1 = __importDefault(require("./Barrier"));
1
+ import Barrier from './Barrier';
8
2
  // This is not very elegant, but as of now TypeScript does not support type
9
3
  // arithmetic, thus we can't have constants assigned like `MIN_MS = 60 * SEC_MS`
10
4
  // and have the result type to be 60000 (number literal), it would be just
11
5
  // the generic number type.
12
- exports.SEC_MS = 1000;
13
- exports.MIN_MS = 60000; // 60 * SEC_MS
14
- exports.HOUR_MS = 3600000; // 60 * MIN_MS
15
- exports.DAY_MS = 86400000; // 24 * HOUR_MS
16
- exports.YEAR_MS = 31536000000; // 365 * DAY_MS
6
+ export const SEC_MS = 1000;
7
+ export const MIN_MS = 60000; // 60 * SEC_MS
8
+ export const HOUR_MS = 3600000; // 60 * MIN_MS
9
+ export const DAY_MS = 86400000; // 24 * HOUR_MS
10
+ export const YEAR_MS = 31536000000; // 365 * DAY_MS
17
11
  // TODO: Ok, as we have ended up with a Timer class, mostly to achieve a good
18
12
  // TypeScript typing for timer() function, it makes sense to expose the class
19
13
  // from the library as well, and it should be documented later.
20
- class Timer extends Barrier_1.default {
14
+ export class Timer extends Barrier {
21
15
  get abort() { return this.p_abort; }
22
16
  get timeout() { return this.p_timeout; }
23
17
  /**
@@ -58,7 +52,6 @@ class Timer extends Barrier_1.default {
58
52
  return res;
59
53
  }
60
54
  }
61
- exports.Timer = Timer;
62
55
  /**
63
56
  * Creates a Promise, which resolves after the given timeout.
64
57
  * @param {number} timeout Timeout [ms].
@@ -66,8 +59,7 @@ exports.Timer = Timer;
66
59
  * .abort() method attached, which cancels the pending timer resolution
67
60
  * (without resolving or rejecting the barrier).
68
61
  */
69
- function timer(timeout) {
62
+ export function timer(timeout) {
70
63
  const t = new Timer();
71
64
  return t.init(timeout);
72
65
  }
73
- exports.timer = timer;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,8 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const time_1 = require("./time");
10
+ import { timer } from './time';
13
11
  /**
14
12
  * Attempts to perform the given async `action` up to `maxRetries` times with
15
13
  * the specified `interval`, stopping at the first successful (non-throwing)
@@ -21,7 +19,7 @@ const time_1 = require("./time");
21
19
  * @returns Resolves to the result of the successful `action` execution;
22
20
  * or rejects with the error from the last faileda attempt.
23
21
  */
24
- function withRetries(action_1) {
22
+ export default function withRetries(action_1) {
25
23
  return __awaiter(this, arguments, void 0, function* (action, maxRetries = 3, interval = 300) {
26
24
  /* eslint-disable no-await-in-loop */
27
25
  for (let n = 1;; ++n) {
@@ -31,7 +29,7 @@ function withRetries(action_1) {
31
29
  }
32
30
  catch (error) {
33
31
  if (n < maxRetries)
34
- yield (0, time_1.timer)(interval);
32
+ yield timer(interval);
35
33
  else
36
34
  throw error;
37
35
  }
@@ -39,4 +37,3 @@ function withRetries(action_1) {
39
37
  /* eslint-enable no-await-in-loop */
40
38
  });
41
39
  }
42
- exports.default = withRetries;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dr.pogodin/js-utils",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "Collection of JavaScript (TypeScript) utilities.",
5
5
  "main": "build/index",
6
6
  "react-native": "src/index",
@@ -31,21 +31,21 @@
31
31
  },
32
32
  "homepage": "https://github.com/birdofpreyru/js-utils#readme",
33
33
  "devDependencies": {
34
- "@babel/core": "^7.24.6",
35
- "@babel/preset-env": "^7.24.6",
36
- "@babel/preset-typescript": "^7.24.6",
37
- "@tsconfig/recommended": "^1.0.6",
38
- "@types/jest": "^29.5.12",
34
+ "@babel/core": "^7.26.9",
35
+ "@babel/preset-env": "^7.26.9",
36
+ "@babel/preset-typescript": "^7.26.0",
37
+ "@tsconfig/recommended": "^1.0.8",
38
+ "@types/jest": "^29.5.14",
39
39
  "babel-jest": "^29.7.0",
40
- "eslint": "^8.57.0",
40
+ "eslint": "^8.57.1",
41
41
  "eslint-config-airbnb-base": "^15.0.0",
42
42
  "eslint-config-airbnb-typescript": "^18.0.0",
43
- "eslint-import-resolver-typescript": "^3.6.1",
44
- "eslint-plugin-import": "^2.29.1",
43
+ "eslint-import-resolver-typescript": "^3.8.3",
44
+ "eslint-plugin-import": "^2.31.0",
45
45
  "jest": "^29.7.0",
46
- "rimraf": "^5.0.7",
47
- "tstyche": "^1.1.0",
48
- "typescript": "^5.4.5",
49
- "typescript-eslint": "^7.10.0"
46
+ "rimraf": "^6.0.1",
47
+ "tstyche": "^3.5.0",
48
+ "typescript": "^5.7.3",
49
+ "typescript-eslint": "^8.24.1"
50
50
  }
51
51
  }
package/tsconfig.json CHANGED
@@ -3,6 +3,7 @@
3
3
  "include": ["src/**/*"],
4
4
  "compilerOptions": {
5
5
  "declaration": true,
6
+ "module": "Preserve",
6
7
  "outDir": "build"
7
8
  }
8
9
  }
@@ -1,3 +1,6 @@
1
1
  {
2
- "testFileMatch": ["__tests__"]
2
+ "testFileMatch": [
3
+ "__tests__/**/*.ts",
4
+ "__tests__/**/*.tsx"
5
+ ]
3
6
  }