Skip to content

Remove lodash dependency#743

Merged
acasazza merged 1 commit intov5.0.0from
v5/remove-lodash
Apr 10, 2026
Merged

Remove lodash dependency#743
acasazza merged 1 commit intov5.0.0from
v5/remove-lodash

Conversation

@acasazza
Copy link
Copy Markdown
Member

@acasazza acasazza commented Apr 9, 2026

Summary

Removes lodash and @types/lodash entirely, replacing all usages with native JS/TS equivalents.

Closes #742

Changes

New utility

  • src/utils/isEmpty.ts — replaces lodash/isEmpty across 18+ files (handles null/undefined, strings, arrays, objects, Map/Set)

Lodash functions replaced

Function Native replacement
isEmpty #utils/isEmpty
isFunction typeof fn === 'function'
camelCase str.replace(/_([a-z])/g, ...)
capitalize Inline helper
compact .filter(Boolean)
differenceBy Set-based filter
first arr[0]
get Optional chaining
has Object.hasOwn
isArray Array.isArray
isString typeof val === 'string'
keys Object.keys
last .at(-1)
map (obj/array-like) Object.entries().map / Array.from().forEach

Type improvements (uncovered by removing lodash's any-based guards)

  • label prop in SubmitButton, PlaceOrderButton, SaveAddressesButton now correctly typed as string | ReactNode | (() => ReactNode)
  • infoMessage.text in PaypalPayment similarly updated

Testing

  • ✅ Build passes (tsup)
  • ✅ All 46 unit tests pass

Replace all lodash imports with native JS/TS equivalents:
- isEmpty → local #utils/isEmpty utility
- isFunction → typeof fn === 'function'
- camelCase → String.replace with regex
- capitalize → inline helper
- compact → Array.filter(Boolean)
- differenceBy → Set-based filter
- first → arr[0]
- get → optional chaining with type cast
- has → Object.hasOwn
- isArray → Array.isArray
- isString → typeof val === 'string'
- keys → Object.keys
- last → Array.at(-1)
- map (object) → Object.entries().map
- map (array-like) → Array.from().forEach
- without → Array.filter with exclusion list

Also improve related types:
- label prop now correctly typed as string | ReactNode | (() => ReactNode)
  in SubmitButton, PlaceOrderButton, SaveAddressesButton
- infoMessage.text in PaypalPayment similarly updated

Closes #742
@acasazza acasazza mentioned this pull request Apr 10, 2026
4 tasks
@acasazza acasazza linked an issue Apr 10, 2026 that may be closed by this pull request
4 tasks
@acasazza acasazza merged commit e25391e into v5.0.0 Apr 10, 2026
2 checks passed
@acasazza acasazza deleted the v5/remove-lodash branch April 10, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove lodash dependency

1 participant