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
Minimize lodash dependency #7747
Comments
@exoego great thanks for putting that into issue. I've updated description with list of all functions which I believe we can replace. I think best if each is handled with separate PR's, so we process it in small steps (change touches sensitive parts, so we need to be careful) I've also added |
Some news about lodash. There's a security issue noted in this issue: https://github.com/lodash/lodash/issues/4738 The current version fails 3rd party security scans. |
@medikoo |
@chrisVillanueva if you mean a language level utilities, then I think we should not introduce any here, but instead rely of utility library of choice. Currently we rely on lodash, and problem is that we overuse it for cases which should rather be handled with native API, and this issue is purely about that. We may at some point consider replacing lodash completely, but I think then it should replaced with other utility library. We definitely should not attempt to build and maintain lang utilities in scope of this project. |
Thanks for clarification. This simplifies the issue. |
Looks like Also if you've got a build tool like TS or Babel, you could use optional chaining to replace most of the |
@G-Rath thanks for pointing. Updated description
Once support for Node.js v12 is dropped we will simply move to native syntax. We do not plan to introduce any transpilation step into this package, as it comes with significant maintenance cost |
I'd like to work on:
If that would be okay. It looks like it's still up for grabs. |
Sure thing, that would be awesome @pjmattingly 👍 |
I've added also |
Next, on to: PR: #11272 |
Next, Edit: did my best! #11273 |
Then, the last one: |
hi @medikoo what about the case with |
@duytrandev I'd welcome PR that switches to |
Use case description
#7680 (comment)
lodash
offers lots of utility, but nowadays we only need the small parts oflodash
, since recent Node.js supports native convenient counterpart (e.g.Array#forEach(f)
over_.forEach(array, f)
).Minimizing
lodash
dependency will achieveProposed solution
lodash
, e.g.lodash-memoize
and so on.Note: Ideally if we handle all below cases, and each is addressed with separate PR
_.assign
withObject.assign
(Addressed with Replace _.assign and _.extend with Object.assign #7766)_.chain
to flow constructed with native functions (Addressed with Replace lodash chain with native array chain #7862)_.compact
witharray.filter(Boolean)
(Addressed with replaced lodash compact with array.filter(Boolean) #7858)_.concat
witharray.concat
(Addressed with Replace _.concat with array.concat #7851)_.each(Array)
witharray.forEach
for array cases (Addressed with Replace lodash forEach(array) with native Array.forEach #7748)_.each(object)
withObject.entries(object).forEach
(Renamed to_.forEach
with Replace lodash forEach(array) with native Array.forEach #7748 and addressed with chore: replace _.forEach with Object.entries().forEach #8280)_.entries
withObject.entries
(Addressed with chore: replace _.entries, _.entriesIn and _.toPairs with Object.entries #8275)_.entriesIn
withObject.entries
, note both are not equivalent, we need to confirm that conversion is safe (Addressed with chore: replace _.entries, _.entriesIn and _.toPairs with Object.entries #8275)_.every
witharray.every
(Addressed with Replace lodash _.every(array) with native Array.every #7764)_.extend
withObject.assign
Note they're not equivalent, but most likelyObject.assign
can be used safely in most of the cases (Addressed with Replace _.assign and _.extend with Object.assign #7766)_.filter
witharray.filter
(Addressed with refactor(lodash): Replace _.filter with array.filter #7775)_.find
witharray.find
(Addressed with Replace lodash _.find with native Array.find #7782)_.findKey
withObject.keys(object).find
(Addressed with Replace _.findKey with Object.keys(object).find #7881)_.first
witharray[0]
(Addressed with Replace lodash _.first with native array[0] #7816)_.flat
witharray.flat
(Addressed with refactor: Replace_.flatten
withArray.prototype.flat
#11271)_.flatMap
witharray.flatMap
(Addressed with refactor: Replace_.flatMap
withArray.prototype.flatMap
#11272)_.forEach(Array)
witharray.forEach
for array cases (Addressed with Replace lodash forEach(array) with native Array.forEach #7748)_.forEach(object)
withObject.entries(object).forEach
(Addressed with chore: replace _.forEach with Object.entries().forEach #8280)_.forOwn
withObject.entries().forEach
(Addressed with chore: replace _.forOwn with Object.entries().forEach #8284)_.get
with normalobj.prop
checks, but only in top level property checks or where given property path is ensured to exist_.has
with normalobj.prop
checks, in top level property checks, or where we're safe fromUndefined is not an object
errors (Addressed with Replaced _.has(object, property) with object.property #7915)_.head
witharray[0]
(Addressed with Replace lodash _.head with array[0] #7817)_.includes
with eitherstring.includes
orarray.includes
(Addressed with Replace lodash _.includes with native includes #7818)_.indexOf
with eitherstring.includes
,array.includes
orstring.indexOf
,array.indexOf
(Addressed with Replace _.indexOf with native includes #7825)_.isBoolean
, we should just check whether value is truthy or falsy, no need to confirm on boolean type (Addressed with Remove is boolean #7880)_.isEmpty
witharray.length
(Addressed with replace _.isEmpty with array.length and Object.keys() #7873)_.isInteger
, in most cases it's used validation is superfluous (so this check can be removed entirely) (Addressed with Remove _.isInteger #7878)_.isFunction
withtypeof value === 'function'
(Addressed with refactor: Replace_.isFunction(value)
withtypeof value === 'function'
#7810)_.isNil
withvalue == null
(Addressed with refactor: Replace_.isNil(value)
withvalue == null
#7809)_.isString
withtypeof value === 'string'
(Addressed with refactor: Replace_.isString(value)
withtypeof value === 'string'
#7812)_.isUndefined
withvalue == null
(Addressed with Replace _.isUndefined with native undefined check #7826)_.join
witharray.join
(Addressed with Replace lodash _.join with native array.join #7805)_.keyBy(collection)
with simple set collection (Addressed with Replace _.keyBy with array.reduce #7882)_.keys
withObject.keys
(Addressed with Replace lodash _.keys with native Object.keys #7784)_.map
witharray.map
(Addressed with Replace _.map with array.map #7827)_merge
withObject.assign
. Note they're not equivalent (_.merge
does deep merge), so it should be done with care in all places where it's safe to rely onObject.assign
instead (majority of cases)_.min
withMath.min(...array)
(Addressed with Replace _.min with Math.min #7840)_.nth
witharr[index]
(Addressed with Replace _.nth with array[index] #7841)_.parseInt
withNumber
(Addressed with Replace _.parseInt with Number #7877)_.pullAllWith
witharray.filter
(Addressed with Replaced lodash pullAllWith with Array.filter() #7861)_.reduce
witharray.reduce
(in this case I'd also investigate ifreduce
is right pattern used) (Addressed with Replace _.reduce with array.reduce #7883)_.repeat
withstring.repeat
(Addressed with Replace _.repeat with string.repeat #7842)_.replace
withstring.replace
(Addressed with Replace _.replace with string.replace #7843)_.set
with normalobj.prop = value
assignments, but only in top level property checks or where given property path is ensured to exist_.size
witharray.length
check on arrays and `Object.keys(object).length on objects (Addressed with Replace lodash _.size with native array length & object.keys length #7798)_.some
witharray.some
(Addressed with chore: reduce _.some usage #7901)_.sortBy
witharray.sort
(Addressed with Replace _.sortBy with array.sort #7823)_.split
withstring.split
(Addressed with Replace _.split with string.split #7820)_.takeRight
witharray.slice
(Addressed with refactor: Replace_.takeRight
witharray.slice
#7831)_.toPairs
withObject.entries
(Addressed with chore: replace _.entries, _.entriesIn and _.toPairs with Object.entries #8275)_.toString
withString(value)
Note: behavior is not equivalent fornull
andundefined
. We need to be sure to handle cases properly (Addressed with Replace toString #7893)_.toUpper
withstring.toUpper
(Addressed with refactor: Replace _.toUpper(string) with string.toUpperCase #7808)_.unset
withdelete obj.prop
(Addressed with Replace lodash unset with native delete objectProp #7813)_.values
withObject.values
(Addressed with chore: replace usage of _.values with Object.values #8274)The text was updated successfully, but these errors were encountered: