Skip to content

Commit

Permalink
fix(struct): encode false and null fields correctly (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
hasparus authored and callmehiphop committed Aug 8, 2019
1 parent 18ff5f9 commit 55f7bea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const struct = {
const fields = {};
Object.keys(json).forEach(key => {
// If value is undefined, do not encode it.
if (!json[key]) return;
if (typeof json[key] === 'undefined') return;
fields[key] = value.encode(json[key]);
});
return {fields};
Expand Down
14 changes: 10 additions & 4 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ const arr = [null, 10];

const obj = {
foo: 'bar',
yes: true
no: false,
nil: null
};

const objWithUndefined = {
foo: 'bar',
yes: true,
no: false,
nil: null,
isUndefined: undefined
};

Expand All @@ -30,9 +32,13 @@ const structValue = {
kind: 'stringValue',
stringValue: 'bar'
},
yes: {
no: {
kind: 'boolValue',
boolValue: true
boolValue: false
},
nil: {
kind: 'nullValue',
nullValue: 0
}
}
};
Expand Down

0 comments on commit 55f7bea

Please sign in to comment.