Skip to content

Commit 59adaa8

Browse files
merlinnotthechenky
authored andcommitted
Remove unused valAt utility (#513)
1 parent 3f1cdd8 commit 59adaa8

File tree

2 files changed

+1
-53
lines changed

2 files changed

+1
-53
lines changed

spec/utils.spec.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// SOFTWARE.
2222

2323
import { expect } from 'chai';
24-
import { applyChange, normalizePath, pathParts, valAt } from '../src/utils';
24+
import { applyChange, normalizePath, pathParts } from '../src/utils';
2525

2626
describe('utils', () => {
2727
describe('.normalizePath(path: string)', () => {
@@ -42,27 +42,6 @@ describe('utils', () => {
4242
});
4343
});
4444

45-
describe('.valAt(source: any, path?: string): any', () => {
46-
it('should be null if null along any point in the path', () => {
47-
expect(valAt(null)).to.be.null;
48-
expect(valAt(null, '/foo')).to.be.null;
49-
expect(valAt({ a: { b: null } }, '/a/b/c')).to.be.null;
50-
});
51-
52-
it('should be null if accessing a path past a leaf value', () => {
53-
expect(valAt({ a: 2 }, '/a/b')).to.be.null;
54-
});
55-
56-
it('should be the leaf value if one is present', () => {
57-
expect(valAt({ a: { b: 23 } }, '/a/b')).to.eq(23);
58-
expect(valAt({ a: { b: 23 } }, '/a')).to.deep.equal({ b: 23 });
59-
});
60-
61-
it('should be undefined if in unexplored territory', () => {
62-
expect(valAt({ a: 23 }, '/b')).to.be.undefined;
63-
});
64-
});
65-
6645
describe('.applyChange(from: any, to: any): any', () => {
6746
it('should return the to value for non-object values of from and to', () => {
6847
expect(applyChange({ a: 'b' }, null)).to.eq(null);

src/utils.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -61,34 +61,3 @@ export function pruneNulls(obj: any) {
6161
}
6262
return obj;
6363
}
64-
65-
export function valAt(source: any, path?: string) {
66-
if (source === null) {
67-
return null;
68-
} else if (typeof source !== 'object') {
69-
return path ? null : source;
70-
}
71-
72-
const parts = pathParts(path);
73-
if (!parts.length) {
74-
return source;
75-
}
76-
77-
let cur = source;
78-
let leaf;
79-
while (parts.length) {
80-
const key = parts.shift();
81-
if (cur[key] === null || leaf) {
82-
return null;
83-
} else if (typeof cur[key] === 'object') {
84-
if (parts.length) {
85-
cur = cur[key];
86-
} else {
87-
return cur[key];
88-
}
89-
} else {
90-
leaf = cur[key];
91-
}
92-
}
93-
return leaf;
94-
}

0 commit comments

Comments
 (0)