@trojs/mutator 0.4.3 → 0.4.5

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@trojs/mutator",
3
3
  "description": "Mutate the value when set some data",
4
- "version": "0.4.3",
4
+ "version": "0.4.5",
5
5
  "author": {
6
6
  "name": "Pieter Wigboldus",
7
7
  "url": "https://trojs.org/"
@@ -24,6 +24,8 @@
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",
27
29
  "@babel/core": "^7.9.0",
28
30
  "@babel/eslint-parser": "^7.14.7",
29
31
  "@babel/plugin-transform-modules-commonjs": "^7.14.0",
@@ -33,14 +35,13 @@
33
35
  "eslint": "^8.6.0",
34
36
  "eslint-config-airbnb-base": "^15.0.0",
35
37
  "eslint-config-prettier": "^9.0.0",
36
- "eslint-config-standard": "^17.1.0",
37
38
  "eslint-plugin-html": "^8.0.0",
38
39
  "eslint-plugin-import": "^2.28.1",
39
- "eslint-plugin-jsdoc": "^48.0.4",
40
+ "eslint-plugin-jsdoc": "^50.0.0",
40
41
  "eslint-plugin-jsx-a11y": "^6.4.1",
41
- "eslint-plugin-n": "^16.2.0",
42
+ "eslint-plugin-n": "^17.0.0",
42
43
  "eslint-plugin-prettier": "^5.0.0",
43
- "eslint-plugin-promise": "^6.1.1",
44
+ "eslint-plugin-promise": "^7.0.0",
44
45
  "eslint-plugin-sonarjs": "^0.25.0",
45
46
  "jest": "^29.0.0",
46
47
  "jscpd": "^4.0.0",
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
- mapper ([key, value]) {
5
- if (value === undefined || value === null || Number.isNaN(value)) {
6
- return [key, undefined]
7
- }
8
-
9
- if (value.constructor === Object) {
10
- const mappedResult = Object.entries(value).map(
11
- ([subKey, subValue]) => {
12
- const result = [`${key}_${subKey}`, subValue]
13
- return [subKey, this.mapper(result)[1]]
4
+ mapper([key, value]) {
5
+ if (value === undefined || value === null || Number.isNaN(value)) {
6
+ return [key, undefined];
14
7
  }
15
- )
16
8
 
17
- const filteredResult = mappedResult.filter(Boolean)
9
+ if (value.constructor === Object) {
10
+ const mappedResult = Object.entries(value).map(
11
+ ([subKey, subValue]) => {
12
+ const result = [`${key}_${subKey}`, subValue];
13
+ return [subKey, this.mapper(result)[1]];
14
+ }
15
+ );
18
16
 
19
- return [key, Object.fromEntries(filteredResult)]
20
- }
17
+ const filteredResult = mappedResult.filter(Boolean);
21
18
 
22
- const fn = `set${capitalizeWords(key)}Attribute`
23
- if (this?.[fn]?.constructor === Function) {
24
- return [key, this[fn](value)]
25
- }
19
+ return [key, Object.fromEntries(filteredResult)];
20
+ }
26
21
 
27
- return [key, value]
28
- }
22
+ const fn = `set${capitalizeWords(key)}Attribute`;
23
+ if (this?.[fn]?.constructor === Function) {
24
+ return [key, this[fn](value)];
25
+ }
29
26
 
30
- hydrate (data) {
31
- const result = Object.entries(data).map(this.mapper.bind(this))
32
- const filteredResult = result.filter(
33
- ([key, value]) => key && value !== undefined
34
- )
27
+ return [key, value];
28
+ }
35
29
 
36
- Object.assign(this, Object.fromEntries(filteredResult))
37
- }
30
+ hydrate(data) {
31
+ const result = Object.entries(data).map(this.mapper.bind(this));
32
+ const filteredResult = result.filter(
33
+ ([key, value]) => key && value !== undefined
34
+ );
38
35
 
39
- static create (data) {
40
- const view = new this()
41
- view.hydrate(data)
36
+ Object.assign(this, Object.fromEntries(filteredResult));
37
+ }
42
38
 
43
- return view
44
- }
39
+ static create(data) {
40
+ const view = new this();
41
+ view.hydrate(data);
42
+
43
+ return view;
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
- string
6
- .split(/_| /)
7
- .map((word) => capitalizeFirstLetter(word))
8
- .join('')
5
+ string
6
+ .split(/_| /)
7
+ .map((word) => capitalizeFirstLetter(word))
8
+ .join('');