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
5 changes: 5 additions & 0 deletions lab-mark/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules/*
**/vendor/*
**/*.min.js
**/coverage/*
**/build/*
26 changes: 26 additions & 0 deletions lab-mark/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"env": {
"browser": true,
"node": true,
"commonjs": true,
"jest": true,
"es6": true
},
"globals": {
"err": true,
"req": true,
"res": true,
"next": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"no-console": "off",
"indent": [ "error", 2 ],
"quotes": ["error", "single", { "allowTemplateLiterals": true }],
"comma-dangle": ["error", "always-multiline"],
"semi": [ "error", "always" ]
}
}
128 changes: 128 additions & 0 deletions lab-mark/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@

# Created by https://www.gitignore.io/api/osx,node,linux,windows

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env


### OSX ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.gitignore.io/api/osx,node,linux,windows
12 changes: 12 additions & 0 deletions lab-mark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) Code-401-Javascript Lab-2
===
This is day 3 of lab with Code Fellows and it teaches students the fundamentals of asynchronous call backs utilizing the FS module in Node.
# Modules
Description of exported values of each module defined in lib/ directory, along with arity and expected input/return values.
### reader.js
Exports a single function that takes an array of n file paths and resolves a mapped array of strings loaded from each file using an error-first callback.

* The reader function has an arity of 3.
* The first parameter expects an array of paths.
* The second parameter expects a callback function used to signal the recursion process is done.
* The third parameter takes in the populated array during recursion.
36 changes: 36 additions & 0 deletions lab-mark/__test__/reader.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

const reader = require('../lib/reader.js');

const testData = [
`${__dirname}/../assets/test1.txt`,
`${__dirname}/../assets/test2.txt`,
`${__dirname}/../assets/test3.txt`,
`${__dirname}/../assets/test4.txt`,
`${__dirname}/../assets/test5.txt`,
];

describe('#reader', () => {
test('an invalid path should reject an error', (done) => {
reader([`${__dirname}/../assets/Invalid-Lol.txt`], (err, data) => {
expect(err).not.toBeNull();
expect(data).toBeUndefined();
done();
});
});

test('a valid single path in an array should return the string of the text in an array', (done) => {
reader([`${__dirname}/../assets/test1.txt`], (err, data) => {
expect(err).toBeNull();
expect(data).toEqual(['This is test one.\n']);
done();
});
});
test('A valid array of file paths should return mapped array string data', (done) => {
reader(testData, (err, data) => {
expect(err).toBeNull();
expect(data).toEqual(['This is test one.\n','This is test two.\n','This is test three.\n','This is test four.\n','I bet you thought this would say this is test 5..... hah!\n']);
done();
});
});
});
1 change: 1 addition & 0 deletions lab-mark/assets/test1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is test one.
1 change: 1 addition & 0 deletions lab-mark/assets/test2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is test two.
1 change: 1 addition & 0 deletions lab-mark/assets/test3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is test three.
1 change: 1 addition & 0 deletions lab-mark/assets/test4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is test four.
1 change: 1 addition & 0 deletions lab-mark/assets/test5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I bet you thought this would say this is test 5..... hah!
25 changes: 25 additions & 0 deletions lab-mark/lib/reader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

const fs = require('fs');

module.exports = (path, callback, returnData) => {

if(!returnData)
returnData = [];

// No more paths... tell tests that it's done.
if (path.length === 0) {
callback(null, returnData);
}

// More paths... call yoself
else {
fs.readFile(path[0], (err, data) => {
if(err)
return callback(err);

returnData.push(data.toString());
module.exports(path.slice(1), callback, returnData);
});
}
};
Loading