@sprucelabs/schema 29.1.2 → 29.2.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.
@@ -3,4 +3,6 @@ export default class KeyMapper {
3
3
  constructor(map: Record<string, any>);
4
4
  mapTo(values: Record<string, any>): any;
5
5
  mapFrom(values: Record<string, any>): any;
6
+ mapFieldNameTo(name: string): any;
7
+ mapFieldNameFrom(name: string): string | null;
6
8
  }
@@ -8,6 +8,20 @@ export default class KeyMapper {
8
8
  mapFrom(values) {
9
9
  return keyMapper.mapFrom(values, this.map);
10
10
  }
11
+ mapFieldNameTo(name) {
12
+ return this.map[name];
13
+ }
14
+ mapFieldNameFrom(name) {
15
+ for (const key in this.map) {
16
+ // eslint-disable-next-line no-prototype-builtins
17
+ if (this.map.hasOwnProperty(key)) {
18
+ if (this.map[key] === name) {
19
+ return key;
20
+ }
21
+ }
22
+ }
23
+ return null;
24
+ }
11
25
  }
12
26
  const keyMapper = {
13
27
  mapTo(values, map) {
@@ -3,4 +3,6 @@ export default class KeyMapper {
3
3
  constructor(map: Record<string, any>);
4
4
  mapTo(values: Record<string, any>): any;
5
5
  mapFrom(values: Record<string, any>): any;
6
+ mapFieldNameTo(name: string): any;
7
+ mapFieldNameFrom(name: string): string | null;
6
8
  }
@@ -10,6 +10,20 @@ class KeyMapper {
10
10
  mapFrom(values) {
11
11
  return keyMapper.mapFrom(values, this.map);
12
12
  }
13
+ mapFieldNameTo(name) {
14
+ return this.map[name];
15
+ }
16
+ mapFieldNameFrom(name) {
17
+ for (const key in this.map) {
18
+ // eslint-disable-next-line no-prototype-builtins
19
+ if (this.map.hasOwnProperty(key)) {
20
+ if (this.map[key] === name) {
21
+ return key;
22
+ }
23
+ }
24
+ }
25
+ return null;
26
+ }
13
27
  }
14
28
  exports.default = KeyMapper;
15
29
  const keyMapper = {
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "!build/__tests__",
9
9
  "esm"
10
10
  ],
11
- "version": "29.1.2",
11
+ "version": "29.2.0",
12
12
  "main": "./build/index.js",
13
13
  "types": "./build/index.d.ts",
14
14
  "module": "./build/esm/index.js",