Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
46 changes: 46 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var index = require('./routes/index');
var users = require('./routes/users');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', index);
app.use('/users', users);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});

// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};

// render the error page
res.status(err.status || 500);
res.render('error');
});

module.exports = app;
90 changes: 90 additions & 0 deletions bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

var app = require('../app');
var debug = require('debug')('npm-modules:server');
var http = require('http');

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
* Create HTTP server.
*/

var server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "npm-modules",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www",
"test": "mocha"
},
"dependencies": {
"body-parser": "~1.16.0",
"chai": "^3.5.0",
"cookie-parser": "~1.4.3",
"debug": "~2.6.0",
"express": "~4.14.1",
"mocha": "^3.2.0",
"morgan": "~1.7.0",
"pug": "latest",
"serve-favicon": "~2.3.2"
}
}
5 changes: 5 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<head>
<title> This is only a Test </title>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only page that comes up when I attempt to load the site

</head>
<body>
</body>
Empty file added public/javascripts/index.js
Empty file.
8 changes: 8 additions & 0 deletions public/stylesheets/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}

a {
color: #00B7FF;
}
9 changes: 9 additions & 0 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'NPM Modules for JS' });
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is rendering index.html instead of index.pug?

});

module.exports = router;
9 changes: 9 additions & 0 deletions routes/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var express = require('express');
var router = express.Router();

/* GET users listing. */
router.get('/', function(req, res, next) {
res.send('respond with a resource');
});

module.exports = router;
3 changes: 3 additions & 0 deletions spec/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (num1,num2){
return (num1 + num2)
}
6 changes: 6 additions & 0 deletions spec/camelcase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports =function ( str ) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a space after the equals sign

function upperCase(match) {
return match.toUpperCase()
}
return str.replace(/\b[a-z]/g, upperCase).replace(/\s/g, '')
}
3 changes: 3 additions & 0 deletions spec/ceil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (num1){
return Math.ceil(num1)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd try rewriting .ceil in code instead of using .ceil

}
19 changes: 19 additions & 0 deletions spec/chunk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = function (list, size=2) {

if (list.isArray){
return []
}
var newList = []
for(var i = 0; i < list.length ; i+=size) {
var subArray = []
for(var j = 0; j < size ; j++) {
if (list[i+j]) {
subArray.push(list[i+j])
}

}
newList.push(subArray)
}

return newList
}
4 changes: 4 additions & 0 deletions spec/divide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = function(num1 , num2){
 // 1.5){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave out comments in the final product

return (num1 / num2)
}
7 changes: 7 additions & 0 deletions spec/join.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// module.exports = function (array) {
// for (i = 0; i < array.length; i++) {
//
//
// }
// return array.filter(/\s/g,'~')
// }
6 changes: 6 additions & 0 deletions spec/min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function min( inputArray ) {

return Math.min.apply(null, inputArray)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to rewrite .min instead of using .min



}
3 changes: 3 additions & 0 deletions spec/multiply.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (num1,num2){
return (num1 * num2)
}
6 changes: 6 additions & 0 deletions spec/random.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// module.exports = function(myArray) {
// function(){
// var result = myArray[Math.floor(Math.random() * myArray.length)]
// return result
// }
// }
7 changes: 7 additions & 0 deletions spec/repeat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function (str, n){
var utilities = {
repeat: function(str, n) {
return (new Array(n + 1)).join(str);
}
}
}
3 changes: 3 additions & 0 deletions spec/replace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (sentence, word1, word2){
return sentence.replace(word1, word2)
}
3 changes: 3 additions & 0 deletions spec/reversearray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function reversearray( array ) {
return array.reverse()
}
3 changes: 3 additions & 0 deletions spec/subtract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (num1,num2){
return (num1 - num2)
}
3 changes: 3 additions & 0 deletions spec/uppercase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function uppercase( anyString ) {
return anyString.toUpperCase()
}
6 changes: 6 additions & 0 deletions spec/upperfirst.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function upperfirst( str ) {
function substr(match) {
return match.toUpperCase()
}
return str.replace(/\b[a-z]/g, substr)
}
8 changes: 8 additions & 0 deletions test/add.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var {expect} = require("chai")
var add = require("../spec/add")

describe("add", function() {
it("should add two numbers", function(){
expect(add( 1 , 2 )).to.eql(3)
})
})
9 changes: 9 additions & 0 deletions test/camelcase.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var {expect} = require("chai")
var camelcase = require('../spec/camelcase')
var str = "This Should Be Camelized"

describe("camelcase", function() {
it("should camelize any sentence", function() {
expect(camelcase(str)).to.equal("ThisShouldBeCamelized")
})
})
8 changes: 8 additions & 0 deletions test/ceil.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var {expect} = require("chai")
var ceil = require('../spec/ceil')

describe("ceil", function() {
it("should compute number rounded up to precision", function() {
expect(ceil(3.2)).to.eql(4)
})
})
11 changes: 11 additions & 0 deletions test/chunk.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var {expect} = require("chai")
var chunk = require("../spec/chunk") // change spec and also folder
// name from spec to source

describe("chunk", function() {
it("should split array into chunks according to selected size", function() {
expect(chunk([1 , 2, 3, 4, 5], 3)).to.eql([[1 , 2 , 3],[4 , 5]])
})
})
// Nest a for loop create variable for new array
//iterate through the new array to handle chunk size
8 changes: 8 additions & 0 deletions test/divide.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var {expect} = require("chai")
var divide = require('../spec/divide')

describe("divide", function() {
it("should divide num1 by num2", function() {
expect(divide( 1 , 2 )).to.eql(.5)
})
})
9 changes: 9 additions & 0 deletions test/join.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// var {expect} = require("chai")
// var join = require('../spec/join')
// var array = ['this' , 'should' , 'be' , 'easy']
//
// describe("join", function() {
// it("should convert all elements into string with designated separator", function() {
// expect(join(array)).to.equal('this~should~be~easy')
// })
// })
8 changes: 8 additions & 0 deletions test/min.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var {expect} = require("chai")
var min = require('../spec/min')

describe("min", function() {
it("should display the lowest number in an array", function() {
expect(min([4, 1, 2, 3])).to.eql(1)
})
})
8 changes: 8 additions & 0 deletions test/multiply.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var {expect} = require("chai")
var multiply = require("../spec/multiply")

describe("multiply", function() {
it("should multiply num1 by num2", function() {
expect(multiply( 3 , 2 )).to.eql(6)
})
})
10 changes: 10 additions & 0 deletions test/random.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// var {expect} = require("chai")
// var random = require('../spec/random')
//
// var myArray = ['this','is','hard']
//
// describe("random", function() {
// it("should find a random element in an array", function() {
// expect(random(myArray)).to.equal(result)
// })
// })
13 changes: 13 additions & 0 deletions test/repeat.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// var {expect} = require("chai")
// var repeat = require('../spec/repeat')
//
// var str = 'cash'
// var n = 5
//
//
//
// describe("repeat", function() {
// it("should repeat the given string n times", function() {
// expect(repeat(str, n)).to.equal('cashcashcashcashcash')
// })
// })
Loading