Allow Number type in updateIn function (#67)
This commit is contained in:
parent
79320ad975
commit
bc00fee109
@ -3,5 +3,5 @@ import reject from 'lodash/reject';
|
|||||||
export default function splitPath(path) {
|
export default function splitPath(path) {
|
||||||
return Array.isArray(path) ?
|
return Array.isArray(path) ?
|
||||||
path :
|
path :
|
||||||
reject(path.split('.'), x => !x);
|
reject((path + '').split('.'), x => !x);
|
||||||
}
|
}
|
||||||
|
22
test/util/splitPath-spec.js
Normal file
22
test/util/splitPath-spec.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { expect } from 'chai';
|
||||||
|
import splitPath from '../../lib/util/splitPath';
|
||||||
|
|
||||||
|
describe('splitPath', () => {
|
||||||
|
it('treats a number as a single step path', () => {
|
||||||
|
const path = 1;
|
||||||
|
const result = splitPath(path);
|
||||||
|
expect(result).to.deep.equal(['1']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles arrays', () => {
|
||||||
|
const path = ['foo', 'bar', 'x'];
|
||||||
|
const result = splitPath(path);
|
||||||
|
expect(result).to.equal(path);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles strings separated by dots', () => {
|
||||||
|
const path = 'bar.0.y';
|
||||||
|
const result = splitPath(path);
|
||||||
|
expect(result).to.deep.equal(['bar', '0', 'y']);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user