Skip to content

Commit 32741e3

Browse files
added getAspectRatio
1 parent 988a5bc commit 32741e3

File tree

76 files changed

+982
-620
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+982
-620
lines changed

.yarn/versions/da4f1b16.yml

Whitespace-only changes.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@devlander/utils",
33
"description": "Utils shared between projects that are plain javascript",
4-
"version": "0.0.26",
4+
"version": "0.0.27",
55
"browser": "dist/umd/index.js",
66
"main": "dist/cjs/index.js",
77
"types": "typings/index.d.ts",
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { GetAspectRatioParams, getAspectRatio } from '../getAspectRatio';
2+
3+
describe('getAspectRatio', () => {
4+
it('should calculate the correct height for landscape orientation', () => {
5+
const params: GetAspectRatioParams = {
6+
width: 1920,
7+
orientation: 'landscape',
8+
aspectRatio: '16:9',
9+
};
10+
11+
const result = getAspectRatio(params);
12+
13+
expect(result.width).toBe(1920);
14+
expect(result.height).toBe(1080);
15+
});
16+
17+
it('should calculate the correct height for portrait orientation', () => {
18+
const params: GetAspectRatioParams = {
19+
width: 1080,
20+
orientation: 'portrait',
21+
aspectRatio: '16:9',
22+
};
23+
24+
const result = getAspectRatio(params);
25+
26+
expect(result.width).toBe(1080);
27+
expect(result.height).toBe(608);
28+
});
29+
30+
});

src/__tests__/getRandomValFromArray.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ describe("getRandomValFromArray", () => {
2727

2828
expect(result).toBe(fallbackValue);
2929
});
30-
});
30+
});

src/__tests__/hslToRgb.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ describe("hslToRgb", () => {
2828

2929
// Add more test cases as needed
3030
});
31-
});
31+
});

src/__tests__/isPlainObject.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ describe("isPlainObject", () => {
4848

4949
expect(result).toBe(false);
5050
});
51-
});
51+
});

src/__tests__/isValidHex.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ describe("isValidHex", () => {
1515
});
1616

1717
it("should return false for non-string input", () => {
18-
expect(isValidHex(null)).toBe(false);
19-
expect(isValidHex(undefined)).toBe(false);
20-
expect(isValidHex(123)).toBe(false);
21-
expect(isValidHex({})).toBe(false);
22-
expect(isValidHex([])).toBe(false);
18+
expect(isValidHex(null as any)).toBe(false);
19+
expect(isValidHex(undefined as any)).toBe(false);
20+
expect(isValidHex(123 as any)).toBe(false);
21+
expect(isValidHex({} as any)).toBe(false);
22+
expect(isValidHex([] as any)).toBe(false);
2323
});
24-
});
24+
});
Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
11
import { applyFormatters } from "../../logFormattedPhrases/applyFormatters";
2-
import { PhraseItem, PhraseOrderType } from "../../logFormattedPhrases/formattedPhrase.types";
2+
import {
3+
PhraseItem,
4+
PhraseOrderType,
5+
} from "../../logFormattedPhrases/formattedPhrase.types";
36
import { defaultPhraseOrder } from "../../logFormattedPhrases/getPhraseStylesFromOrder";
47

5-
68
describe("applyFormatters", () => {
79
it("Expect apply formatters to return correct values", () => {
810
const phraseItem: PhraseItem = {
9-
background: "red", color: "blue",
10-
phrase: ""
11+
background: "red",
12+
color: "blue",
13+
phrase: "",
1114
};
12-
const orderItems:PhraseOrderType[] = defaultPhraseOrder
15+
const orderItems: PhraseOrderType[] = defaultPhraseOrder;
1316

1417
const result = applyFormatters(phraseItem, orderItems);
1518

1619
// console.log(result, 'result in applyFormatters test');
1720

18-
const hasBlueForColor = result.some((formatter) => formatter.value === "blue" && formatter.name === "color");
21+
const hasBlueForColor = result.some(
22+
(formatter) => formatter.value === "blue" && formatter.name === "color",
23+
);
1924

20-
const hasRedValueForBackground = result.some((formatter) => formatter.value === "red" && formatter.name === "background");
25+
const hasRedValueForBackground = result.some(
26+
(formatter) =>
27+
formatter.value === "red" && formatter.name === "background",
28+
);
2129
expect(hasRedValueForBackground).toBe(true);
2230
expect(hasBlueForColor).toBe(true);
2331
});
24-
25-
});
32+
});
Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
2-
import { formatPhrase } from '../../logFormattedPhrases/formatPhrase';
3-
import { PhraseItem } from '../../logFormattedPhrases/formattedPhrase.types';
4-
1+
import { formatPhrase } from "../../logFormattedPhrases/formatPhrase";
2+
import { PhraseItem } from "../../logFormattedPhrases/formattedPhrase.types";
53

64
describe("formatPhrase", () => {
75
it("should be able to log with just text", () => {
@@ -11,34 +9,28 @@ describe("formatPhrase", () => {
119

1210
const expectedFormattedPhrase = "Hello, world!"; // Update this with the expected formatted phrase
1311

14-
15-
1612
// Call the formatPhrase function
17-
const result = formatPhrase(item);
18-
if(result) {
19-
expect(result.message).toBe(expectedFormattedPhrase);
13+
const result = formatPhrase(item);
14+
if (result) {
15+
expect(result.message).toBe(expectedFormattedPhrase);
2016
}
2117
});
2218

2319
it("it should work with color and background", () => {
2420
const item: PhraseItem = {
2521
phrase: "Hello, world!",
2622
color: "blue",
27-
background: "red"
23+
background: "red",
2824
};
2925

30-
31-
32-
3326
// Call the formatPhrase function
34-
const result = formatPhrase(item);
27+
const result = formatPhrase(item);
3528

36-
console.log(result, 'result in formatPhrase test');
37-
38-
if(result) {
29+
console.log(result, "result in formatPhrase test");
30+
31+
if (result) {
3932
expect(result.formattersApplied.includes("color")).toBe(true);
4033
expect(result.formattersApplied.includes("background")).toBe(true);
41-
4234
}
4335
});
44-
});
36+
});

src/__tests__/logFormattedPhrases/getPhraseStylesFromOrder.test.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22
// referenced in conversations about the code.
33
// Path: ./src/__tests__/logFormattedPhrases/getPhraseStylesFromOrder.test.ts
44

5-
import { AppliedFormatter, PhraseItem } from "../../logFormattedPhrases/formattedPhrase.types";
5+
import {
6+
AppliedFormatter,
7+
PhraseItem,
8+
} from "../../logFormattedPhrases/formattedPhrase.types";
69
import { getPhraseStylesFromOrder } from "../../logFormattedPhrases/getPhraseStylesFromOrder";
710

8-
const hasValueInFormatters = (formatters: AppliedFormatter[], property: string) => {
11+
const hasValueInFormatters = (
12+
formatters: AppliedFormatter[],
13+
property: string,
14+
) => {
915
return formatters.some((formatter) => formatter.name === property);
10-
}
16+
};
1117

1218
describe("getPhraseStylesFromOrder", () => {
13-
14-
1519
// it("should return an empty array when item.orderToApplyStyles is empty", () => {
1620
// const item: PhraseItem = {
1721
// orderToApplyStyles: [],
@@ -22,7 +26,7 @@ describe("getPhraseStylesFromOrder", () => {
2226
// });
2327

2428
// it("should return an empty array when item.orderToApplyStyles is not an array", () => {
25-
29+
2630
// const item: PhraseItem = {
2731
// orderToApplyStyles: "invalid" as any,
2832
// phrase: ""
@@ -43,10 +47,8 @@ describe("getPhraseStylesFromOrder", () => {
4347
],
4448
};
4549
const result: AppliedFormatter[] = getPhraseStylesFromOrder(item);
46-
expect(result).toBeDefined();
47-
50+
expect(result).toBeDefined();
4851
});
4952

5053
// Add more test cases for different scenarios
51-
52-
});
54+
});

0 commit comments

Comments
 (0)