-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎉 Remove lodash from immutadot package (#143)
* 🔨 Remove lodash from fill * 🔨 Remove lodash from reverse * 🔨 Remove lodash from slice * 🔨 Remove lodash from concat * 🔨 Remove lodash from add * 🔨 Remove lodash from divide * 🔨 Remove lodash from multiply * 🔨 Remove lodash from subtract * 🔨 Remove lodash from replace * 🔨 Remove lodash from assign * 🚚 Move convertLodashFp in immutadot-lodash package * 🚧 Remove concat from ChainWrapper * 🚧 Remove omit from ChainWrapper * 🚧 Remove mapValues from ChainWrapper * 🚧 Remove flow from ChainWrapper * 🚧 Remove concat from protect * 🚧 Remove get from protect * 🚧 Remove isObject from protect * 🚧 Remove isEmpty from protect * 🚧 Remove map from using * 🚧 Remove head from using * 🚧 Remove concat from using * 🚧 Remove drop from using * 🚧 Remove get from using * 🚧 Remove mapValues from using * 🚧 Remove omit from using * 🚧 Remove isSymbol from using * 🐛 toPath: Return empty path for nil values * 🚧 Remove _.toPath from seq.ChainWrapper * ♻ Use module resolver for convertLodashFp imports * ♻ Manage non mutating methods in convertArrayMethod * ♻ toPath: Move nil arg concern from allowingArrays to stringToPath * 🚨 fix lint after rebase * 🔥 Remove util namespace from lodash plugin * 🔨 Remove concat from empty array when uneccessary * 🔨 Use isSymbol from util/lang * 🔨 Replace drop by Array.slice * ⏪ revert convertLodashFp deletion * 🚚 Rename convert.js to convertLodashFp.js * ➖ Remove lodash from immutadot package * ♻ Replace concat one element by destructuring * ♻ Inline flow in ChainWrapper * ♻ Replace omit by destructuring in ChainWrapper * ♻ Replace mapValues by a for in in ChainWrapper * ♻️ Inline get and isEmpty in protect * 🚚 Move isObject to util/lang * ♻️ Use instanceof instead of typeof for isObject implementation * ♻ Replace omit by destructuring in UsingWrapper * ♻ Add get to core for usage in UsingWrapper * 💡 core.get documentation * ✏️ Fix typo in isObject jsdoc
- Loading branch information
1 parent
cbeda1d
commit 79d0b59
Showing
34 changed files
with
222 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/immutadot/src/util/convert.js → ...utadot-lodash/src/util/convertLodashFp.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { isNil } from 'util/lang' | ||
import { unsafeToPath } from './toPath' | ||
|
||
/** | ||
* Gets the value at <code>path</code> of <code>obj</code>. | ||
* @memberof core | ||
* @param {*} obj The object. | ||
* @param {string|Array} path The path of the property to get. | ||
* @param {*} defaultValue The default value. | ||
* @return {*} Returns the value or <code>defaultValue</code>. | ||
* @example get({ nested: { prop: 'val' } }, 'nested.prop') // => 'val' | ||
* @example get({ nested: { prop: 'val' } }, 'nested.unknown', 'default') // => 'default' | ||
* @since 1.0.0 | ||
*/ | ||
export function get(obj, path, defaultValue) { | ||
function walkPath(curObj, remPath) { | ||
if (remPath.length === 0) return curObj === undefined ? defaultValue : curObj | ||
if (isNil(curObj)) return defaultValue | ||
const [prop, ...pathRest] = remPath | ||
return walkPath(curObj[prop], pathRest) | ||
} | ||
return walkPath(obj, unsafeToPath(path)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* eslint-env jest */ | ||
import { get } from 'core' | ||
|
||
describe('Get', () => { | ||
const obj = { | ||
nested1: { prop: 'val' }, | ||
nested2: { arr: [{ val: 'arrVal' }] }, | ||
} | ||
|
||
it('should get a prop', () => { | ||
expect(get(obj, 'nested1.prop')).toBe('val') | ||
expect(get(obj, 'nested1.prop.length')).toBe(3) | ||
expect(get(obj, 'nested2.arr.length')).toBe(1) | ||
expect(get(obj, 'nested2.arr[0].val')).toBe('arrVal') | ||
}) | ||
|
||
it('should return undefined for unexisting path', () => { | ||
expect(get(obj, 'nested1.foo')).toBe(undefined) | ||
expect(get(obj, 'nested3.val')).toBe(undefined) | ||
expect(get(obj, 'nested2.arr[1].val')).toBe(undefined) | ||
}) | ||
|
||
it('should return defaultValue for unexisting path', () => { | ||
expect(get(obj, 'nested1.foo', 'defaultValue')).toBe('defaultValue') | ||
expect(get(obj, 'nested3.val', 'defaultValue')).toBe('defaultValue') | ||
expect(get(obj, 'nested2.arr[1].val', 'defaultValue')).toBe('defaultValue') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,12 @@ | ||
import { convert } from './convert' | ||
import { set } from './set' | ||
import { toPath } from './toPath' | ||
import { unset } from './unset' | ||
import { update } from './update' | ||
|
||
/** | ||
* Core functions. | ||
* @namespace core | ||
* @since 1.0.0 | ||
*/ | ||
export { | ||
convert, | ||
set, | ||
toPath, | ||
unset, | ||
update, | ||
} | ||
* Core functions. | ||
* @namespace core | ||
* @since 1.0.0 | ||
*/ | ||
|
||
export { convert } from './convert' | ||
export { get } from './get' | ||
export { set } from './set' | ||
export { toPath } from './toPath' | ||
export { unset } from './unset' | ||
export { update } from './update' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.