mirror of
https://github.com/cupcakearmy/svelte-i18n.git
synced 2024-11-17 02:19:52 +01:00
refactor: 💡 rename getIn to deepGet
This commit is contained in:
parent
c9c74480c3
commit
c783e1f9b3
@ -11,7 +11,7 @@ import { walk } from 'estree-walker'
|
|||||||
import { Ast } from 'svelte/types/compiler/interfaces'
|
import { Ast } from 'svelte/types/compiler/interfaces'
|
||||||
import { parse } from 'svelte/compiler'
|
import { parse } from 'svelte/compiler'
|
||||||
|
|
||||||
import { getIn } from './includes/getIn'
|
import { deepGet } from './includes/deepGet'
|
||||||
import { deepSet } from './includes/deepSet'
|
import { deepSet } from './includes/deepSet'
|
||||||
import { getObjFromExpression } from './includes/getObjFromExpression'
|
import { getObjFromExpression } from './includes/getObjFromExpression'
|
||||||
import { Message } from './types'
|
import { Message } from './types'
|
||||||
@ -173,7 +173,7 @@ export function extractMessages(
|
|||||||
} else {
|
} else {
|
||||||
if (
|
if (
|
||||||
overwrite === false &&
|
overwrite === false &&
|
||||||
typeof getIn(accumulator, message.meta.id) !== 'undefined'
|
typeof deepGet(accumulator, message.meta.id) !== 'undefined'
|
||||||
) {
|
) {
|
||||||
return
|
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) => {
|
return id.split('.').reduce((acc, path) => {
|
||||||
if (typeof acc !== 'object') {
|
if (typeof acc !== 'object') {
|
||||||
return acc
|
return acc
|
@ -1,17 +1,17 @@
|
|||||||
import { getIn } from '../../src/cli/includes/getIn'
|
import { deepGet } from '../../src/cli/includes/deepGet'
|
||||||
|
|
||||||
describe('deep object handling', () => {
|
describe('deep object handling', () => {
|
||||||
test('gets a deep property', () => {
|
test('gets a deep property', () => {
|
||||||
const obj = {
|
const obj = {
|
||||||
a: { b: { c: { d: ['foo', 'bar'] } } },
|
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', () => {
|
test('returns undefined for if some property not found', () => {
|
||||||
const obj = {
|
const obj = {
|
||||||
a: { b: 1 },
|
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