Skip to content

Commit 988a5bc

Browse files
gave isPlainObject a type
1 parent 1473ad2 commit 988a5bc

24 files changed

+242
-244
lines changed

src/abbreviateNumber.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,25 @@
44
* @returns The abbreviated number as a string.
55
*/
66
export const abbreviateNumber = (value: number): string | number => {
7-
let newValue: number | string = value;
7+
let newValue: number | string = value
88
if (value >= 1000) {
9-
const suffixes = ["", "k", "m", "b", "t"];
10-
const suffixNum = Math.floor(("" + value).length / 3);
11-
let shortValue: number | string = 0;
9+
const suffixes = ['', 'k', 'm', 'b', 't']
10+
const suffixNum = Math.floor(('' + value).length / 3)
11+
let shortValue: number | string = 0
1212
for (let precision = 2; precision >= 1; precision--) {
1313
shortValue = parseFloat(
1414
(suffixNum != 0
1515
? value / Math.pow(1000, suffixNum)
1616
: value
1717
).toPrecision(precision),
18-
);
19-
const dotLessShortValue = (shortValue + "").replace(
20-
/[^a-zA-Z 0-9]+/g,
21-
"",
22-
);
18+
)
19+
const dotLessShortValue = (shortValue + '').replace(/[^a-zA-Z 0-9]+/g, '')
2320
if (dotLessShortValue.length <= 2) {
24-
break;
21+
break
2522
}
2623
}
27-
if (shortValue % 1 != 0) shortValue = shortValue.toFixed(1);
28-
newValue = shortValue + suffixes[suffixNum];
24+
if (shortValue % 1 != 0) shortValue = shortValue.toFixed(1)
25+
newValue = shortValue + suffixes[suffixNum]
2926
}
30-
return newValue;
31-
};
27+
return newValue
28+
}

src/calculatePercentage.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
* @throws Error if either partial or whole is not a number, or if whole is zero.
88
*/
99
export function calculatePercentage(partial: number, whole: number) {
10-
if (typeof partial !== "number" || typeof whole !== "number" || whole === 0) {
11-
throw new Error("Both inputs must be numbers and 'whole' cannot be zero.");
10+
if (typeof partial !== 'number' || typeof whole !== 'number' || whole === 0) {
11+
throw new Error("Both inputs must be numbers and 'whole' cannot be zero.")
1212
}
1313

14-
const percentage = (partial / whole) * 100;
15-
return percentage;
14+
const percentage = (partial / whole) * 100
15+
return percentage
1616
}

src/convertVideoTimeStampToSeconds.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55
* @returns The number of seconds represented by the timestamp, or NaN if the timestamp is invalid.
66
*/
77
export function convertVideoTimeStampToSeconds(timestamp: string): number {
8-
const parts: string[] = timestamp.split(":");
8+
const parts: string[] = timestamp.split(':')
99

1010
if (parts.length !== 3) {
11-
throw new Error('Invalid timestamp format. Expected format: "HH:MM:SS"');
11+
throw new Error('Invalid timestamp format. Expected format: "HH:MM:SS"')
1212
}
1313

14-
const hours = parseInt(parts[0], 10);
15-
const minutes = parseInt(parts[1], 10);
16-
const seconds = parseInt(parts[2], 10);
14+
const hours = parseInt(parts[0], 10)
15+
const minutes = parseInt(parts[1], 10)
16+
const seconds = parseInt(parts[2], 10)
1717

1818
if (isNaN(hours) || isNaN(minutes) || isNaN(seconds)) {
19-
throw new Error('Invalid timestamp format. Expected format: "HH:MM:SS"');
19+
throw new Error('Invalid timestamp format. Expected format: "HH:MM:SS"')
2020
}
2121

2222
if (hours < 0 || minutes < 0 || seconds < 0) {
23-
throw new Error("Invalid timestamp. Negative values are not allowed.");
23+
throw new Error('Invalid timestamp. Negative values are not allowed.')
2424
}
2525

26-
return hours * 3600 + minutes * 60 + seconds;
26+
return hours * 3600 + minutes * 60 + seconds
2727
}

src/dashToCamelCase.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
*/
77
export function dashToCamelCase(dashName: string): string {
88
return dashName
9-
.replace(/^-+/, "")
10-
.replace(/-+$/, "")
9+
.replace(/^-+/, '')
10+
.replace(/-+$/, '')
1111
.toLowerCase()
1212
.replace(/-([a-z])/g, function (_match, group1) {
13-
return group1.toUpperCase();
14-
});
13+
return group1.toUpperCase()
14+
})
1515
}

src/ensureValidStyle.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ export const ensureValidStyle = (cssString: string): string => {
55
.replace(
66
/([a-z-]+)\s+([^;:]+)(;|$)/gi,
77
(match, property, value, ending) =>
8-
`${property}: ${value}${ending === ";" ? ";" : ""}`,
8+
`${property}: ${value}${ending === ';' ? ';' : ''}`,
99
)
1010
// Ensure semicolons at the end of each declaration
11-
.replace(/([^;])\s*$/gm, "$1;");
11+
.replace(/([^;])\s*$/gm, '$1;')
1212

13-
return fixedCSS;
14-
};
13+
return fixedCSS
14+
}

src/getRange.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
export const getRange = (start: number, count: number) => {
88
if (count < 0) {
9-
return [];
9+
return []
1010
}
11-
return Array.apply(0, Array(count)).map((_element, index) => index + start);
12-
};
11+
return Array.apply(0, Array(count)).map((_element, index) => index + start)
12+
}

src/getUniqueObjects.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const getUniqueObjects = (
1414
.filter(
1515
(element, index, finalArray) => finalArray.indexOf(element) === index,
1616
)
17-
.map((element, index) => array[index]);
17+
.map((element, index) => array[index])
1818

19-
return uniqueElements;
20-
};
19+
return uniqueElements
20+
}

src/hasItemByLetterAndFilter.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,46 @@
1313
export const hasItemByLetterAndFilter = (
1414
letter: string,
1515
array: Array<any>,
16-
key: string = "name",
16+
key: string = 'name',
1717
index?: number,
1818
filterText?: string,
1919
): boolean => {
2020
return array.some((item) => {
2121
if (letter.length !== 1) {
22-
throw new Error("Letter must be a single character.");
22+
throw new Error('Letter must be a single character.')
2323
}
24-
const keyValue: string | null = item[key] || null;
24+
const keyValue: string | null = item[key] || null
2525

2626
if (!keyValue) {
27-
return false;
27+
return false
2828
}
2929

3030
const checkForLetter = (keyValue: string, index = 0): boolean => {
31-
if (typeof index === "undefined") {
32-
index = 0;
31+
if (typeof index === 'undefined') {
32+
index = 0
3333
}
34-
const values = [keyValue, keyValue.toLowerCase()];
34+
const values = [keyValue, keyValue.toLowerCase()]
3535

36-
return values.some((value) => value.charAt(index) === letter);
37-
};
36+
return values.some((value) => value.charAt(index) === letter)
37+
}
3838

3939
const checkForFilterText = (keyValue: string): boolean => {
4040
if (!filterText) {
41-
return true;
41+
return true
4242
}
4343

44-
const filterTextValues = [filterText, filterText.toLowerCase()];
44+
const filterTextValues = [filterText, filterText.toLowerCase()]
4545

4646
return filterTextValues.every((filterTextValue) =>
4747
keyValue.includes(filterTextValue),
48-
);
49-
};
48+
)
49+
}
5050

51-
const hasFilterText = checkForFilterText(keyValue);
52-
const hasLetter = checkForLetter(keyValue, index);
51+
const hasFilterText = checkForFilterText(keyValue)
52+
const hasLetter = checkForLetter(keyValue, index)
5353

54-
const hasValue = hasFilterText && hasLetter ? true : false;
54+
const hasValue = hasFilterText && hasLetter ? true : false
5555

56-
return hasValue;
57-
});
58-
};
56+
return hasValue
57+
})
58+
}

src/isDeepEqual.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,30 @@ export function isDeepEqual(
1111
obj2: Record<string, any>,
1212
): boolean {
1313
if (obj1 === obj2) {
14-
return true;
14+
return true
1515
}
1616

1717
if (
18-
typeof obj1 !== "object" ||
18+
typeof obj1 !== 'object' ||
1919
obj1 === null ||
20-
typeof obj2 !== "object" ||
20+
typeof obj2 !== 'object' ||
2121
obj2 === null
2222
) {
23-
return false;
23+
return false
2424
}
2525

26-
const keys1 = Object.keys(obj1);
27-
const keys2 = Object.keys(obj2);
26+
const keys1 = Object.keys(obj1)
27+
const keys2 = Object.keys(obj2)
2828

2929
if (keys1.length !== keys2.length) {
30-
return false;
30+
return false
3131
}
3232

3333
for (const key of keys1) {
3434
if (!keys2.includes(key) || !isDeepEqual(obj1[key], obj2[key])) {
35-
return false;
35+
return false
3636
}
3737
}
3838

39-
return true;
39+
return true
4040
}

src/isEmpty.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const isEmpty = (value: unknown) =>
22
value === undefined ||
33
value === null ||
4-
(typeof value === "object" && Object.keys(value).length === 0) ||
5-
(typeof value === "string" && value.trim().length === 0);
4+
(typeof value === 'object' && Object.keys(value).length === 0) ||
5+
(typeof value === 'string' && value.trim().length === 0)

0 commit comments

Comments
 (0)