Skip to content

Commit ae9a50f

Browse files
committed
remove lodash
1 parent fbe488e commit ae9a50f

File tree

17 files changed

+158
-44
lines changed

17 files changed

+158
-44
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
},
2020
"dependencies": {
2121
"axios": "^1.6.1",
22-
"form-data": "^4.0.0",
23-
"lodash": "^4.17.21"
22+
"form-data": "^4.0.0"
2423
},
2524
"devDependencies": {
2625
"@babel/preset-env": "^7.23.3",
@@ -40,6 +39,7 @@
4039
"eslint-plugin-standard": "^5.0.0",
4140
"husky": "^8.0.3",
4241
"jest": "^29.7.0",
42+
"lodash": "^4.17.21",
4343
"nock": "^13.3.8",
4444
"prettier": "^3.0.3",
4545
"rimraf": "^5.0.5",

src/helpers/camelCase/index.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { camelCase } from '.';
2+
3+
describe('camelCase', () => {
4+
it.each([
5+
['abc-def', 'abcDef'],
6+
['abcdef', 'abcdef'],
7+
['abcDef', 'abcDef'],
8+
['AbcDef', 'abcDef'],
9+
['abc def', 'abcDef'],
10+
['abc_def', 'abcDef'],
11+
['__abc-def_ghi--', 'abcDefGhi'],
12+
])('should convert %s to %s', (value, expectedString) => {
13+
expect(camelCase(value)).toEqual(expectedString);
14+
});
15+
});

src/helpers/camelCase/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const camelCase = (value: string): string => {
2+
const a = value.replace(/[-_\s.]+(.)?/g, (_, c) =>
3+
c ? c.toUpperCase() : '',
4+
);
5+
return a.substring(0, 1).toLowerCase() + a.substring(1);
6+
};

src/helpers/isObject/index.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { isObject } from '.';
2+
3+
describe('isObject', () => {
4+
it.each([{}, new Date(), [1], new Object()])(
5+
'should true for %o',
6+
(value) => {
7+
expect(isObject(value)).toBe(true);
8+
},
9+
);
10+
11+
it.each([null, 'abc', 1])('should false for %o', (value) => {
12+
expect(isObject(value)).toBe(false);
13+
});
14+
});

src/helpers/isObject/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const isObject = (value: unknown): value is object => {
2+
return value !== null && typeof value === 'object';
3+
};

src/helpers/mapKeys/index.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { mapKeys } from '.';
2+
3+
describe('mapKeys', () => {
4+
it('should transform keys', () => {
5+
const obj = {
6+
a: 1,
7+
b: 2,
8+
};
9+
10+
expect(mapKeys(obj, (key) => key.toUpperCase())).toEqual({
11+
A: 1,
12+
B: 2,
13+
});
14+
});
15+
});

src/helpers/mapKeys/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { isObject } from '../isObject';
2+
3+
export const mapKeys = (
4+
value: Record<string, unknown>,
5+
callback: (key: string) => string,
6+
): Record<string, string | boolean | number> => {
7+
if (value === undefined || !isObject(value)) {
8+
return value;
9+
}
10+
11+
const result = {};
12+
13+
Object.entries(value).forEach(([key, value]) => {
14+
result[callback(key)] = value;
15+
});
16+
17+
return result;
18+
};

src/helpers/mapValues/index.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { mapValues } from '.';
2+
3+
describe('mapValues', () => {
4+
it('should transform values', () => {
5+
const obj = {
6+
a: 'a',
7+
b: 'b',
8+
};
9+
10+
expect(mapValues(obj, (value) => value.toUpperCase())).toEqual({
11+
a: 'A',
12+
b: 'B',
13+
});
14+
});
15+
});

src/helpers/mapValues/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
import { isObject } from '../isObject';
3+
4+
export const mapValues = (
5+
value: Record<string, unknown>,
6+
callback: (value: any, key: string) => any,
7+
): Record<string, any> => {
8+
if (value === undefined || !isObject(value)) {
9+
return value;
10+
}
11+
12+
const result = {};
13+
14+
Object.entries(value).forEach(([key, value]) => {
15+
result[key] = callback(value, key);
16+
});
17+
18+
return result;
19+
};

src/helpers/snakeCase/index.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { snakeCase } from '.';
2+
3+
describe('snakeCase', () => {
4+
it.each([
5+
['abc-def', 'abc_def'],
6+
['abcdef', 'abcdef'],
7+
['abcDef', 'abc_def'],
8+
['AbcDef', 'abc_def'],
9+
['abc def', 'abc_def'],
10+
['abc_def', 'abc_def'],
11+
['__abc-def_ghi--', 'abc_def_ghi'],
12+
['__Abc-def_ghi__', 'abc_def_ghi'],
13+
])('should convert %s to %s', (value, expectedString) => {
14+
expect(snakeCase(value)).toEqual(expectedString);
15+
});
16+
});

0 commit comments

Comments
 (0)