-
Notifications
You must be signed in to change notification settings - Fork 39
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
Allow Number type in updateIn function #67
Allow Number type in updateIn function #67
Conversation
|
||
export default function splitPath(path) { | ||
return Array.isArray(path) ? | ||
path : | ||
reject(path.split('.'), x => !x); | ||
reject(toString(path).split('.'), x => !x); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need all of the things that lodash/toString
does, can you just use (path + '')
instead please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
const path = 'bar.0.y'; | ||
const result = splitPath(path); | ||
expect(result).to.deep.equal(['bar', '0', 'y']); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks for the tests, though could you follow the existing style of tests, specifically:
- blank lines between tests
- complete sentences (when "it" is prepended) for the test names, e.g.
it('treats a number as a single step path')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe('splitPath', () => {
it('treats only number', () => {
const path = 1;
const result = splitPath(path);
expect(result).to.deep.equal(['1']);
});
it('treats only number', () => {
const path = 0;
const result = splitPath(path);
expect(result).to.deep.equal(['0']);
});
it('treats simple array', () => {
const path = ['foo', 'bar', 'x'];
const result = splitPath(path);
expect(result).to.equal(path);
});
it('treats a number as a single step path', () => {
const path = 'bar.0.y';
const result = splitPath(path);
expect(result).to.deep.equal(['bar', '0', 'y']);
});
});
so, it's ok? 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, my example was meant to be for the first.
You can certainly simplify, but I would use the word "handles" instead of "treats", since "treats" requires something like "as a ..." at the end of the sentence.
So, "it handles numbers", "it handles arrays", "it handles strings separated by dots"
You can probably get rid of either the 0 or the 1 test, you don't really need them both and they'd have the same name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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']);
});
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aaronjensen done :)
Looks great, thank you for the contribution @avevlad |
@aaronjensen thanks you! 👍 |
@avevlad released 1.0.0, thanks again |
Test case:
Before output:
After: