@trojs/mutator 1.0.2 → 1.0.4

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": "1.0.2",
4
+ "version": "1.0.4",
5
5
  "author": {
6
6
  "name": "Pieter Wigboldus",
7
7
  "url": "https://trojs.org/"
@@ -11,8 +11,7 @@
11
11
  "lint": "eslint",
12
12
  "lint:fix": "eslint --fix",
13
13
  "lint:report": "eslint src/*.js -f json -o report.json",
14
- "test": "c8 node --test src/__tests__/*.js",
15
- "test:watch": "c8 node --test --watch src/__tests__/*.js",
14
+ "test": "node --test --experimental-test-coverage --test-reporter=spec --test-reporter=lcov --test-reporter-destination=stdout --test-reporter-destination=./coverage/lcov.info",
16
15
  "cpd": "node_modules/jscpd/bin/jscpd src",
17
16
  "vulnerabilities": "npm audit --only=prod"
18
17
  },
@@ -23,21 +22,10 @@
23
22
  ],
24
23
  "main": "src/default.js",
25
24
  "devDependencies": {
26
- "@eslint/js": "^9.15.0",
27
- "@stylistic/eslint-plugin": "^2.11.0",
28
- "@stylistic/eslint-plugin-js": "^2.11.0",
29
- "c8": "^10.1.2",
25
+ "@trojs/lint": "^0.2.9",
30
26
  "eslint": "^9.15.0",
31
- "eslint-config-prettier": "^10.0.0",
32
- "eslint-plugin-import": "^2.31.0",
33
- "eslint-plugin-jsdoc": "^50.5.0",
34
- "eslint-plugin-n": "^17.14.0",
35
- "eslint-plugin-prettier": "^5.2.1",
36
- "eslint-plugin-promise": "^7.1.0",
37
- "eslint-plugin-sonarjs": "^2.0.4",
38
- "globals": "^15.12.0",
39
- "jscpd": "^4.0.0",
40
- "prettier": "^3.0.0"
27
+ "globals": "^16.0.0",
28
+ "jscpd": "^4.0.5"
41
29
  },
42
30
  "repository": {
43
31
  "type": "git",
package/src/default.js CHANGED
@@ -1,45 +1,45 @@
1
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]]
14
- }
15
- )
16
-
17
- const filteredResult = mappedResult.filter(Boolean)
4
+ mapper ([key, value]) {
5
+ if (value === undefined || value === null || Number.isNaN(value)) {
6
+ return [key, undefined]
7
+ }
18
8
 
19
- return [key, Object.fromEntries(filteredResult)]
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]]
20
14
  }
15
+ )
21
16
 
22
- const fn = `set${capitalizeWords(key)}Attribute`
23
- if (this?.[fn]?.constructor === Function) {
24
- return [key, this[fn](value)]
25
- }
17
+ const filteredResult = mappedResult.filter(Boolean)
26
18
 
27
- return [key, value]
19
+ return [key, Object.fromEntries(filteredResult)]
28
20
  }
29
21
 
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
- )
35
-
36
- Object.assign(this, Object.fromEntries(filteredResult))
22
+ const fn = `set${capitalizeWords(key)}Attribute`
23
+ if (this?.[fn]?.constructor === Function) {
24
+ return [key, this[fn](value)]
37
25
  }
38
26
 
39
- static create(data) {
40
- const view = new this()
41
- view.hydrate(data)
27
+ return [key, value]
28
+ }
42
29
 
43
- return view
44
- }
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
+ )
35
+
36
+ Object.assign(this, Object.fromEntries(filteredResult))
37
+ }
38
+
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('')