From 027174dbf488259f764f0dfcc40276ac950695c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Natan=20S=C4=85gol?= Date: Wed, 10 Jul 2019 22:18:13 +0200 Subject: [PATCH] Remove unused valAt utility --- spec/utils.spec.ts | 23 +---------------------- src/utils.ts | 31 ------------------------------- 2 files changed, 1 insertion(+), 53 deletions(-) diff --git a/spec/utils.spec.ts b/spec/utils.spec.ts index 57634dd72..2ea64fb7e 100644 --- a/spec/utils.spec.ts +++ b/spec/utils.spec.ts @@ -21,7 +21,7 @@ // SOFTWARE. import { expect } from 'chai'; -import { applyChange, normalizePath, pathParts, valAt } from '../src/utils'; +import { applyChange, normalizePath, pathParts } from '../src/utils'; describe('utils', () => { describe('.normalizePath(path: string)', () => { @@ -42,27 +42,6 @@ describe('utils', () => { }); }); - describe('.valAt(source: any, path?: string): any', () => { - it('should be null if null along any point in the path', () => { - expect(valAt(null)).to.be.null; - expect(valAt(null, '/foo')).to.be.null; - expect(valAt({ a: { b: null } }, '/a/b/c')).to.be.null; - }); - - it('should be null if accessing a path past a leaf value', () => { - expect(valAt({ a: 2 }, '/a/b')).to.be.null; - }); - - it('should be the leaf value if one is present', () => { - expect(valAt({ a: { b: 23 } }, '/a/b')).to.eq(23); - expect(valAt({ a: { b: 23 } }, '/a')).to.deep.equal({ b: 23 }); - }); - - it('should be undefined if in unexplored territory', () => { - expect(valAt({ a: 23 }, '/b')).to.be.undefined; - }); - }); - describe('.applyChange(from: any, to: any): any', () => { it('should return the to value for non-object values of from and to', () => { expect(applyChange({ a: 'b' }, null)).to.eq(null); diff --git a/src/utils.ts b/src/utils.ts index 0ebbb38c4..ffec72a2d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -61,34 +61,3 @@ export function pruneNulls(obj: any) { } return obj; } - -export function valAt(source: any, path?: string) { - if (source === null) { - return null; - } else if (typeof source !== 'object') { - return path ? null : source; - } - - const parts = pathParts(path); - if (!parts.length) { - return source; - } - - let cur = source; - let leaf; - while (parts.length) { - const key = parts.shift(); - if (cur[key] === null || leaf) { - return null; - } else if (typeof cur[key] === 'object') { - if (parts.length) { - cur = cur[key]; - } else { - return cur[key]; - } - } else { - leaf = cur[key]; - } - } - return leaf; -}