Skip to content

Commit

Permalink
Merge pull request gcanti#228 from gcanti/227
Browse files Browse the repository at this point in the history
null Maybes should stringify to null, fix gcanti#227
  • Loading branch information
gcanti authored Jul 11, 2016
2 parents 9dcbbd2 + 2e2e229 commit fbacefb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
**Note**: Gaps between patch versions are faulty/broken releases.
**Note**: A feature tagged as Experimental is in a high state of flux, you're at risk of it changing without notice.

# v3.2.6

- **Bug Fix**
- null Maybes should stringify to null, fix #227 (@gcanti)

# v3.2.5

- **Polish**
Expand Down
2 changes: 1 addition & 1 deletion lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var stringify = require('./stringify');
// creates an instance of a type, handling the optional new operator
module.exports = function create(type, value, path) {
if (isType(type)) {
return !type.meta.identity && typeof value === 'object' ? new type(value, path): type(value, path);
return !type.meta.identity && typeof value === 'object' && value !== null ? new type(value, path): type(value, path);
}

if (process.env.NODE_ENV !== 'production') {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tcomb",
"version": "3.2.5",
"version": "3.2.6",
"description": "Type checking and DDD for JavaScript",
"main": "index.js",
"typings": "index.d.ts",
Expand Down
6 changes: 6 additions & 0 deletions test/maybe.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ describe('t.maybe(type, [name])', function () {
assert.ok(typeof T(undefined) === 'undefined');
});

it('should play well with JSON.stringify (#227)', function () {
var thing = t.struct({ foo: t.maybe(t.struct({ bar: t.String })) });
assert.strictEqual(JSON.stringify(thing({foo: null})), '{"foo":null}');
assert.strictEqual(JSON.stringify(thing({foo: undefined})), '{}');
});

});

describe('is(x)', function () {
Expand Down

0 comments on commit fbacefb

Please sign in to comment.