scats 1.3.1 → 1.4.0-dev

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/.eslintrc.cjs ADDED
@@ -0,0 +1,44 @@
1
+ module.exports = {
2
+ parser: '@typescript-eslint/parser',
3
+ parserOptions: {
4
+ project: './tsconfig-eslint.json',
5
+ sourceType: 'module',
6
+ },
7
+ plugins: ['@typescript-eslint/eslint-plugin'],
8
+ extends: [
9
+ "eslint:recommended",
10
+ 'plugin:@typescript-eslint/eslint-recommended',
11
+ 'plugin:@typescript-eslint/recommended'
12
+ ],
13
+ root: true,
14
+ env: {
15
+ node: true,
16
+ jest: true,
17
+ },
18
+ rules: {
19
+ '@typescript-eslint/interface-name-prefix': 'off',
20
+ '@typescript-eslint/explicit-function-return-type': 'off',
21
+ '@typescript-eslint/no-explicit-any': 'off',
22
+ '@typescript-eslint/no-namespace': 'off',
23
+ '@typescript-eslint/no-non-null-assertion': 'off',
24
+ '@typescript-eslint/member-delimiter-style': 'error',
25
+ 'quotes': ["error", "single"],
26
+ "camelcase": ["error", {"properties": "always"}],
27
+ "semi": "off",
28
+ "@typescript-eslint/semi": ["error"],
29
+ "@typescript-eslint/prefer-readonly": ["error"],
30
+ "no-labels": "error",
31
+ "key-spacing": "error",
32
+ "keyword-spacing": "error",
33
+ "no-continue": "error",
34
+ "no-lonely-if": "error",
35
+ "no-multi-assign": "error",
36
+ "no-nested-ternary": "error",
37
+ "no-new-object": "error",
38
+ "no-unneeded-ternary": "error",
39
+ "no-whitespace-before-property": "error",
40
+ "nonblock-statement-body-position": "error",
41
+ 'arrow-spacing': "error",
42
+ "@typescript-eslint/no-unused-vars": ["error", {"argsIgnorePattern": "_"}]
43
+ },
44
+ };
@@ -103,9 +103,9 @@ class Collection extends ArrayBackedCollection {
103
103
  return new Collection(this.items.map(i => f(i)));
104
104
  }
105
105
  flatMap(f) {
106
- const res = [];
106
+ let res = [];
107
107
  this.items.forEach(i => {
108
- res.push(...f(i).items);
108
+ res = res.concat(f(i).items);
109
109
  });
110
110
  return new Collection(res);
111
111
  }
@@ -134,10 +134,10 @@ class Collection extends ArrayBackedCollection {
134
134
  }
135
135
  flatMapPromise(f) {
136
136
  return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
137
- const res = [];
137
+ let res = [];
138
138
  for (let i = 0; i < this.items.length; i++) {
139
139
  const item = this.items[i];
140
- res.push(...(yield f(item)).items);
140
+ res = res.concat((yield f(item)).items);
141
141
  }
142
142
  return new Collection(res);
143
143
  });
@@ -331,7 +331,7 @@ class ArrayBuffer extends ArrayBackedCollection {
331
331
  flatMap(f) {
332
332
  let res = [];
333
333
  this.items.forEach(i => {
334
- res = res.concat(...f(i).items);
334
+ res = res.concat(f(i).items);
335
335
  });
336
336
  return new ArrayBuffer(res);
337
337
  }
package/jest.config.js ADDED
@@ -0,0 +1,32 @@
1
+
2
+ const config = {
3
+ preset: 'ts-jest',
4
+ testEnvironment: 'node',
5
+ rootDir: '.',
6
+ roots: ['test'],
7
+ collectCoverageFrom: ["src/**/*.ts"],
8
+ reporters: ['default'],
9
+ coverageThreshold: {
10
+ global: {
11
+ branches: 10,
12
+ functions: 50,
13
+ lines: 50,
14
+ statements: 50
15
+ }
16
+ },
17
+ extensionsToTreatAsEsm: ['.ts'],
18
+ moduleNameMapper: {
19
+ '^(\\.{1,2}/.*)\\.js$': '$1',
20
+ },
21
+ transform: {
22
+ // '^.+\\.[tj]sx?$' to process ts,js,tsx,jsx with `ts-jest`
23
+ // '^.+\\.m?[tj]sx?$' to process ts,js,tsx,jsx,mts,mjs,mtsx,mjsx with `ts-jest`
24
+ '^.+\\.tsx?$': [
25
+ 'ts-jest',
26
+ {
27
+ useESM: true,
28
+ },
29
+ ],
30
+ },
31
+ };
32
+ export default config;
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "scats",
3
- "version": "1.3.1",
3
+ "version": "1.4.0-dev",
4
4
  "description": "Useful scala classes in typescript",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "type": "module",
7
8
  "scripts": {
8
9
  "clean": "rimraf dist",
9
10
  "lint": "eslint \"{src,test}/**/*.ts\" --fix",
@@ -36,15 +37,15 @@
36
37
  },
37
38
  "homepage": "https://github.com/papirosko/scats#readme",
38
39
  "devDependencies": {
39
- "@types/jest": "^27.0.3",
40
+ "@types/jest": "27.0.3",
40
41
  "@typescript-eslint/eslint-plugin": "5.6.0",
41
42
  "@typescript-eslint/parser": "5.6.0",
42
43
  "eslint": "7.32.0",
43
- "eslint-plugin-import": "^2.25.3",
44
- "jest": "^27.4.4",
45
- "ts-jest": "^27.1.1",
46
- "ts-node": "^10.4.0",
47
- "typescript": "^4.5.3"
44
+ "eslint-plugin-import": "2.25.3",
45
+ "jest": "27.4.4",
46
+ "ts-jest": "27.1.1",
47
+ "ts-node": "10.4.0",
48
+ "typescript": "4.5.5"
48
49
  },
49
50
  "dependencies": {
50
51
  "tslib": "^2.3.1"
package/src/collection.ts CHANGED
@@ -133,9 +133,10 @@ export class Collection<T> extends ArrayBackedCollection<T, Collection<T>> imple
133
133
  }
134
134
 
135
135
  flatMap<B>(f: (item: T) => Collection<B>): Collection<B> {
136
- const res: B[] = [];
136
+ //https://stackoverflow.com/questions/61740599/rangeerror-maximum-call-stack-size-exceeded-with-array-push
137
+ let res: B[] = [];
137
138
  this.items.forEach(i => {
138
- res.push(...f(i).items);
139
+ res = res.concat(f(i).items);
139
140
  });
140
141
  return new Collection<B>(res);
141
142
  }
@@ -201,10 +202,10 @@ export class Collection<T> extends ArrayBackedCollection<T, Collection<T>> imple
201
202
  * @param f
202
203
  */
203
204
  async flatMapPromise<B>(f: (item: T) => Promise<Collection<B>>): Promise<Collection<B>> {
204
- const res: B[] = [];
205
+ let res: B[] = [];
205
206
  for (let i = 0; i < this.items.length; i++) {
206
207
  const item = this.items[i];
207
- res.push(...(await f(item)).items);
208
+ res = res.concat((await f(item)).items);
208
209
  }
209
210
  return new Collection<B>(res);
210
211
  }
@@ -553,7 +554,7 @@ export class ArrayBuffer<T> extends ArrayBackedCollection<T, ArrayBuffer<T>> imp
553
554
  //https://stackoverflow.com/questions/61740599/rangeerror-maximum-call-stack-size-exceeded-with-array-push
554
555
  let res: B[] = [];
555
556
  this.items.forEach(i => {
556
- res = res.concat(...f(i).items);
557
+ res = res.concat(f(i).items);
557
558
  });
558
559
  return new ArrayBuffer<B>(res);
559
560
  }