mirror of
https://github.com/cupcakearmy/svelte-i18n.git
synced 2024-11-16 18:10:43 +01:00
refactor: 💡 rename getIn to deepGet
This commit is contained in:
parent
6526245bf9
commit
9f352845e1
@ -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
|
||||
}
|
||||
|
@ -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
|
@ -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)
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user