Skip to content

Commit da03618

Browse files
got rid of babel/preset-react since react is not used in package
1 parent ea33626 commit da03618

File tree

15 files changed

+124
-6
lines changed

15 files changed

+124
-6
lines changed

.yarn/versions/2bcae1f2.yml

Whitespace-only changes.

package.json

Lines changed: 3 additions & 5 deletions
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.20",
4+
"version": "0.0.22",
55
"browser": "dist/umd/index.js",
66
"main": "dist/cjs/index.js",
77
"types": "typings/index.d.ts",
@@ -78,15 +78,13 @@
7878
"eslint-plugin-unused-imports": "^3.0.0",
7979
"jest": "^29.7.0",
8080
"jest-environment-jsdom": "^29.7.0",
81+
"jsdom-global": "^3.0.2",
8182
"picocolors": "^1.0.0",
8283
"prettier": "^3.0.3",
8384
"rollup": "^3.29.1",
8485
"rollup-plugin-peer-deps-external": "^2.2.4",
8586
"rollup-plugin-polyfill-node": "^0.13.0",
8687
"rollup-plugin-terser": "^7.0.2",
87-
"tslib": "^2.6.2",
88-
"jsdom-global": "^3.0.2"
89-
88+
"tslib": "^2.6.2"
9089
}
91-
9290
}

rollup.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ export default {
8282
babelHelpers: "bundled",
8383
presets: [
8484
"@babel/preset-env",
85-
"@babel/preset-react",
8685
"@babel/preset-typescript",
8786
],
8887
}),

src/__tests__/isEmpty.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { isEmpty } from "../isEmpty";
2+
3+
describe("isEmpty", () => {
4+
it("should return true for undefined", () => {
5+
const value = undefined;
6+
const result = isEmpty(value);
7+
expect(result).toBe(true);
8+
});
9+
10+
it("should return true for null", () => {
11+
const value = null;
12+
const result = isEmpty(value);
13+
expect(result).toBe(true);
14+
});
15+
16+
it("should return true for an empty object", () => {
17+
const value = {};
18+
const result = isEmpty(value);
19+
expect(result).toBe(true);
20+
});
21+
22+
it("should return true for an empty string", () => {
23+
const value = "";
24+
const result = isEmpty(value);
25+
expect(result).toBe(true);
26+
});
27+
28+
it("should return false for a non-empty object", () => {
29+
const value = { name: "John", age: 30 };
30+
const result = isEmpty(value);
31+
expect(result).toBe(false);
32+
});
33+
34+
it("should return false for a non-empty string", () => {
35+
const value = "Hello, world!";
36+
const result = isEmpty(value);
37+
expect(result).toBe(false);
38+
});
39+
});

src/__tests__/pluralize.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { pluralize } from "../pluralize";
2+
3+
describe("pluralize", () => {
4+
it("should return singular when count is 1", () => {
5+
const count = 1;
6+
const singular = "apple";
7+
const plural = "apples";
8+
const result = pluralize(count, singular, plural);
9+
expect(result).toBe(singular);
10+
});
11+
12+
it("should return plural when count is not 1", () => {
13+
const count = 5;
14+
const singular = "apple";
15+
const plural = "apples";
16+
const result = pluralize(count, singular, plural);
17+
expect(result).toBe(plural);
18+
});
19+
});

src/getUniqueObjects.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
/**
3+
* Returns an array of unique elements from the input array based on the specified property.
4+
* @param array The input array.
5+
* @param property The property to compare for uniqueness.
6+
* @returns An array of unique elements.
7+
*/
8+
export const getUniqueObjects = (
9+
array: Array<any>,
10+
property: string,
11+
): any[] => {
12+
const uniqueElements = array
13+
.map((element) => element[property])
14+
.filter(
15+
(element, index, finalArray) => finalArray.indexOf(element) === index,
16+
)
17+
.map((element, index) => array[index]);
18+
19+
return uniqueElements;
20+
};

src/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export * from "./dashToCamelCase";
1818
* TSDoc for getRange
1919
*/
2020
export * from "./getRange";
21+
/**
22+
* TSDoc for getUniqueObjects
23+
*/
24+
export * from "./getUniqueObjects";
2125
/**
2226
* TSDoc for hasItemByLetterAndFilter
2327
*/
@@ -26,6 +30,10 @@ export * from "./hasItemByLetterAndFilter";
2630
* TSDoc for isDeepEqual
2731
*/
2832
export * from "./isDeepEqual";
33+
/**
34+
* TSDoc for isEmpty
35+
*/
36+
export * from "./isEmpty";
2937
/**
3038
* TSDoc for isJson
3139
*/
@@ -42,6 +50,10 @@ export * from "./logFormattedPhrases";
4250
* TSDoc for mergeObjects
4351
*/
4452
export * from "./mergeObjects";
53+
/**
54+
* TSDoc for pluralize
55+
*/
56+
export * from "./pluralize";
4557
/**
4658
* TSDoc for removeNewLinesFromJson
4759
*/

src/isEmpty.ts

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

src/pluralize.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const pluralize = (count: number, singular: string, plural: string) => {
2+
return count === 1 ? singular : plural;
3+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

0 commit comments

Comments
 (0)