Skip to content

Commit

Permalink
refactor: replace lodash deps with native js implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnpnl committed Jun 29, 2024
1 parent 572db16 commit 40f1708
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@
"js-yaml": "latest",
"json-schema-to-typescript": "^13.1.2",
"lint-staged": "latest",
"lodash.camelcase": "^4.3.0",
"lodash.set": "^4.3.2",
"prettier": "^2.8.8",
"typescript": "~5.5.2"
},
Expand Down
4 changes: 1 addition & 3 deletions src/__mocks__/thing1.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import camelCase from 'lodash.camelcase'

import { getBar } from './thing2'
import { camelCase, getBar } from './thing2'

export function getFoo(msg: string): string {
return camelCase(msg) + getBar(msg)
Expand Down
6 changes: 4 additions & 2 deletions src/__mocks__/thing2.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import camelCase from 'lodash.camelcase'

export function getBar(msg: string): string {
return camelCase(msg) + 'foo'
}

export function camelCase(str: string): string {
return str.replace(/[-_\s]+(.)?/g, (_, chr) => (chr ? chr.toUpperCase() : ''))
}
22 changes: 21 additions & 1 deletion src/utils/backports.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
import { inspect } from 'util'

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

import { backportJestConfig } from './backports'

const logger = testing.createLoggerMock()
const logTarget = logger.target

function set<T>(obj: T, path: string | string[], value: unknown): T {
if (!path) return obj

if (!Array.isArray(path)) {
path = path.toString().match(/[^.[\]]+/g) || []
}

path.reduce((acc, key, index) => {
if (index === path.length - 1) {
acc[key] = value
} else if (!acc[key]) {
acc[key] = {}
}

return acc[key]
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}, obj as Record<string, any>)

return obj
}

beforeEach(() => {
logTarget.clear()
})
Expand Down

0 comments on commit 40f1708

Please sign in to comment.