Skip to content

Commit 75e8664

Browse files
authored
Implemented equals for simplicity reasons
1 parent bb892ad commit 75e8664

File tree

10 files changed

+98
-39
lines changed

10 files changed

+98
-39
lines changed

src/column/renderAlignSelf.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import ColumnAlignSelf from "./ColumnAlignSelf";
2-
import { css } from "../utils";
2+
import { css, equals } from "../utils";
33

44
export default (alignSelf?: ColumnAlignSelf): string => {
55
if (
6-
alignSelf === "baseline" ||
7-
alignSelf === "center" ||
8-
alignSelf === "flex-end" ||
9-
alignSelf === "flex-start" ||
10-
alignSelf === "stretch"
6+
equals(alignSelf, [
7+
"baseline",
8+
"center",
9+
"flex-end",
10+
"flex-start",
11+
"stretch"
12+
])
1113
) {
1214
return css`
13-
align-self: ${alignSelf} !important;
15+
align-self: ${alignSelf + ""} !important;
1416
`;
1517
} else {
1618
return "";

src/row/renderAlignContent.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import RowAlignContent from "./RowAlignContent";
2-
import { css } from "../utils";
2+
import { css, equals } from "../utils";
33

44
export default (alignContent?: RowAlignContent): string => {
55
if (
6-
alignContent === "center" ||
7-
alignContent === "flex-end" ||
8-
alignContent === "flex-start" ||
9-
alignContent === "space-around" ||
10-
alignContent === "space-between" ||
11-
alignContent === "stretch"
6+
equals(alignContent, [
7+
"center",
8+
"flex-end",
9+
"flex-start",
10+
"space-around",
11+
"space-between",
12+
"stretch"
13+
])
1214
) {
1315
return css`
14-
align-content: ${alignContent} !important;
16+
align-content: ${alignContent + ""} !important;
1517
`;
1618
} else {
1719
return "";

src/row/renderAlignItems.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import RowAlignItems from "./RowAlignItems";
2-
import { css } from "../utils";
2+
import { css, equals } from "../utils";
33

44
export default (alignItems?: RowAlignItems): string => {
55
if (
6-
alignItems === "baseline" ||
7-
alignItems === "center" ||
8-
alignItems === "flex-end" ||
9-
alignItems === "flex-start" ||
10-
alignItems === "stretch"
6+
equals(alignItems, [
7+
"baseline",
8+
"center",
9+
"flex-end",
10+
"flex-start",
11+
"stretch"
12+
])
1113
) {
1214
return css`
13-
align-items: ${alignItems} !important;
15+
align-items: ${alignItems + ""} !important;
1416
`;
1517
} else {
1618
return "";

src/row/renderDirection.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
import RowDirection from "./RowDirection";
2-
import { css } from "../utils";
2+
import { css, equals } from "../utils";
33

44
export default (direction?: RowDirection): string => {
5-
if (
6-
direction === "column" ||
7-
direction === "column-reverse" ||
8-
direction === "row" ||
9-
direction === "row-reverse"
10-
) {
5+
if (equals(direction, ["column", "column-reverse", "row", "row-reverse"])) {
116
return css`
12-
flex-direction: ${direction} !important;
7+
flex-direction: ${direction + ""} !important;
138
`;
149
} else {
1510
return "";

src/row/renderJustifyContent.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import RowJustifyContent from "./RowJustifyContent";
2-
import { css } from "../utils";
2+
import { css, equals } from "../utils";
33

44
export default (contentJustify?: RowJustifyContent): string => {
55
if (
6-
contentJustify === "center" ||
7-
contentJustify === "flex-end" ||
8-
contentJustify === "flex-start" ||
9-
contentJustify === "space-around" ||
10-
contentJustify === "space-between"
6+
equals(contentJustify, [
7+
"center",
8+
"flex-end",
9+
"flex-start",
10+
"space-around",
11+
"space-between"
12+
])
1113
) {
1214
return css`
13-
justify-content: ${contentJustify} !important;
15+
justify-content: ${contentJustify + ""} !important;
1416
`;
1517
} else {
1618
return "";

src/row/renderWrap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import RowWrap from "./RowWrap";
2-
import { css } from "../utils";
2+
import { css, equals } from "../utils";
33

44
function renderWrap(wrap?: RowWrap): string {
55
if (wrap == null) {
66
return renderWrap("wrap");
77
}
88

9-
if (wrap === "nowrap" || wrap === "wrap" || wrap === "wrap-reverse") {
9+
if (equals(wrap, ["nowrap", "wrap", "wrap-reverse"])) {
1010
return css`
1111
flex-wrap: ${wrap};
1212
`;

src/utils/__snapshots__/index.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ exports[`index should verify the API shape 1`] = `
44
Object {
55
"RenderProvider": Object {},
66
"css": [Function],
7+
"equals": [Function],
78
"flatten": [Function],
89
"map": [Function],
910
"percentage": [Function],

src/utils/equals.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import equals from "./equals";
2+
3+
describe("equals", () => {
4+
it("should return true", () => {
5+
// arrange
6+
const a = "test-b";
7+
const b = ["test-a", "Test-b", "test-b"];
8+
9+
// act
10+
const output = equals(a, b);
11+
12+
// assert
13+
expect(output).toBeTruthy();
14+
});
15+
16+
it("should return false", () => {
17+
// arrange
18+
const a = "test-b";
19+
const b = ["test-a", "Test-b", "test-B"];
20+
21+
// act
22+
const output = equals(a, b);
23+
24+
// assert
25+
expect(output).toBeFalsy();
26+
});
27+
28+
it("should return false if array is empty", () => {
29+
// arrange
30+
const a = "test-b";
31+
const b = [];
32+
33+
// act
34+
const output = equals(a, b);
35+
36+
// assert
37+
expect(output).toBeFalsy();
38+
});
39+
40+
it("should return false if undefined", () => {
41+
// arrange
42+
const a = undefined;
43+
const b = ["test-a", "Test-b", "test-B"];
44+
45+
// act
46+
const output = equals(a, b);
47+
48+
// assert
49+
expect(output).toBeFalsy();
50+
});
51+
});

src/utils/equals.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default (a: string | undefined, b: string[]) => {
2+
return a != null && b.indexOf(a) > -1;
3+
};

src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export { default as css } from "./css";
2+
export { default as equals } from "./equals";
23
export { default as flatten } from "./flatten";
34
export { default as map } from "./map";
45
export { default as percentage } from "./percentage";

0 commit comments

Comments
 (0)