refactor: 💡 rename getIn to deepGet

This commit is contained in:
Christian Kaisermann 2020-01-21 10:07:27 -03:00
parent c9c74480c3
commit c783e1f9b3
3 changed files with 6 additions and 6 deletions

View File

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

View File

@ -1,4 +1,4 @@
export const getIn = (o: Record<string, any>, id: string) => {
export const deepGet = (o: Record<string, any>, id: string) => {
return id.split('.').reduce((acc, path) => {
if (typeof acc !== 'object') {
return acc

View File

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