Skip to content

Commit 28d5268

Browse files
authored
Feature Utilities class to migrate from prototype implementation (#9)
Feature `Utilities class` to migrate from prototype implementation
2 parents 5aed504 + b361fa1 commit 28d5268

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/lib/categoriesHandlers.class.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
2-
Array.prototype.isEmpty = (arr) => {
3-
return (arr === undefined || arr.length === 0) ? false : true
4-
}
1+
import Utility from './utilities.class.js'
52

63
class Categories {
74
getCategoriesFlags = array => {
@@ -17,7 +14,7 @@ class Categories {
1714
}
1815

1916
getCategoriesFromCategoriesFlags = array => {
20-
return (!Array.isEmpty(array)) ? array : undefined
17+
return (!Utility.isEmpty(array)) ? array : undefined
2118
}
2219
}
2320

src/lib/utilities.class.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Utility {
2+
isEmpty = data => {
3+
let result;
4+
if (typeof data === 'array') result = this.#isArrayEmpty(data)
5+
if (typeof data === 'object') result = this.#isObjEmpty(data)
6+
7+
return result
8+
}
9+
10+
#isArrayEmpty = (data = []) => {
11+
return (data === undefined || data.length === 0) ? false : true
12+
}
13+
14+
#isObjEmpty = (data = {}) => {
15+
for (const prop in data)
16+
if (Object.hasOwn(data, prop)) return false
17+
return true
18+
}
19+
}
20+
21+
export default new Utility()

0 commit comments

Comments
 (0)