Last active
February 2, 2018 23:41
-
-
Save kevinchisholm/5aadcf9296b2b009183022cb7b62a84d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name" : "firstNodeJsModuleExample", | |
"version" : "0.0.1", | |
"dependencies" : { | |
"dateTools": "file:my_modules/dateTools" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'], | |
months = ['January', 'February', 'March', 'April', 'May', 'June', | |
'July', 'August', 'September', 'October', 'November', 'December']; | |
function getDays () { | |
return days; | |
}; | |
function getMonths () { | |
return months; | |
}; | |
function getDay (dayNumber) { | |
return (Number.isInteger(dayNumber) && (dayNumber <= (days.length - 1))) ? days[dayNumber] : ''; | |
}; | |
function getMonth (monthNumber) { | |
return (Number.isInteger(monthNumber) && (monthNumber <= (months.length - 1))) ? months[monthNumber] : ''; | |
}; | |
// export the module | |
module.exports = { | |
getDays: getDays, | |
getMonths: getMonths, | |
getDay: getDay, | |
getMonth: getMonth | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "dateTools", | |
"description": "Example Node Module", | |
"private": true, | |
"version": "1.0.0", | |
"main": "index.js" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// require the dateTools module. | |
var dateTools = require('dateTools'); | |
//demonstrate the getDay method | |
console.log('TEST 1: ' + dateTools.getDay(0)); //TEST 1: Monday | |
console.log('TEST 2: ' + dateTools.getDay(6)); //TEST 2: Sunday | |
//demonstrate the getMonth method | |
console.log('TEST 3: ' + dateTools.getMonth(0)); //TEST 3: January | |
console.log('TEST 4: ' + dateTools.getMonth(11)); //TEST 4: December | |
//demonstrate the getDays method | |
console.log('TEST 5: ' + dateTools.getDays()); //TEST 5: All seven days | |
//demonstrate the getMonths method | |
console.log('TEST 6: ' + dateTools.getMonths()); //TEST 6: All 12 months |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment