Skip to content

Commit 7ec57de

Browse files
committed
Fix exports
1 parent 84b6aca commit 7ec57de

16 files changed

+104
-93
lines changed

prepublish-test/browser-global.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
describe('global Monet object', function () {
1+
describe('Browser: global Monet object', function () {
22
it('should be available', function () {
33
expect(Monet).toBeDefined()
4-
expect(Maybe).toBeDefined()
5-
expect(Either).toBeDefined()
6-
expect(Validation.success).toBe(Success)
4+
expect(Monet.Maybe).toBeDefined()
5+
expect(Monet.Either).toBeDefined()
6+
expect(Monet.Validation.success).toBe(Monet.Success)
7+
8+
expect(() => Maybe).toThrow()
9+
expect(() => Either).toThrow()
710
})
811
})

prepublish-test/node-global.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
global.useMonetGlobalObject = true // run browser style tests
2-
require('../dist/monet.js')
1+
global.Monet = require('../dist/monet.js')
32

4-
describe('global Monet object', function () {
3+
describe('Node: global Monet object', function () {
54
it('should be available', function () {
65
expect(Monet).toBeDefined()
7-
expect(Maybe).toBeDefined()
8-
expect(Either).toBeDefined()
9-
expect(Validation.success).toBe(Success)
6+
expect(Monet.Maybe).toBeDefined()
7+
expect(Monet.Either).toBeDefined()
8+
expect(Monet.Validation.success).toBe(Monet.Success)
9+
10+
expect(() => Maybe).toThrow()
11+
expect(() => Either).toThrow()
1012
})
1113
})

prepublish-test/node-regular.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const monet = require('../dist/monet.js')
22

3-
describe('monet.js exports object', function () {
3+
describe('Node: monet.js exports object', function () {
44
it('should be available', function () {
55
expect(monet).toBeDefined()
66
expect(monet.Maybe).toBeDefined()

src/monet-pimp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
if (typeof define === 'function' && define.amd) {
1818
define(['monet'], factory)
1919
} else if (typeof module === 'object' && module.exports) {
20-
module.exports = factory(require('monet'), typeof global === 'object' ? global : root)
20+
module.exports = factory(require('monet'), root)
2121
} else {
2222
factory(root.Monet, root)
2323
}

src/monet.js

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,13 @@
1414
if (typeof define === 'function' && define.amd) {
1515
define(factory)
1616
} else if (typeof module === 'object' && module.exports) {
17-
module.exports = factory(typeof global === 'object' ? global : root)
17+
module.exports = factory(root)
1818
} else {
19-
root.useMonetGlobalObject =
20-
typeof root.useMonetGlobalObject === 'boolean' ?
21-
root.useMonetGlobalObject :
22-
true
2319
root.Monet = factory(root)
2420
}
25-
}(typeof self !== 'undefined' ? self : this, function (rootGlobalObject) {
21+
}(typeof self !== 'undefined' ? self : this, function () {
2622
'use strict'
2723

28-
var root = {}
29-
3024
function assignImp(target, source) {
3125
for (var key in source) { // we need only one level of composition
3226
// eslint-disable-next-line no-undefined
@@ -242,7 +236,7 @@
242236
}
243237
}
244238

245-
root.List = List
239+
Monet.List = List
246240

247241
var listForEach = function (effectFn, l) {
248242
if (!l.isNil) {
@@ -362,9 +356,6 @@
362356
}, [], this)
363357
},
364358
toSet: function () {
365-
if (!rootGlobalObject.Set) {
366-
throw new Error('Provide polyfill or use up to date browser/node version to use "toSet" operator.')
367-
}
368359
return new Set(this)
369360
},
370361
foldLeft: function (initialValue) {
@@ -479,7 +470,7 @@
479470
// backwards compatibility, deprecated
480471
List.prototype.each = List.prototype.forEach
481472

482-
Nil = root.Nil = new List.fn.init()
473+
Nil = Monet.Nil = new List.fn.init()
483474

484475
/*
485476
* Non-Empty List monad
@@ -499,7 +490,7 @@
499490
return new NEL.fn.init(head, tail)
500491
}
501492

502-
root.NEL = root.NonEmptyList = NEL
493+
Monet.NEL = Monet.NonEmptyList = NEL
503494

504495
NEL.of = function (a) {
505496
return NEL(a, Nil)
@@ -637,7 +628,7 @@
637628

638629
/* Maybe Monad */
639630

640-
var Maybe = root.Maybe = {}
631+
var Maybe = Monet.Maybe = {}
641632

642633
Maybe.fromFalsy = function (val) {
643634
return !val ? Maybe.None() : Maybe.Some(val)
@@ -656,11 +647,11 @@
656647
return Some(a)
657648
}
658649

659-
var Some = Maybe.Just = Maybe.Some = Maybe.some = root.Some = root.Just = function (val) {
650+
var Some = Maybe.Just = Maybe.Some = Maybe.some = Monet.Some = Monet.Just = function (val) {
660651
return new Maybe.fn.init(true, val)
661652
}
662653

663-
var None = Maybe.Nothing = Maybe.None = Maybe.none = root.None = root.Nothing = function () {
654+
var None = Maybe.Nothing = Maybe.None = Maybe.none = Monet.None = Monet.Nothing = function () {
664655
return new Maybe.fn.init(false, null)
665656
}
666657

@@ -730,9 +721,6 @@
730721
})
731722
},
732723
toSet: function () {
733-
if (!rootGlobalObject.Set) {
734-
throw new Error('Provide polyfill or use up to date browser/node version to use "toSet" operator.')
735-
}
736724
return new Set(this)
737725
},
738726
toList: function () {
@@ -803,13 +791,13 @@
803791
Maybe.isInstance = isInstance(TYPES_NAMES.Maybe)
804792
Maybe.isOfType = isOfType(TYPES_NAMES.Maybe)
805793

806-
var Validation = root.Validation = {}
794+
var Validation = Monet.Validation = {}
807795

808-
var Success = Validation.Success = Validation.success = root.Success = function (val) {
796+
var Success = Validation.Success = Validation.success = Monet.Success = function (val) {
809797
return new Validation.fn.init(val, true)
810798
}
811799

812-
var Fail = Validation.Fail = Validation.fail = root.Fail = function (error) {
800+
var Fail = Validation.Fail = Validation.fail = Monet.Fail = function (error) {
813801
return new Validation.fn.init(error, false)
814802
}
815803

@@ -923,7 +911,7 @@
923911
Validation.isInstance = isInstance(TYPES_NAMES.Validation)
924912
Validation.isOfType = isOfType(TYPES_NAMES.Validation)
925913

926-
var Semigroup = root.Semigroup = {
914+
var Semigroup = Monet.Semigroup = {
927915
append: function (a, b) {
928916
if (isFunction(a.concat)) {
929917
return a.concat(b)
@@ -934,7 +922,7 @@
934922
}
935923
}
936924

937-
var MonadT = root.monadTransformer = root.MonadT = root.monadT = function (monad) {
925+
var MonadT = Monet.monadTransformer = Monet.MonadT = Monet.monadT = function (monad) {
938926
return new MonadT.fn.init(monad)
939927
}
940928

@@ -971,7 +959,7 @@
971959

972960
MonadT.fn.init.prototype = MonadT.fn
973961

974-
var IO = root.IO = root.io = function (effectFn) {
962+
var IO = Monet.IO = Monet.io = function (effectFn) {
975963
return new IO.fn.init(effectFn)
976964
}
977965

@@ -1023,16 +1011,16 @@
10231011

10241012
/* Either Monad */
10251013

1026-
var Either = root.Either = {}
1014+
var Either = Monet.Either = {}
10271015

10281016
Either.of = function (a) {
10291017
return Right(a)
10301018
}
10311019

1032-
var Right = Either.Right = Either.right = root.Right = function (val) {
1020+
var Right = Either.Right = Either.right = Monet.Right = function (val) {
10331021
return new Either.fn.init(val, true)
10341022
}
1035-
var Left = Either.Left = Either.left = root.Left = function (val) {
1023+
var Left = Either.Left = Either.left = Monet.Left = function (val) {
10361024
return new Either.fn.init(val, false)
10371025
}
10381026

@@ -1133,7 +1121,7 @@
11331121
Either.isInstance = isInstance(TYPES_NAMES.Either)
11341122
Either.isOfType = isOfType(TYPES_NAMES.Either)
11351123

1136-
var Reader = root.Reader = function (fn) {
1124+
var Reader = Monet.Reader = function (fn) {
11371125
return new Reader.fn.init(fn)
11381126
}
11391127

@@ -1191,12 +1179,12 @@
11911179
Reader.isInstance = isInstance(TYPES_NAMES.Reader)
11921180
Reader.isOfType = isOfType(TYPES_NAMES.Reader)
11931181

1194-
var Free = root.Free = {}
1182+
var Free = Monet.Free = {}
11951183

1196-
var Suspend = Free.Suspend = root.Suspend = function (functor) {
1184+
var Suspend = Free.Suspend = Monet.Suspend = function (functor) {
11971185
return new Free.fn.init(functor, true)
11981186
}
1199-
var Return = Free.Return = root.Return = function (val) {
1187+
var Return = Free.Return = Monet.Return = function (val) {
12001188
return new Free.fn.init(val, false)
12011189
}
12021190

@@ -1285,7 +1273,7 @@
12851273
return new Identity.fn.init(a)
12861274
}
12871275

1288-
root.Identity = Identity
1276+
Monet.Identity = Identity
12891277

12901278
Identity.of = function (a) {
12911279
return new Identity(a)
@@ -1330,9 +1318,6 @@
13301318
return List(this.get(), Nil)
13311319
},
13321320
toSet: function () {
1333-
if (!rootGlobalObject.Set) {
1334-
throw new Error('Provide polyfill or use up to date browser/node version to use "toSet" operator.')
1335-
}
13361321
return new Set(this)
13371322
}
13381323
}
@@ -1429,10 +1414,6 @@
14291414

14301415
function makeIterable(type) {
14311416
if (isFunction(type.prototype.toArray)) {
1432-
if (!rootGlobalObject.Symbol) {
1433-
// eslint-disable-next-line no-console
1434-
console.error(new Error('Provide polyfill or use up to date browser/node version to use "Iterable" protocol.'))
1435-
}
14361417
type.prototype[Symbol.iterator] = function () {
14371418
return this.toArray()[Symbol.iterator]()
14381419
}
@@ -1470,11 +1451,5 @@
14701451
decorate(Free)
14711452
decorate(Identity)
14721453

1473-
return Maybe.fromNull(rootGlobalObject)
1474-
.filter(function (rootObj) { return rootObj.useMonetGlobalObject })
1475-
.cata(function () { return assign(Monet, root) }, function (rootObj) {
1476-
assign(rootObj, root)
1477-
rootObj.Monet = Monet
1478-
return Monet
1479-
})
1454+
return Monet
14801455
}))

test/either-spec.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
*/
44

55
describe('An Either', function () {
6+
var Either = Monet.Either
7+
var Right = Monet.Right
8+
var Left = Monet.Left
69
var sideEffectsReceiver = null
710

811
beforeEach(function () {
@@ -113,7 +116,7 @@ describe('An Either', function () {
113116
it('equals to Right with the same value', function () {
114117
expect(rightString.equals(Either.Right('abcd'))).toBe(true)
115118
expect(rightString.equals(Either.right('abcd'))).toBe(true)
116-
expect(Right(Just(2)).equals(Right(Just(2)))).toBe(true)
119+
expect(Right(Monet.Just(2)).equals(Right(Monet.Just(2)))).toBe(true)
117120
})
118121
it('does not equal to Rights with different values or Lefts', function () {
119122
expect(rightString.equals(Either.Left('abcd'))).toBe(false)
@@ -227,7 +230,7 @@ describe('An Either', function () {
227230
it('equals to Left with the same value', function () {
228231
expect(leftString.equals(Either.Left('error dude'))).toBe(true)
229232
expect(leftString.equals(Either.left('error dude'))).toBe(true)
230-
expect(Left(Just(2)).equals(Left(Just(2)))).toBe(true)
233+
expect(Left(Monet.Just(2)).equals(Left(Monet.Just(2)))).toBe(true)
231234
})
232235
it('does not equal to Rights with different values or Lefts', function () {
233236
expect(leftString.equals(Either.Left('x'))).toBeFalsy()

test/free-spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
describe('A Free monad', function () {
2+
var Free = Monet.Free
3+
var Suspend = Monet.Suspend
4+
var Return = Monet.Return
5+
var Identity = Monet.Identity
6+
27
it('do Ken\'s simple box example', function () {
38
var s1 = Free.liftF(Identity(1));
49
var s2 = Free.liftF(Identity(2));

test/io-spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
describe('An IO monad', function () {
2+
var IO = Monet.IO
23
var effect = IO(function () {
34
return 'effect';
45
})

test/list-spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
describe('An immutable list', function () {
2+
var List = Monet.List
3+
var Nil = Monet.Nil
4+
var Some = Monet.Some
5+
var None = Monet.None
6+
var IO = Monet.IO
7+
var Reader = Monet.Reader
8+
var Right = Monet.Right
9+
var Left = Monet.Left
10+
var Success = Monet.Success
11+
var Fail = Monet.Fail
212
var sideEffectsReceiver = null
313

414
function expectCalls(spiedCall, values) {

0 commit comments

Comments
 (0)