@thecb/components 5.0.0-beta.6 → 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/.babelrc +24 -0
- package/.eslintrc.json +2 -2
- package/dist/index.cjs.js +313 -137
- package/package.json +3 -2
- package/src/deprecated/utility/__tests__/safeConcat.spec.js +30 -28
- package/src/deprecated/utility/__tests__/validateKeyType.spec.js +65 -49
- package/src/deprecated/utility/index.js +2 -2
- package/src/deprecated/utility/safeConcat.js +3 -3
- package/src/deprecated/utility/validateKeyType.js +4 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thecb/components",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
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",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"homepage": "https://github.com/CityBaseInc/cb-components#readme",
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@babel/core": "^7.0.0-0",
|
|
24
|
+
"@babel/eslint-parser": "^7.15.8",
|
|
24
25
|
"@babel/preset-env": "^7.6.0",
|
|
25
26
|
"@babel/preset-react": "^7.0.0",
|
|
26
27
|
"@babel/register": "^7.6.2",
|
|
@@ -34,7 +35,6 @@
|
|
|
34
35
|
"@storybook/addon-viewport": "^5.3.14",
|
|
35
36
|
"@storybook/react": "^5.3.14",
|
|
36
37
|
"babel-core": "^6.26.3",
|
|
37
|
-
"babel-eslint": "^10.1.0",
|
|
38
38
|
"babel-loader": "^8.1.0",
|
|
39
39
|
"babel-preset-env": "^1.7.0",
|
|
40
40
|
"babel-preset-react": "^6.24.1",
|
|
@@ -73,6 +73,7 @@
|
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
+
"@babel/runtime": "^7.15.4",
|
|
76
77
|
"formatted-input": "^0.1.3",
|
|
77
78
|
"framer-motion": "^1.11.0",
|
|
78
79
|
"numeral": "^2.0.6",
|
|
@@ -1,59 +1,61 @@
|
|
|
1
|
-
//
|
|
1
|
+
//
|
|
2
2
|
|
|
3
|
-
import safeConcat from
|
|
3
|
+
import safeConcat from "../safeConcat";
|
|
4
4
|
|
|
5
|
-
describe(
|
|
5
|
+
describe("safeConcat", () => {
|
|
6
6
|
beforeEach(() => {
|
|
7
7
|
console.error = jest.fn();
|
|
8
8
|
});
|
|
9
9
|
|
|
10
|
-
describe(
|
|
11
|
-
describe(
|
|
12
|
-
it(
|
|
13
|
-
const result = safeConcat(
|
|
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(
|
|
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(
|
|
27
|
-
it(
|
|
28
|
-
const result = safeConcat([
|
|
29
|
-
expect(result).toEqual(
|
|
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(
|
|
33
|
-
const result = safeConcat([
|
|
34
|
-
expect(result).toEqual(
|
|
34
|
+
it("stringifies the concatinator", () => {
|
|
35
|
+
const result = safeConcat(["a", "b", "c"], 1);
|
|
36
|
+
expect(result).toEqual("a1b1c");
|
|
35
37
|
});
|
|
36
38
|
|
|
37
|
-
it(
|
|
38
|
-
const result = safeConcat([
|
|
39
|
-
expect(result).toEqual(
|
|
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(
|
|
43
|
-
const result = safeConcat([
|
|
44
|
-
expect(result).toEqual(
|
|
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(
|
|
48
|
-
const result = safeConcat([
|
|
49
|
-
expect(result).toEqual(
|
|
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(
|
|
54
|
-
it(
|
|
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
|
|
3
|
+
import validateKeyType from "../validateKeyType";
|
|
4
4
|
|
|
5
|
-
describe(
|
|
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:
|
|
12
|
-
aString:
|
|
11
|
+
aObject: { foo: "bar" },
|
|
12
|
+
aString: "bar"
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
describe(
|
|
16
|
-
it(
|
|
17
|
-
const result = validateKeyType(objParam,
|
|
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(
|
|
23
|
-
describe(
|
|
24
|
-
describe(
|
|
25
|
-
describe(
|
|
26
|
-
it(
|
|
27
|
-
const arrayResult = validateKeyType(objParam,
|
|
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(
|
|
33
|
-
it(
|
|
34
|
-
const arrayResult = validateKeyType(
|
|
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(
|
|
40
|
-
it(
|
|
41
|
-
const arrayResult = validateKeyType(
|
|
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(
|
|
47
|
-
it(
|
|
48
|
-
const arrayResult = validateKeyType(objParam,
|
|
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(
|
|
54
|
-
it(
|
|
55
|
-
const arrayResult = validateKeyType(objParam,
|
|
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(
|
|
61
|
-
it(
|
|
62
|
-
const arrayResult = validateKeyType(objParam,
|
|
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(
|
|
69
|
-
describe(
|
|
70
|
-
it(
|
|
71
|
-
const arrayResult = validateKeyType(objParam,
|
|
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(
|
|
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(
|
|
80
|
-
it(
|
|
81
|
-
const arrayResult = validateKeyType(objParam,
|
|
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(
|
|
87
|
-
it(
|
|
88
|
-
const arrayResult = validateKeyType(
|
|
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(
|
|
94
|
-
it(
|
|
95
|
-
const arrayResult = validateKeyType(objParam,
|
|
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(
|
|
101
|
-
it(
|
|
102
|
-
const arrayResult = validateKeyType(objParam,
|
|
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(
|
|
108
|
-
it(
|
|
109
|
-
const arrayResult = validateKeyType(objParam,
|
|
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
|
|
2
|
-
export { default as validateKeyType } from
|
|
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
|
|
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(
|
|
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 ===
|
|
8
|
+
if (expectedType === "object" && Array.isArray(obj[expectedKey])) {
|
|
11
9
|
return false;
|
|
12
10
|
}
|
|
13
11
|
|
|
14
|
-
if (expectedType ===
|
|
12
|
+
if (expectedType === "array" && Array.isArray(obj[expectedKey])) {
|
|
15
13
|
return true;
|
|
16
14
|
}
|
|
17
15
|
|