@thecb/components 5.0.0-beta.8 → 5.0.0-beta.9

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "5.0.0-beta.8",
3
+ "version": "5.0.0-beta.9",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -1,59 +1,61 @@
1
- //
1
+ //
2
2
 
3
- import safeConcat from '../safeConcat';
3
+ import safeConcat from "../safeConcat";
4
4
 
5
- describe('safeConcat', () => {
5
+ describe("safeConcat", () => {
6
6
  beforeEach(() => {
7
7
  console.error = jest.fn();
8
8
  });
9
9
 
10
- describe('arg validation', () => {
11
- describe('when values not an array', () => {
12
- it('throws console error', () => {
13
- const result = safeConcat('a', '-');
10
+ describe("arg validation", () => {
11
+ describe("when values not an array", () => {
12
+ it("throws console error", () => {
13
+ const result = safeConcat("a", "-");
14
14
 
15
15
  const errors = console.error.mock.calls;
16
16
  expect(errors.length).toEqual(1);
17
17
 
18
18
  const firstError = errors[0][0];
19
- expect(firstError).toEqual('\'values\' needs to be an array. Recieved string');
19
+ expect(firstError).toEqual(
20
+ "'values' needs to be an array. Recieved string"
21
+ );
20
22
 
21
23
  expect(result).toEqual(undefined);
22
24
  });
23
25
  });
24
26
  });
25
27
 
26
- describe('with valid values', () => {
27
- it('concatinates strings with concatinator', () => {
28
- const result = safeConcat(['a', 'b', 'c'], '-');
29
- expect(result).toEqual('a-b-c');
28
+ describe("with valid values", () => {
29
+ it("concatinates strings with concatinator", () => {
30
+ const result = safeConcat(["a", "b", "c"], "-");
31
+ expect(result).toEqual("a-b-c");
30
32
  });
31
33
 
32
- it('stringifies the concatinator', () => {
33
- const result = safeConcat(['a', 'b', 'c'], 1);
34
- expect(result).toEqual('a1b1c');
34
+ it("stringifies the concatinator", () => {
35
+ const result = safeConcat(["a", "b", "c"], 1);
36
+ expect(result).toEqual("a1b1c");
35
37
  });
36
38
 
37
- it('removes falsey string values from values array', () => {
38
- const result = safeConcat(['a', undefined, 'b', ''], '-');
39
- expect(result).toEqual('a-b');
39
+ it("removes falsey string values from values array", () => {
40
+ const result = safeConcat(["a", undefined, "b", ""], "-");
41
+ expect(result).toEqual("a-b");
40
42
  });
41
43
 
42
- it('does not append concatinator single values arrays', () => {
43
- const result = safeConcat(['a'], '-');
44
- expect(result).toEqual('a');
44
+ it("does not append concatinator single values arrays", () => {
45
+ const result = safeConcat(["a"], "-");
46
+ expect(result).toEqual("a");
45
47
  });
46
48
 
47
- it('does not append concatinator to single truthy values', () => {
48
- const result = safeConcat(['a', undefined], '-');
49
- expect(result).toEqual('a');
49
+ it("does not append concatinator to single truthy values", () => {
50
+ const result = safeConcat(["a", undefined], "-");
51
+ expect(result).toEqual("a");
50
52
  });
51
53
  });
52
54
 
53
- describe('with no valid values', () => {
54
- it('returns empty string when no valid values', () => {
55
- const result = safeConcat([undefined], '-');
56
- expect(result).toEqual('');
55
+ describe("with no valid values", () => {
56
+ it("returns empty string when no valid values", () => {
57
+ const result = safeConcat([undefined], "-");
58
+ expect(result).toEqual("");
57
59
  });
58
60
  });
59
61
  });
@@ -1,112 +1,128 @@
1
- //
1
+ //
2
2
 
3
- import validateKeyType from '../validateKeyType';
3
+ import validateKeyType from "../validateKeyType";
4
4
 
5
- describe('validateKeyType', () => {
5
+ describe("validateKeyType", () => {
6
6
  const objParam = {
7
7
  aArray: [1],
8
8
  aBoolean: true,
9
9
  aFunction: jest.fn(),
10
10
  aNumber: 1,
11
- aObject: { foo: 'bar' },
12
- aString: 'bar'
11
+ aObject: { foo: "bar" },
12
+ aString: "bar"
13
13
  };
14
14
 
15
- describe('when obj param does not contain key param', () => {
16
- it('returns false', () => {
17
- const result = validateKeyType(objParam, 'wrong-key', 'string');
15
+ describe("when obj param does not contain key param", () => {
16
+ it("returns false", () => {
17
+ const result = validateKeyType(objParam, "wrong-key", "string");
18
18
  expect(result).toEqual(false);
19
19
  });
20
20
  });
21
21
 
22
- describe('when obj param contains key param', () => {
23
- describe('when obj[key] type', () => {
24
- describe('matches type param', () => {
25
- describe('of Array', () => {
26
- it('returns true', () => {
27
- const arrayResult = validateKeyType(objParam, 'aArray', 'array');
22
+ describe("when obj param contains key param", () => {
23
+ describe("when obj[key] type", () => {
24
+ describe("matches type param", () => {
25
+ describe("of Array", () => {
26
+ it("returns true", () => {
27
+ const arrayResult = validateKeyType(objParam, "aArray", "array");
28
28
  expect(arrayResult).toEqual(true);
29
29
  });
30
30
  });
31
31
 
32
- describe('of Boolean', () => {
33
- it('returns true', () => {
34
- const arrayResult = validateKeyType(objParam, 'aBoolean', 'boolean');
32
+ describe("of Boolean", () => {
33
+ it("returns true", () => {
34
+ const arrayResult = validateKeyType(
35
+ objParam,
36
+ "aBoolean",
37
+ "boolean"
38
+ );
35
39
  expect(arrayResult).toEqual(true);
36
40
  });
37
41
  });
38
42
 
39
- describe('of Function', () => {
40
- it('returns true', () => {
41
- const arrayResult = validateKeyType(objParam, 'aFunction', 'function');
43
+ describe("of Function", () => {
44
+ it("returns true", () => {
45
+ const arrayResult = validateKeyType(
46
+ objParam,
47
+ "aFunction",
48
+ "function"
49
+ );
42
50
  expect(arrayResult).toEqual(true);
43
51
  });
44
52
  });
45
53
 
46
- describe('of Number', () => {
47
- it('returns true', () => {
48
- const arrayResult = validateKeyType(objParam, 'aNumber', 'number');
54
+ describe("of Number", () => {
55
+ it("returns true", () => {
56
+ const arrayResult = validateKeyType(objParam, "aNumber", "number");
49
57
  expect(arrayResult).toEqual(true);
50
58
  });
51
59
  });
52
60
 
53
- describe('of Object', () => {
54
- it('returns true', () => {
55
- const arrayResult = validateKeyType(objParam, 'aObject', 'object');
61
+ describe("of Object", () => {
62
+ it("returns true", () => {
63
+ const arrayResult = validateKeyType(objParam, "aObject", "object");
56
64
  expect(arrayResult).toEqual(true);
57
65
  });
58
66
  });
59
67
 
60
- describe('of String', () => {
61
- it('returns true', () => {
62
- const arrayResult = validateKeyType(objParam, 'aString', 'string');
68
+ describe("of String", () => {
69
+ it("returns true", () => {
70
+ const arrayResult = validateKeyType(objParam, "aString", "string");
63
71
  expect(arrayResult).toEqual(true);
64
72
  });
65
73
  });
66
74
  });
67
75
 
68
- describe('does not match type param', () => {
69
- describe('of Array', () => {
70
- it('returns false', () => {
71
- const arrayResult = validateKeyType(objParam, 'aArray', 'string');
76
+ describe("does not match type param", () => {
77
+ describe("of Array", () => {
78
+ it("returns false", () => {
79
+ const arrayResult = validateKeyType(objParam, "aArray", "string");
72
80
  expect(arrayResult).toEqual(false);
73
81
 
74
- const arrayObjResult = validateKeyType(objParam, 'aArray', 'object');
82
+ const arrayObjResult = validateKeyType(
83
+ objParam,
84
+ "aArray",
85
+ "object"
86
+ );
75
87
  expect(arrayObjResult).toEqual(false);
76
88
  });
77
89
  });
78
90
 
79
- describe('of Boolean', () => {
80
- it('returns false', () => {
81
- const arrayResult = validateKeyType(objParam, 'aBoolean', 'string');
91
+ describe("of Boolean", () => {
92
+ it("returns false", () => {
93
+ const arrayResult = validateKeyType(objParam, "aBoolean", "string");
82
94
  expect(arrayResult).toEqual(false);
83
95
  });
84
96
  });
85
97
 
86
- describe('of Function', () => {
87
- it('returns false', () => {
88
- const arrayResult = validateKeyType(objParam, 'aFunction', 'string');
98
+ describe("of Function", () => {
99
+ it("returns false", () => {
100
+ const arrayResult = validateKeyType(
101
+ objParam,
102
+ "aFunction",
103
+ "string"
104
+ );
89
105
  expect(arrayResult).toEqual(false);
90
106
  });
91
107
  });
92
108
 
93
- describe('of Number', () => {
94
- it('returns false', () => {
95
- const arrayResult = validateKeyType(objParam, 'aNumber', 'string');
109
+ describe("of Number", () => {
110
+ it("returns false", () => {
111
+ const arrayResult = validateKeyType(objParam, "aNumber", "string");
96
112
  expect(arrayResult).toEqual(false);
97
113
  });
98
114
  });
99
115
 
100
- describe('of Object', () => {
101
- it('returns false', () => {
102
- const arrayResult = validateKeyType(objParam, 'aObject', 'string');
116
+ describe("of Object", () => {
117
+ it("returns false", () => {
118
+ const arrayResult = validateKeyType(objParam, "aObject", "string");
103
119
  expect(arrayResult).toEqual(false);
104
120
  });
105
121
  });
106
122
 
107
- describe('of String', () => {
108
- it('returns false', () => {
109
- const arrayResult = validateKeyType(objParam, 'aString', 'number');
123
+ describe("of String", () => {
124
+ it("returns false", () => {
125
+ const arrayResult = validateKeyType(objParam, "aString", "number");
110
126
  expect(arrayResult).toEqual(false);
111
127
  });
112
128
  });
@@ -1,2 +1,2 @@
1
- export { default as safeConcat } from './safeConcat';
2
- export { default as validateKeyType } from './validateKeyType';
1
+ export { default as safeConcat } from "./safeConcat";
2
+ export { default as validateKeyType } from "./validateKeyType";
@@ -1,10 +1,10 @@
1
- //
1
+ //
2
2
 
3
- export default function safeConcat(values , concatinator ) {
3
+ export default function safeConcat(values, concatinator) {
4
4
  if (!Array.isArray(values)) {
5
5
  console.error(`'values' needs to be an array. Recieved ${typeof values}`);
6
6
  return;
7
7
  }
8
8
 
9
- return values.filter((val ) => !!val).join(String(concatinator));
9
+ return values.filter(val => !!val).join(String(concatinator));
10
10
  }
@@ -1,17 +1,15 @@
1
- //
1
+ //
2
2
 
3
- export default function validateKeyType(obj ,
4
- expectedKey ,
5
- expectedType ) {
3
+ export default function validateKeyType(obj, expectedKey, expectedType) {
6
4
  if (!(expectedKey in obj)) {
7
5
  return false;
8
6
  }
9
7
 
10
- if (expectedType === 'object' && Array.isArray(obj[expectedKey])) {
8
+ if (expectedType === "object" && Array.isArray(obj[expectedKey])) {
11
9
  return false;
12
10
  }
13
11
 
14
- if (expectedType === 'array' && Array.isArray(obj[expectedKey])) {
12
+ if (expectedType === "array" && Array.isArray(obj[expectedKey])) {
15
13
  return true;
16
14
  }
17
15