@dr.pogodin/js-utils 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/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  [![NPM Downloads](https://img.shields.io/npm/dm/@dr.pogodin/js-utils.svg)](https://www.npmjs.com/package/@dr.pogodin/js-utils)
7
7
  [![CircleCI](https://dl.circleci.com/status-badge/img/gh/birdofpreyru/js-utils/tree/master.svg?style=shield)](https://app.circleci.com/pipelines/github/birdofpreyru/js-utils)
8
8
  [![GitHub repo stars](https://img.shields.io/github/stars/birdofpreyru/js-utils?style=social)](https://github.com/birdofpreyru/js-utils)
9
- [![Dr. Pogodin Studio](https://raw.githubusercontent.com/birdofpreyru/js-utils/master/.README/logo-dr-pogodin-studio.png)](https://dr.pogodin.studio/docs/js-utils)
9
+ [![Dr. Pogodin Studio](https://raw.githubusercontent.com/birdofpreyru/js-utils/master/.README/logo-dr-pogodin-studio.svg)](https://dr.pogodin.studio/docs/js-utils)
10
10
 
11
11
  The aim for this repo/package is to move in from the [React Utils] the pieces
12
12
  which are not React-specific, thus are also useful cross non-React projects,
@@ -22,10 +22,10 @@ very well documented as such.
22
22
 
23
23
  Yeah, the source code will be written in TypeScript, and for the library
24
24
  version released to NPM it will be also compiled into plain JavaScript.
25
- Consumers of that NPM package thus will have access to both TS (`/ts` folder)
26
- and JS (`/js` folder) version of the library.
25
+ Consumers of that NPM package thus will have access to both TS (`/src` folder)
26
+ and JS (`/build` folder) version of the library.
27
27
 
28
- [![Sponsor](.README/sponsor.png)](https://github.com/sponsors/birdofpreyru)
28
+ [![Sponsor](https://raw.githubusercontent.com/birdofpreyru/js-utils/master/.README/sponsor.svg)](https://github.com/sponsors/birdofpreyru)
29
29
 
30
30
  ## Content
31
31
 
@@ -31,7 +31,7 @@ class Emitter {
31
31
  * @param args
32
32
  */
33
33
  emit(...args) {
34
- const { p_listeners: listeners } = this;
34
+ const listeners = this.p_listeners.slice();
35
35
  for (let i = 0; i < listeners.length; ++i) {
36
36
  listeners[i](...args);
37
37
  }
@@ -1,9 +1,9 @@
1
1
  import Barrier, { type Executor } from './Barrier';
2
2
  export declare const SEC_MS = 1000;
3
- export declare const MIN_MS: number;
4
- export declare const HOUR_MS: number;
5
- export declare const DAY_MS: number;
6
- export declare const YEAR_MS: number;
3
+ export declare const MIN_MS = 60000;
4
+ export declare const HOUR_MS = 3600000;
5
+ export declare const DAY_MS = 86400000;
6
+ export declare const YEAR_MS = 31536000000;
7
7
  export declare class Timer<T> extends Barrier<void, T> {
8
8
  private p_abort;
9
9
  private p_timeout?;
@@ -5,11 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.timer = exports.Timer = exports.YEAR_MS = exports.DAY_MS = exports.HOUR_MS = exports.MIN_MS = exports.SEC_MS = void 0;
7
7
  const Barrier_1 = __importDefault(require("./Barrier"));
8
+ // This is not very elegant, but as of now TypeScript does not support type
9
+ // arithmetic, thus we can't have constants assigned like `MIN_MS = 60 * SEC_MS`
10
+ // and have the result type to be 60000 (number literal), it would be just
11
+ // the generic number type.
8
12
  exports.SEC_MS = 1000;
9
- exports.MIN_MS = 60 * exports.SEC_MS;
10
- exports.HOUR_MS = 60 * exports.MIN_MS;
11
- exports.DAY_MS = 24 * exports.HOUR_MS;
12
- exports.YEAR_MS = 365 * exports.DAY_MS;
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
13
17
  // TODO: Ok, as we have ended up with a Timer class, mostly to achieve a good
14
18
  // TypeScript typing for timer() function, it makes sense to expose the class
15
19
  // from the library as well, and it should be documented later.
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ runner: 'jest-runner-tsd',
3
+ testMatch: ['**/__tests__/ts-types/**'],
4
+ };
package/jest.config.js CHANGED
@@ -1,4 +1,7 @@
1
1
  module.exports = {
2
2
  collectCoverage: true,
3
3
  coverageDirectory: '__coverage__',
4
+ testPathIgnorePatterns: [
5
+ '/__tests__/ts-types/',
6
+ ],
4
7
  };
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "@dr.pogodin/js-utils",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "Collection of JavaScript (TypeScript) utilities.",
5
- "main": "js/index",
6
- "react-native": "ts/index",
7
- "source": "ts/index",
8
- "types": "js/index.d.ts",
5
+ "main": "build/index",
6
+ "react-native": "src/index",
7
+ "source": "src/index",
8
+ "types": "build/index.d.ts",
9
9
  "scripts": {
10
- "build": "rimraf js && tsc",
11
- "jest": "jest --config jest.config.js",
10
+ "build": "rimraf build && tsc",
11
+ "jest": "npm run jest:types && npm run jest:logic",
12
+ "jest:logic": "jest --config jest.config.js",
13
+ "jest:types": "jest --config jest.config-types.js",
12
14
  "lint": "eslint . --ext .js,.ts",
13
- "test": "npm run build && npm run lint && npm run typecheck && npm run jest",
14
- "typecheck": "tsc --noEmit && tsc --project __tests__/ts/tsconfig.json"
15
+ "test": "npm run lint && npm run typecheck && npm run jest",
16
+ "typecheck": "tsc --noEmit && tsc --project __tests__/tsconfig.json"
15
17
  },
16
18
  "repository": {
17
19
  "type": "git",
@@ -29,21 +31,24 @@
29
31
  },
30
32
  "homepage": "https://github.com/birdofpreyru/js-utils#readme",
31
33
  "devDependencies": {
32
- "@babel/core": "^7.21.8",
33
- "@babel/preset-env": "^7.21.5",
34
- "@babel/preset-typescript": "^7.21.5",
35
- "@tsconfig/recommended": "^1.0.2",
36
- "@types/jest": "^29.5.1",
37
- "@typescript-eslint/eslint-plugin": "^5.59.6",
38
- "@typescript-eslint/parser": "^5.59.6",
39
- "babel-jest": "^29.5.0",
40
- "eslint": "^8.40.0",
34
+ "@babel/core": "^7.23.7",
35
+ "@babel/preset-env": "^7.23.8",
36
+ "@babel/preset-typescript": "^7.23.3",
37
+ "@tsconfig/recommended": "^1.0.3",
38
+ "@tsd/typescript": "^5.3.3",
39
+ "@types/jest": "^29.5.11",
40
+ "@typescript-eslint/eslint-plugin": "^6.19.0",
41
+ "@typescript-eslint/parser": "^6.19.0",
42
+ "babel-jest": "^29.7.0",
43
+ "eslint": "^8.56.0",
41
44
  "eslint-config-airbnb-base": "^15.0.0",
42
- "eslint-config-airbnb-typescript": "^17.0.0",
43
- "eslint-import-resolver-typescript": "^3.5.5",
44
- "eslint-plugin-import": "^2.27.5",
45
- "jest": "^29.5.0",
46
- "rimraf": "^5.0.0",
47
- "typescript": "^5.0.4"
45
+ "eslint-config-airbnb-typescript": "^17.1.0",
46
+ "eslint-import-resolver-typescript": "^3.6.1",
47
+ "eslint-plugin-import": "^2.29.1",
48
+ "jest": "^29.7.0",
49
+ "jest-runner-tsd": "^6.0.0",
50
+ "rimraf": "^5.0.5",
51
+ "tsd-lite": "^0.8.2",
52
+ "typescript": "^5.3.3"
48
53
  }
49
54
  }
@@ -33,7 +33,7 @@ export default class Emitter<T extends unknown[] = unknown[]> {
33
33
  * @param args
34
34
  */
35
35
  emit(...args: T) {
36
- const { p_listeners: listeners } = this;
36
+ const listeners = this.p_listeners.slice();
37
37
  for (let i = 0; i < listeners.length; ++i) {
38
38
  listeners[i](...args);
39
39
  }
@@ -1,10 +1,14 @@
1
1
  import Barrier, { type Executor } from './Barrier';
2
2
 
3
+ // This is not very elegant, but as of now TypeScript does not support type
4
+ // arithmetic, thus we can't have constants assigned like `MIN_MS = 60 * SEC_MS`
5
+ // and have the result type to be 60000 (number literal), it would be just
6
+ // the generic number type.
3
7
  export const SEC_MS = 1000;
4
- export const MIN_MS = 60 * SEC_MS;
5
- export const HOUR_MS = 60 * MIN_MS;
6
- export const DAY_MS = 24 * HOUR_MS;
7
- export const YEAR_MS = 365 * DAY_MS;
8
+ export const MIN_MS = 60000; // 60 * SEC_MS
9
+ export const HOUR_MS = 3600000; // 60 * MIN_MS
10
+ export const DAY_MS = 86400000; // 24 * HOUR_MS
11
+ export const YEAR_MS = 31536000000; // 365 * DAY_MS
8
12
 
9
13
  // TODO: Ok, as we have ended up with a Timer class, mostly to achieve a good
10
14
  // TypeScript typing for timer() function, it makes sense to expose the class
package/tsconfig.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "extends": "@tsconfig/recommended",
3
- "include": ["ts/**/*"],
3
+ "include": ["src/**/*"],
4
4
  "compilerOptions": {
5
5
  "declaration": true,
6
- "outDir": "js"
6
+ "outDir": "build"
7
7
  }
8
8
  }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes