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) }) })