Skip to content

Commit d4ce40a

Browse files
committed
fix(Array): Support dot and number in name
Array now support starting with numbers and having dot in their name. Fixes #95
1 parent 081d7de commit d4ce40a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/lib/ArrayInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function isInt(value: any) {
66
Number(value) == value && !isNaN(parseInt(value, 10))
77
}
88

9-
export const arrayRegex = () => /^([a-zA-Z_$][0-9a-zA-Z_\-$]*)\[((?!(\]|\[)).*|)\]$/gm
9+
export const arrayRegex = () => /^([\.0-9a-zA-Z_$\-][0-9a-zA-Z_\-$\.]*)\[((?!(\]|\[)).*|)\]$/gm
1010
const regexCache = {} as KeyValue
1111

1212
export class ArrayInfo {

test/02-jsondb.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,18 @@ describe('JsonDB', () => {
481481
}
482482
}
483483
)
484+
test('should add array entry of array starting with number in name', () => {
485+
db.push('/arraytest/11_Dec[0]', "test", true)
486+
const myarray = db.getData('/arraytest/11_Dec')
487+
expect(myarray).toBeInstanceOf(Array)
488+
expect(myarray[0]).toBe('test')
489+
})
490+
test('should add array entry of array containg a dot (.) in name', () => {
491+
db.push('/arraytest/d.s_[0]', "test", true)
492+
const myarray = db.getData('/arraytest/d.s_')
493+
expect(myarray).toBeInstanceOf(Array)
494+
expect(myarray[0]).toBe('test')
495+
})
484496
describe('last item', () => {
485497

486498
test(

0 commit comments

Comments
 (0)