Skip to content

Commit 7c947fb

Browse files
committed
Grunt inited, Need to work out some tests.
1 parent c1c3fdb commit 7c947fb

File tree

10 files changed

+339
-3
lines changed

10 files changed

+339
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules/

.jshintrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"curly": true,
3+
"eqeqeq": true,
4+
"immed": true,
5+
"latedef": true,
6+
"newcap": true,
7+
"noarg": true,
8+
"sub": true,
9+
"undef": true,
10+
"unused": true,
11+
"boss": true,
12+
"eqnull": true,
13+
"node": true
14+
}

Gruntfile.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
'use strict';
2+
3+
module.exports = function(grunt) {
4+
5+
// Project configuration.
6+
grunt.initConfig({
7+
// Metadata.
8+
pkg: grunt.file.readJSON('package.json'),
9+
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
10+
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
11+
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
12+
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
13+
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
14+
// Task configuration.
15+
concat: {
16+
options: {
17+
banner: '<%= banner %>',
18+
stripBanners: true
19+
},
20+
dist: {
21+
src: ['lib/<%= pkg.name %>.js'],
22+
dest: 'dist/<%= pkg.name %>.js'
23+
},
24+
},
25+
uglify: {
26+
options: {
27+
banner: '<%= banner %>'
28+
},
29+
dist: {
30+
src: '<%= concat.dist.dest %>',
31+
dest: 'dist/<%= pkg.name %>.min.js'
32+
},
33+
},
34+
nodeunit: {
35+
files: ['test/**/*_test.js']
36+
},
37+
jshint: {
38+
options: {
39+
jshintrc: '.jshintrc'
40+
},
41+
gruntfile: {
42+
src: 'Gruntfile.js'
43+
},
44+
lib: {
45+
options: {
46+
jshintrc: 'lib/.jshintrc'
47+
},
48+
src: ['lib/**/*.js']
49+
},
50+
test: {
51+
src: ['test/**/*.js']
52+
},
53+
},
54+
watch: {
55+
gruntfile: {
56+
files: '<%= jshint.gruntfile.src %>',
57+
tasks: ['jshint:gruntfile']
58+
},
59+
lib: {
60+
files: '<%= jshint.lib.src %>',
61+
tasks: ['jshint:lib', 'nodeunit']
62+
},
63+
test: {
64+
files: '<%= jshint.test.src %>',
65+
tasks: ['jshint:test', 'nodeunit']
66+
},
67+
},
68+
});
69+
70+
// These plugins provide necessary tasks.
71+
grunt.loadNpmTasks('grunt-contrib-concat');
72+
grunt.loadNpmTasks('grunt-contrib-uglify');
73+
grunt.loadNpmTasks('grunt-contrib-nodeunit');
74+
grunt.loadNpmTasks('grunt-contrib-jshint');
75+
grunt.loadNpmTasks('grunt-contrib-watch');
76+
77+
// Default task.
78+
grunt.registerTask('default', ['jshint', 'nodeunit', 'concat', 'uglify']);
79+
80+
};

LICENSE-MIT

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2013 Michael Seid
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use,
7+
copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.

Monad.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
;(function(M, undefined){
2+
var isFunction = function (functionToCheck) {
3+
var getType = {};
4+
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
5+
}
6+
7+
M.Option = function( value ){
8+
this.get = value;
9+
this.isDefined = function(){
10+
return (typeof this.get != "undefined");
11+
}
12+
this.getOrElse = function( elseVal ){
13+
if(this.isDefined){
14+
return this.get;
15+
}else{
16+
if(isFunction( elseVal)){
17+
return elseVal();
18+
}else{
19+
return elseVal;
20+
}
21+
22+
}
23+
}
24+
return this;
25+
}
26+
M.Some = function( value ){
27+
return M.Option(value);
28+
}
29+
M.None = function(){
30+
return M.Option(undefined);
31+
}
32+
}
33+
}(window.M = window.M || {}));

README.md

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,57 @@
1-
Mondad.js
2-
=========
1+
# Monad
32

4-
Mondads for Javascript -- Heavily Inspired by Scala
3+
Bringing Monads to JS -- Heavily Inspired by Scala
4+
5+
## Getting Started
6+
### On the server
7+
Install the module with: `npm install Monad`
8+
9+
```javascript
10+
var Monad = require('Monad');
11+
Monad.awesome(); // "awesome"
12+
```
13+
14+
### In the browser
15+
Download the [production version][min] or the [development version][max].
16+
17+
[min]: https://raw.github.com/mbseid/Monad.js/master/dist/Monad.min.js
18+
[max]: https://raw.github.com/mbseid/Monad.js/master/dist/Monad.js
19+
20+
In your web page:
21+
22+
```html
23+
<script src="dist/Monad.min.js"></script>
24+
<script>
25+
awesome(); // "awesome"
26+
</script>
27+
```
28+
29+
In your code, you can attach Monad's methods to any object.
30+
31+
```html
32+
<script>
33+
var exports = Bocoup.utils;
34+
</script>
35+
<script src="dist/Monad.min.js"></script>
36+
<script>
37+
Bocoup.utils.awesome(); // "awesome"
38+
</script>
39+
```
40+
41+
## Documentation
42+
_(Coming soon)_
43+
44+
## Examples
45+
_(Coming soon)_
46+
47+
## Contributing
48+
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
49+
50+
_Also, please don't edit files in the "dist" subdirectory as they are generated via Grunt. You'll find source code in the "lib" subdirectory!_
51+
52+
## Release History
53+
_(Nothing yet)_
54+
55+
## License
56+
Copyright (c) 2013 Michael Seid
57+
Licensed under the MIT license.

lib/.jshintrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"curly": true,
3+
"eqeqeq": true,
4+
"immed": true,
5+
"latedef": true,
6+
"newcap": true,
7+
"noarg": true,
8+
"sub": true,
9+
"undef": true,
10+
"boss": true,
11+
"eqnull": true,
12+
"predef": ["exports"]
13+
}

lib/Monad.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Monad
3+
* https://github.com/mbseid/Monad.js
4+
*
5+
* Copyright (c) 2013 Michael Seid
6+
* Licensed under the MIT license.
7+
*/
8+
9+
(function(exports) {
10+
11+
'use strict';
12+
13+
var isFunction = function (functionToCheck) {
14+
var getType = {};
15+
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
16+
}
17+
18+
exports.Option = function( value ){
19+
this.get = value;
20+
this.isDefined = function(){
21+
return (typeof this.get != "undefined");
22+
}
23+
this.getOrElse = function( elseVal ){
24+
if(this.isDefined){
25+
return this.get;
26+
}else{
27+
if(isFunction( elseVal)){
28+
return elseVal();
29+
}else{
30+
return elseVal;
31+
}
32+
33+
}
34+
}
35+
return this;
36+
}
37+
exports.Some = function( value ){
38+
return exports.Option(value);
39+
}
40+
exports.None = function(){
41+
return exports.Option(undefined);
42+
}
43+
44+
45+
}(typeof exports === 'object' && exports || this));

package.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "Monad",
3+
"description": "Bringing Monads to JS -- Heavily Inspired by Scala",
4+
"version": "0.1.0",
5+
"homepage": "https://github.com/mbseid/Monad.js",
6+
"author": {
7+
"name": "Michael Seid",
8+
"email": "[email protected]",
9+
"url": "mbseid.com"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "https://[email protected]/mbseid/Monad.js.git"
14+
},
15+
"bugs": {
16+
"url": "https://github.com/mbseid/Monad.js/issues"
17+
},
18+
"licenses": [
19+
{
20+
"type": "MIT",
21+
"url": "https://github.com/mbseid/Monad.js/blob/master/LICENSE-MIT"
22+
}
23+
],
24+
"main": "lib/Monad",
25+
"engines": {
26+
"node": ">= 0.6.0"
27+
},
28+
"scripts": {
29+
"test": "grunt nodeunit"
30+
},
31+
"devDependencies": {
32+
"grunt-contrib-concat": "~0.3.0",
33+
"grunt-contrib-uglify": "~0.2.0",
34+
"grunt-contrib-jshint": "~0.6.0",
35+
"grunt-contrib-nodeunit": "~0.2.0",
36+
"grunt-contrib-watch": "~0.4.0",
37+
"grunt": "~0.4.1"
38+
},
39+
"keywords": []
40+
}

test/Monad_test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
var Monad = require('../lib/Monad.js');
4+
5+
/*
6+
======== A Handy Little Nodeunit Reference ========
7+
https://github.com/caolan/nodeunit
8+
9+
Test methods:
10+
test.expect(numAssertions)
11+
test.done()
12+
Test assertions:
13+
test.ok(value, [message])
14+
test.equal(actual, expected, [message])
15+
test.notEqual(actual, expected, [message])
16+
test.deepEqual(actual, expected, [message])
17+
test.notDeepEqual(actual, expected, [message])
18+
test.strictEqual(actual, expected, [message])
19+
test.notStrictEqual(actual, expected, [message])
20+
test.throws(block, [error], [message])
21+
test.doesNotThrow(block, [error], [message])
22+
test.ifError(value)
23+
*/
24+
25+
exports['awesome'] = {
26+
setUp: function(done) {
27+
done();
28+
},
29+
'no args': function(test) {
30+
test.expect(1);
31+
// tests here
32+
test.equal(Monad.awesome(), 'awesome', 'should be awesome.');
33+
test.done();
34+
}
35+
};

0 commit comments

Comments
 (0)