@trojs/mutator 0.4.6 → 1.0.0

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,16 +1,16 @@
1
1
  {
2
2
  "name": "@trojs/mutator",
3
3
  "description": "Mutate the value when set some data",
4
- "version": "0.4.6",
4
+ "version": "1.0.0",
5
5
  "author": {
6
6
  "name": "Pieter Wigboldus",
7
7
  "url": "https://trojs.org/"
8
8
  },
9
9
  "license": "MIT",
10
10
  "scripts": {
11
- "lint": "eslint src/*.js --config .eslintrc",
12
- "lint:fix": "eslint src/*.js --config .eslintrc --fix",
13
- "lint:report": "eslint src/*.js --config .eslintrc -f json -o report.json",
11
+ "lint": "eslint",
12
+ "lint:fix": "eslint --fix",
13
+ "lint:report": "eslint src/*.js -f json -o report.json",
14
14
  "test": "jest",
15
15
  "test:watch": "jest src --watch",
16
16
  "coveralls": "jest && codecov && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
@@ -24,25 +24,24 @@
24
24
  ],
25
25
  "main": "src/default.js",
26
26
  "devDependencies": {
27
- "@hckrnews/eslint-code-quality": "^0.2.0",
28
- "@hckrnews/eslint-config": "^3.0.0",
29
27
  "@babel/core": "^7.9.0",
30
28
  "@babel/eslint-parser": "^7.14.7",
31
29
  "@babel/plugin-transform-modules-commonjs": "^7.14.0",
32
30
  "@babel/preset-env": "^7.9.5",
31
+ "@eslint/js": "^9.15.0",
33
32
  "@jest/globals": "^29.0.0",
33
+ "@stylistic/eslint-plugin": "^2.11.0",
34
+ "@stylistic/eslint-plugin-js": "^2.11.0",
34
35
  "babel-jest": "^29.0.0",
35
- "eslint": "^8.6.0",
36
- "eslint-config-airbnb-base": "^15.0.0",
37
- "eslint-config-prettier": "^9.0.0",
38
- "eslint-plugin-html": "^8.0.0",
39
- "eslint-plugin-import": "^2.28.1",
40
- "eslint-plugin-jsdoc": "^50.0.0",
41
- "eslint-plugin-jsx-a11y": "^6.4.1",
42
- "eslint-plugin-n": "^17.0.0",
43
- "eslint-plugin-prettier": "^5.0.0",
44
- "eslint-plugin-promise": "^7.0.0",
45
- "eslint-plugin-sonarjs": "^0.25.0",
36
+ "eslint": "^9.15.0",
37
+ "eslint-config-prettier": "^9.1.0",
38
+ "eslint-plugin-import": "^2.31.0",
39
+ "eslint-plugin-jsdoc": "^50.5.0",
40
+ "eslint-plugin-n": "^17.14.0",
41
+ "eslint-plugin-prettier": "^5.2.1",
42
+ "eslint-plugin-promise": "^7.1.0",
43
+ "eslint-plugin-sonarjs": "^2.0.4",
44
+ "globals": "^15.12.0",
46
45
  "jest": "^29.0.0",
47
46
  "jscpd": "^4.0.0",
48
47
  "prettier": "^3.0.0"
@@ -52,10 +51,19 @@
52
51
  "url": "https://github.com/trojs/mutator"
53
52
  },
54
53
  "engines": {
55
- "node": ">= 18"
54
+ "node": ">= 20"
56
55
  },
57
56
  "keywords": [
58
57
  "object",
59
58
  "mutate"
60
- ]
59
+ ],
60
+ "overrides": {
61
+ "eslint-plugin-sonarjs": {
62
+ "eslint": "^9.15.0",
63
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
64
+ "@typescript-eslint/utils": "^8.0.0",
65
+ "eslint-plugin-import": "^2.31.0",
66
+ "eslint-plugin-react-hooks": "^5.0.0"
67
+ }
68
+ }
61
69
  }
package/src/default.js CHANGED
@@ -1,45 +1,45 @@
1
- import { capitalizeWords } from './string-helper.js';
1
+ import { capitalizeWords } from './string-helper.js'
2
2
 
3
3
  export default class DefaultMutator {
4
4
  mapper([key, value]) {
5
5
  if (value === undefined || value === null || Number.isNaN(value)) {
6
- return [key, undefined];
6
+ return [key, undefined]
7
7
  }
8
8
 
9
9
  if (value.constructor === Object) {
10
10
  const mappedResult = Object.entries(value).map(
11
11
  ([subKey, subValue]) => {
12
- const result = [`${key}_${subKey}`, subValue];
13
- return [subKey, this.mapper(result)[1]];
12
+ const result = [`${key}_${subKey}`, subValue]
13
+ return [subKey, this.mapper(result)[1]]
14
14
  }
15
- );
15
+ )
16
16
 
17
- const filteredResult = mappedResult.filter(Boolean);
17
+ const filteredResult = mappedResult.filter(Boolean)
18
18
 
19
- return [key, Object.fromEntries(filteredResult)];
19
+ return [key, Object.fromEntries(filteredResult)]
20
20
  }
21
21
 
22
- const fn = `set${capitalizeWords(key)}Attribute`;
22
+ const fn = `set${capitalizeWords(key)}Attribute`
23
23
  if (this?.[fn]?.constructor === Function) {
24
- return [key, this[fn](value)];
24
+ return [key, this[fn](value)]
25
25
  }
26
26
 
27
- return [key, value];
27
+ return [key, value]
28
28
  }
29
29
 
30
30
  hydrate(data) {
31
- const result = Object.entries(data).map(this.mapper.bind(this));
31
+ const result = Object.entries(data).map(this.mapper.bind(this))
32
32
  const filteredResult = result.filter(
33
33
  ([key, value]) => key && value !== undefined
34
- );
34
+ )
35
35
 
36
- Object.assign(this, Object.fromEntries(filteredResult));
36
+ Object.assign(this, Object.fromEntries(filteredResult))
37
37
  }
38
38
 
39
39
  static create(data) {
40
- const view = new this();
41
- view.hydrate(data);
40
+ const view = new this()
41
+ view.hydrate(data)
42
42
 
43
- return view;
43
+ return view
44
44
  }
45
45
  }
@@ -1,8 +1,8 @@
1
1
  export const capitalizeFirstLetter = (string) =>
2
- string.charAt(0).toUpperCase() + string.slice(1);
2
+ string.charAt(0).toUpperCase() + string.slice(1)
3
3
 
4
4
  export const capitalizeWords = (string) =>
5
5
  string
6
- .split(/_| /)
7
- .map((word) => capitalizeFirstLetter(word))
8
- .join('');
6
+ .split(/[_| ]/)
7
+ .map((word)=>capitalizeFirstLetter(word))
8
+ .join('')