@trayio/commons 4.53.0 → 4.54.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.
@@ -61,7 +61,7 @@ class CamelCasePropertyNameCodec {
61
61
  return Object.entries(value).reduce((acc, [key, propertyValue]) => {
62
62
  if (this.isObject(propertyValue)) {
63
63
  const nestedObject = this.camelCasePropertyNameFromObjectIfPresent(propertyValue);
64
- return { ...acc, [key]: nestedObject };
64
+ return { ...acc, [StringExtensions_1.StringExtensions.camelCase(key)]: nestedObject };
65
65
  }
66
66
  if (Array.isArray(propertyValue)) {
67
67
  const nestedArray = this.camelCasePropertyNameFromArrayIfPresent(propertyValue);
@@ -67,4 +67,72 @@ describe('CamelCasePropertyNameCodec', () => {
67
67
  };
68
68
  expect(actualValue).toEqual(expectedValue);
69
69
  });
70
+ test('should camel case all properties names including nested and parent', () => {
71
+ const value = {
72
+ first_name: 'blah',
73
+ last_name: {
74
+ middle_name: 'blah',
75
+ },
76
+ addresses: [
77
+ {
78
+ street: 'blah street',
79
+ number: 123,
80
+ city: {
81
+ name: 'London',
82
+ province: null,
83
+ state: null,
84
+ },
85
+ notes_id: 'blah blah blah',
86
+ },
87
+ {
88
+ street: 'blah blah street',
89
+ number: 321,
90
+ city: {
91
+ name: 'New York',
92
+ province: null,
93
+ state: 'NY',
94
+ },
95
+ notes_id: null,
96
+ },
97
+ ],
98
+ phone: {
99
+ Area_Code: null,
100
+ TelephoneNumber: 1234567,
101
+ },
102
+ };
103
+ const actualValue = testCamelCasePropertyNameCodec.encode(value);
104
+ const expectedValue = {
105
+ firstName: 'blah',
106
+ lastName: {
107
+ middleName: 'blah',
108
+ },
109
+ addresses: [
110
+ {
111
+ street: 'blah street',
112
+ number: 123,
113
+ city: {
114
+ name: 'London',
115
+ province: null,
116
+ state: null,
117
+ },
118
+ notesId: 'blah blah blah',
119
+ },
120
+ {
121
+ street: 'blah blah street',
122
+ number: 321,
123
+ city: {
124
+ name: 'New York',
125
+ province: null,
126
+ state: 'NY',
127
+ },
128
+ notesId: null,
129
+ },
130
+ ],
131
+ phone: {
132
+ areaCode: null,
133
+ telephoneNumber: 1234567,
134
+ },
135
+ };
136
+ expect(actualValue).toEqual(expectedValue);
137
+ });
70
138
  });
@@ -61,7 +61,7 @@ class SnakeCasePropertyNameCodec {
61
61
  return Object.entries(value).reduce((acc, [key, propertyValue]) => {
62
62
  if (this.isObject(propertyValue)) {
63
63
  const nestedObject = this.snakeCasePropertyNameFromObjectIfPresent(propertyValue);
64
- return { ...acc, [key]: nestedObject };
64
+ return { ...acc, [StringExtensions_1.StringExtensions.snakeCase(key)]: nestedObject };
65
65
  }
66
66
  if (Array.isArray(propertyValue)) {
67
67
  const nestedArray = this.snakeCasePropertyNameFromArrayIfPresent(propertyValue);
@@ -67,4 +67,72 @@ describe('SnakeCasePropertyNameCodec', () => {
67
67
  };
68
68
  expect(actualValue).toEqual(expectedValue);
69
69
  });
70
+ test('should snake case all properties names including nested and parent', () => {
71
+ const value = {
72
+ firstName: 'blah',
73
+ LastName: {
74
+ middleName: 'blah',
75
+ },
76
+ addresses: [
77
+ {
78
+ street: 'blah street',
79
+ number: 123,
80
+ city: {
81
+ name: 'London',
82
+ province: null,
83
+ state: null,
84
+ },
85
+ notes_id: 'blah blah blah',
86
+ },
87
+ {
88
+ street: 'blah blah street',
89
+ number: 321,
90
+ city: {
91
+ name: 'New York',
92
+ province: null,
93
+ state: 'NY',
94
+ },
95
+ notesId: null,
96
+ },
97
+ ],
98
+ phone: {
99
+ Area_Code: null,
100
+ TelephoneNumber: 1234567,
101
+ },
102
+ };
103
+ const actualValue = testSnakeCasePropertyNameCodec.encode(value);
104
+ const expectedValue = {
105
+ first_name: 'blah',
106
+ last_name: {
107
+ middle_name: 'blah',
108
+ },
109
+ addresses: [
110
+ {
111
+ street: 'blah street',
112
+ number: 123,
113
+ city: {
114
+ name: 'London',
115
+ province: null,
116
+ state: null,
117
+ },
118
+ notes_id: 'blah blah blah',
119
+ },
120
+ {
121
+ street: 'blah blah street',
122
+ number: 321,
123
+ city: {
124
+ name: 'New York',
125
+ province: null,
126
+ state: 'NY',
127
+ },
128
+ notes_id: null,
129
+ },
130
+ ],
131
+ phone: {
132
+ area_code: null,
133
+ telephone_number: 1234567,
134
+ },
135
+ };
136
+ expect(actualValue).toEqual(expectedValue);
137
+ });
70
138
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayio/commons",
3
- "version": "4.53.0",
3
+ "version": "4.54.0",
4
4
  "description": "Extensions to the standard/core libraries and basic features",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js"