From 9f352845e14f09f7dfcce2cadc34a8c908e07970 Mon Sep 17 00:00:00 2001 From: Christian Kaisermann Date: Tue, 21 Jan 2020 10:07:27 -0300 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20rename=20getIn=20to?= =?UTF-8?q?=20deepGet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cli/extract.ts | 4 ++-- src/cli/includes/{getIn.ts => deepGet.ts} | 2 +- test/cli/includes.test.ts | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) rename src/cli/includes/{getIn.ts => deepGet.ts} (67%) diff --git a/src/cli/extract.ts b/src/cli/extract.ts index 9dd7bc3..a91982d 100644 --- a/src/cli/extract.ts +++ b/src/cli/extract.ts @@ -11,7 +11,7 @@ import { walk } from 'estree-walker' import { Ast } from 'svelte/types/compiler/interfaces' import { parse } from 'svelte/compiler' -import { getIn } from './includes/getIn' +import { deepGet } from './includes/deepGet' import { deepSet } from './includes/deepSet' import { getObjFromExpression } from './includes/getObjFromExpression' import { Message } from './types' @@ -173,7 +173,7 @@ export function extractMessages( } else { if ( overwrite === false && - typeof getIn(accumulator, message.meta.id) !== 'undefined' + typeof deepGet(accumulator, message.meta.id) !== 'undefined' ) { return } diff --git a/src/cli/includes/getIn.ts b/src/cli/includes/deepGet.ts similarity index 67% rename from src/cli/includes/getIn.ts rename to src/cli/includes/deepGet.ts index cd17649..b790d79 100644 --- a/src/cli/includes/getIn.ts +++ b/src/cli/includes/deepGet.ts @@ -1,4 +1,4 @@ -export const getIn = (o: Record, id: string) => { +export const deepGet = (o: Record, id: string) => { return id.split('.').reduce((acc, path) => { if (typeof acc !== 'object') { return acc diff --git a/test/cli/includes.test.ts b/test/cli/includes.test.ts index acb2063..256bd20 100644 --- a/test/cli/includes.test.ts +++ b/test/cli/includes.test.ts @@ -1,17 +1,17 @@ -import { getIn } from '../../src/cli/includes/getIn' +import { deepGet } from '../../src/cli/includes/deepGet' describe('deep object handling', () => { test('gets a deep property', () => { const obj = { a: { b: { c: { d: ['foo', 'bar'] } } }, } - expect(getIn(obj, 'a.b.c.d.1')).toBe('bar') + expect(deepGet(obj, 'a.b.c.d.1')).toBe('bar') }) test('returns undefined for if some property not found', () => { const obj = { a: { b: 1 }, } - expect(getIn(obj, 'c.b')).toBe(undefined) + expect(deepGet(obj, 'c.b')).toBe(undefined) }) })