Skip to content

Commit e635177

Browse files
committed
More tests coverage
1 parent 8f5056b commit e635177

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/get-in.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@ const testCases: {
4242
],
4343
result: 'value1'
4444
},
45+
{
46+
parameters: [
47+
{
48+
key1: [
49+
{
50+
x: 777
51+
},
52+
{
53+
x: 888
54+
},
55+
{
56+
x: 999
57+
}
58+
]
59+
},
60+
'key1[2].x'
61+
],
62+
result: 999
63+
},
4564
{
4665
parameters: [['value0', 'value1', 'value2'], '[1]'],
4766
result: 'value1'

src/get-in.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { IPlainObject } from './types';
66
import { toPath } from './to-path';
77
import { isPlainObject } from './is-plain-object';
88

9+
// -----------------------------------------------------------------------------
10+
// Helper
11+
// -----------------------------------------------------------------------------
12+
913
/**
1014
* Convert string sample in to the path (array)
1115
* Inspired by final-form's `toPath` helper

src/to-path.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
// -----------------------------------------------------------------------------
2+
// Private
3+
// -----------------------------------------------------------------------------
4+
15
const cache: Record<string, string[]> = {};
26
const regex = /(\[(?=\d+])|(?<=\[\d+)])|\.+/;
37

8+
// -----------------------------------------------------------------------------
9+
// Helper
10+
// -----------------------------------------------------------------------------
11+
412
/**
513
* Convert string sample in to the path (array)
614
* Inspired by final-form's `toPath` helper

0 commit comments

Comments
 (0)