@trayio/commons 2.9.0 → 2.10.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.
@@ -6,6 +6,7 @@ export declare class RemoveNullValuesCodec implements Codec<unknown> {
6
6
  decode(value: unknown): E.Either<Error, unknown>;
7
7
  private isObject;
8
8
  private removeNullValuesIfPresent;
9
+ private removeNullFromArrayIfPresent;
9
10
  private removeNullFromObjectIfPresent;
10
11
  }
11
12
  //# sourceMappingURL=RemoveNullValuesCodec.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RemoveNullValuesCodec.d.ts","sourceRoot":"","sources":["../../src/codec/RemoveNullValuesCodec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,qBAAa,qBAAsB,YAAW,KAAK,CAAC,OAAO,CAAC;IAC3D,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAA+B;IAE9D,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAI/B,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC;IAIhD,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,yBAAyB;IAUjC,OAAO,CAAC,6BAA6B;CAYrC"}
1
+ {"version":3,"file":"RemoveNullValuesCodec.d.ts","sourceRoot":"","sources":["../../src/codec/RemoveNullValuesCodec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,qBAAa,qBAAsB,YAAW,KAAK,CAAC,OAAO,CAAC;IAC3D,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAA+B;IAE9D,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAI/B,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC;IAIhD,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,yBAAyB;IAajC,OAAO,CAAC,4BAA4B;IASpC,OAAO,CAAC,6BAA6B;CAgBrC"}
@@ -42,8 +42,19 @@ class RemoveNullValuesCodec {
42
42
  if (this.isObject(value)) {
43
43
  return this.removeNullFromObjectIfPresent(value);
44
44
  }
45
+ if (Array.isArray(value)) {
46
+ return this.removeNullFromArrayIfPresent(value);
47
+ }
45
48
  return value;
46
49
  }
50
+ removeNullFromArrayIfPresent(value) {
51
+ return value.reduce((acc, propertyValue) => {
52
+ if (propertyValue == null) {
53
+ return acc;
54
+ }
55
+ return [...acc, this.removeNullValuesIfPresent(propertyValue)];
56
+ }, []);
57
+ }
47
58
  removeNullFromObjectIfPresent(value) {
48
59
  return Object.entries(value).reduce((acc, [key, propertyValue]) => {
49
60
  if (propertyValue == null) {
@@ -53,6 +64,10 @@ class RemoveNullValuesCodec {
53
64
  const nestedObject = this.removeNullFromObjectIfPresent(propertyValue);
54
65
  return Object.assign(Object.assign({}, acc), { [key]: nestedObject });
55
66
  }
67
+ if (Array.isArray(propertyValue)) {
68
+ const nestedArray = this.removeNullFromArrayIfPresent(propertyValue);
69
+ return Object.assign(Object.assign({}, acc), { [key]: nestedArray });
70
+ }
56
71
  return Object.assign(Object.assign({}, acc), { [key]: propertyValue });
57
72
  }, {});
58
73
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayio/commons",
3
- "version": "2.9.0",
3
+ "version": "2.10.0",
4
4
  "description": "Extensions to the standard/core libraries and basic features",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js"