Skip to content

Commit 40f1708

Browse files
committed
refactor: replace lodash deps with native js implementation
1 parent 572db16 commit 40f1708

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

package-lock.json

-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@
135135
"js-yaml": "latest",
136136
"json-schema-to-typescript": "^13.1.2",
137137
"lint-staged": "latest",
138-
"lodash.camelcase": "^4.3.0",
139-
"lodash.set": "^4.3.2",
140138
"prettier": "^2.8.8",
141139
"typescript": "~5.5.2"
142140
},

src/__mocks__/thing1.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import camelCase from 'lodash.camelcase'
2-
3-
import { getBar } from './thing2'
1+
import { camelCase, getBar } from './thing2'
42

53
export function getFoo(msg: string): string {
64
return camelCase(msg) + getBar(msg)

src/__mocks__/thing2.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import camelCase from 'lodash.camelcase'
2-
31
export function getBar(msg: string): string {
42
return camelCase(msg) + 'foo'
53
}
4+
5+
export function camelCase(str: string): string {
6+
return str.replace(/[-_\s]+(.)?/g, (_, chr) => (chr ? chr.toUpperCase() : ''))
7+
}

src/utils/backports.spec.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
import { inspect } from 'util'
22

33
import { testing } from 'bs-logger'
4-
import set from 'lodash.set'
54

65
import { backportJestConfig } from './backports'
76

87
const logger = testing.createLoggerMock()
98
const logTarget = logger.target
109

10+
function set<T>(obj: T, path: string | string[], value: unknown): T {
11+
if (!path) return obj
12+
13+
if (!Array.isArray(path)) {
14+
path = path.toString().match(/[^.[\]]+/g) || []
15+
}
16+
17+
path.reduce((acc, key, index) => {
18+
if (index === path.length - 1) {
19+
acc[key] = value
20+
} else if (!acc[key]) {
21+
acc[key] = {}
22+
}
23+
24+
return acc[key]
25+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
26+
}, obj as Record<string, any>)
27+
28+
return obj
29+
}
30+
1131
beforeEach(() => {
1232
logTarget.clear()
1333
})

0 commit comments

Comments
 (0)