Skip to content

Commit

Permalink
Merge pull request #294 from sanctuary-js/davidchambers/buffer
Browse files Browse the repository at this point in the history
types: define Buffer
  • Loading branch information
davidchambers authored Jul 25, 2020
2 parents 77d25f4 + 25baaf0 commit 453d771
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
16 changes: 16 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,18 @@
([])
(typeofEq ('boolean'));

//# Buffer :: Type
//.
//. Type comprising every [Buffer][] object.
var Buffer_ = NullaryTypeWithUrl
('Buffer')
([])
(function(x) {
return typeof Buffer !== 'undefined' &&
// eslint-disable-next-line no-undef
Buffer.isBuffer (x);
});

//# Date :: Type
//.
//. Type comprising every Date value.
Expand Down Expand Up @@ -1054,6 +1066,7 @@
//. - <code>[Array](#Array) ([Unknown][])</code>
//. - <code>[Array2](#Array2) ([Unknown][]) ([Unknown][])</code>
//. - <code>[Boolean](#Boolean)</code>
//. - <code>[Buffer](#Buffer)</code>
//. - <code>[Date](#Date)</code>
//. - <code>[Descending](#Descending) ([Unknown][])</code>
//. - <code>[Either](#Either) ([Unknown][]) ([Unknown][])</code>
Expand Down Expand Up @@ -1082,6 +1095,7 @@
Array_ (Unknown),
Array2 (Unknown) (Unknown),
Boolean_,
Buffer_,
Date_,
Descending (Unknown),
Either_ (Unknown) (Unknown),
Expand Down Expand Up @@ -2823,6 +2837,7 @@
Array1: fromUncheckedUnaryType (Array1),
Array2: fromUncheckedBinaryType (Array2),
Boolean: Boolean_,
Buffer: Buffer_,
Date: Date_,
ValidDate: ValidDate,
Descending: fromUncheckedUnaryType (Descending),
Expand Down Expand Up @@ -2974,6 +2989,7 @@

}));

//. [Buffer]: https://nodejs.org/api/buffer.html#buffer_buffer
//. [Descending]: v:sanctuary-js/sanctuary-descending
//. [Either]: v:sanctuary-js/sanctuary-either
//. [FL:Semigroup]: https://github.com/fantasyland/fantasy-land#semigroup
Expand Down
22 changes: 22 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ suite ('env', () => {
$.Array ($.Unknown),
$.Array2 ($.Unknown) ($.Unknown),
$.Boolean,
$.Buffer,
$.Date,
$.Descending ($.Unknown),
$.Either ($.Unknown) ($.Unknown),
Expand Down Expand Up @@ -1552,6 +1553,27 @@ See https://github.com/sanctuary-js/sanctuary-def/tree/v${version}#Array2 for in
eq ($.Boolean.supertypes) ([]);
});

test ('provides the "Buffer" type', () => {
eq ($.Buffer.name) ('Buffer');
eq ($.Buffer.url) (`https://github.com/sanctuary-js/sanctuary-def/tree/v${version}#Buffer`);
eq ($.Buffer.supertypes) ([]);

const isBuffer = $.test ([]) ($.Buffer);
eq (isBuffer (null)) (false);
eq (isBuffer (Buffer.from ([1, 2, 3]))) (true);

{
const Buffer = global.Buffer;
delete global.Buffer;
try {
eq (isBuffer (null)) (false);
eq (isBuffer (Buffer.from ([1, 2, 3]))) (false);
} finally {
global.Buffer = Buffer;
}
}
});

test ('provides the "Date" type', () => {
eq ($.Date.name) ('Date');
eq ($.Date.url) (`https://github.com/sanctuary-js/sanctuary-def/tree/v${version}#Date`);
Expand Down

0 comments on commit 453d771

Please sign in to comment.