Skip to content

Commit

Permalink
Fixes #242
Browse files Browse the repository at this point in the history
  • Loading branch information
marcvelmer committed Aug 29, 2023
1 parent bf81834 commit 3da15f4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- `dotobject` helper returns null when key is not found.

## [0.1.1] - 2023-08-14

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions src/util/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export function formatUnits(value: BigNumberish, decimals: number = 18): string
*/
export const dotobject = (obj: any, dot: string) => {
const rec = (obj: any, dot: string[]): any => {
if (dot.length && typeof obj[dot[0]] !== 'undefined') {
return rec(obj[dot[0]], dot.slice(1));
if (dot.length) {
return typeof obj[dot[0]] !== 'undefined' ? rec(obj[dot[0]], dot.slice(1)) : null;
}
return obj;
};
Expand Down
4 changes: 4 additions & 0 deletions test/unit/types/election.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ describe('Election tests', () => {
},
});
expect(election.get('census.type')).toEqual('spreadsheet');
expect(election.get('census.fields')).toEqual(['firstname', 'lastname', 'email']);
expect(election.get('bad')).toBeNull();
expect(election.get('bad.bad')).toBeNull();
expect(election.get('census.bad')).toBeNull();
expect(election.electionType).toEqual({
autoStart: true,
interruptible: true,
Expand Down

0 comments on commit 3da15f4

Please sign in to comment.