Skip to content

remove some lodash calls #3950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

remove some lodash calls #3950

wants to merge 14 commits into from

Conversation

dynst
Copy link

@dynst dynst commented Jun 30, 2025

#3949

Excluding isString, isUndefined, isObject, and things like that (which don't have to be removed, if lodash can be replaced with var _ = require('is-what')), there are fewer than 50 lines using lodash in the library code after this PR. (There's much more than that in the tests.)

dynst added 4 commits June 30, 2025 18:33
find packages/ -type f \( -name "*.js" \) -exec sed -i -E \
  -e 's/_.includes\(([^,]+),[[:space:]]*([^)]+)\)/\1.includes(\2)/g' {} +
find packages/ -type f -name '*.js' -exec sed -i -E \
  -e 's/_\.takeRight\(([^,]+), ([0-9])\)/\1.slice(-\2)/g' {} +
find packages/ -type f -name '*.js' -exec sed -i -E \
  -e 's/_\.each\(([^,]+), function\(([^\)]*)\) \{/\1.forEach((\2) => {/g' {} +
find packages/ -type f -name '*.js' -exec sed -i -E \
  -e 's/_\.each\((\[[^]]+\]), function\(([^\)]*)\) \{/\1.forEach((\2) => {/g' {} +
@dynst dynst force-pushed the lodash-removal-1 branch from ccdc4b0 to f56ccaf Compare June 30, 2025 20:08
find packages/ -type f -exec sed -i -E \
  -e 's/_\.without\(([^,]+), ([^,\)]+)\)/\1.filter(x => x !== \2)/g' {} +
@dynst dynst force-pushed the lodash-removal-1 branch from c4a61e0 to ccdc4b0 Compare June 30, 2025 20:23
@dynst dynst force-pushed the lodash-removal-1 branch 5 times, most recently from 2bcf94b to 9b109ea Compare June 30, 2025 21:02
dynst added 3 commits June 30, 2025 21:05
find packages/ -type f -exec sed -i -E \
  -e 's/_\.every\(([^,]+), function\(([a-zA-Z]+)\) \{/\1.every(\2 => \{/g' {} +

find packages/ -type f -exec sed -i -E \
  -e 's/_\.every\(([^,]+), ([^,\)]+)\)/\1.every(\2)/g' {} +
@dynst dynst force-pushed the lodash-removal-1 branch from aa6cefe to 84d1497 Compare June 30, 2025 21:58
find packages/ -type f -exec sed -i -E \
  -e 's/_\.map\(([^,]+), function\(([^,\)]*)\) \{/\1.map(\2 => {/g' {} +

find packages/ -type f -exec sed -i -E \
  -e 's/_\.map\(([^,]+), function(\([^\)]*\)) \{/\1.map(\2 => {/g' {} +

find packages/ -type f -exec sed -i -E \
  -e 's/_[.]map\(([^,]+), ([a-zA-Z]+) => \{/\1.map(\2 => {/g' {} +

find packages/ -type f -exec sed -i -E \
  -e 's/_[.]map\(([^,]+), ([a-zA-Z]+ => [^\{])/\1.map(\2/g' {} +
@dynst dynst force-pushed the lodash-removal-1 branch from a1a733e to 9bcb338 Compare June 30, 2025 22:28
find packages/ -type f -exec sed -i -E \
  -e 's/_\.filter\(([^,]+), function\(([a-zA-Z]+)\) \{/\1.filter(\2 => \{/g' {} +

find packages/ -type f -exec sed -i -E \
  -e 's/_\.filter\(([^,]+), (.* => \{)/\1.filter(\2/g' {} +
@dynst dynst force-pushed the lodash-removal-1 branch from 509de91 to 1b440e7 Compare June 30, 2025 23:25
find packages/ -type f -exec sed -i -E \
  -e 's/!_\.isEmpty\(([a-zA-Z.]+)\)/\1.length !== 0/g' {} +
find packages/ -type f -exec sed -i -E \
  -e 's/_\.isEmpty\(([a-zA-Z.]+)\)/\1.length === 0/g' {} +
@dynst dynst force-pushed the lodash-removal-1 branch 2 times, most recently from 6a1c1ec to aca1d55 Compare July 1, 2025 00:18
@dynst dynst force-pushed the lodash-removal-1 branch 2 times, most recently from 6ba9604 to 50cc7bb Compare July 1, 2025 20:38
@kajoseph
Copy link
Collaborator

Thanks for the PR @dynst . Before I can merge anything, you'll need to resolve the merge conflict and sign all your commits per the contributing guidelines. Additionally, here are a few notes regarding the work:

  • We'd like to avoid .forEach and instead use for-of loops. .forEach loops are relatively slow and antiquated.
  • lodash typically handles non-iterable values cleanly (e.g. _.includes(null, 'someval') => false, _.each(null, ...) => null) whereas similar declarative calls (e.g. null.includes('someval')) will throw an error. This is worth considering in the codebase when null, undefined, or other non-iterable values may be acceptable.

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.

2 participants