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-christina/.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-christina/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"env": {
"browser": true,
"node": true,
"commonjs": true,
"mocha": 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-christina/.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-christina/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## 03-asynchronous-callbacks
### reader.js module
* Exports a function that loops though an array of filepaths. The function has an arity of two.
* Using fs readFIle the files are translated from buffer objects to 'utf-8'
* fs readFile is in error first data last format.
* If the filepath is undefined you will recieve an error.

### reader.test.js

* In the test file I've created two test.
* The first test ensures that an error will be returned in an invalid filepath is provided.
* The second tests purpose is to test the data is returned in a mapped array of strings. I am currently looping through all files and recieved the correct data. I've yet to accomplish mapping the return into an array.
1 change: 1 addition & 0 deletions lab-christina/__test__/asset/betcha.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
food
1 change: 1 addition & 0 deletions lab-christina/__test__/asset/data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
for
1 change: 1 addition & 0 deletions lab-christina/__test__/asset/lastly.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
words
19 changes: 19 additions & 0 deletions lab-christina/__test__/reader.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

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

describe('reader', () => {
test('an invalid path will result in an error message', (done) => {
reader(`${__dirname}/fake`, (err, data) => {
expect(data).toBeUndefined();
done();
});
});
test('a valid path should resolve in an array of strings', (done) => {
reader([`${__dirname}/asset/betcha.txt`,`${__dirname}/asset/data.txt`, `${__dirname}/asset/lastly.txt`], (err, data) => {
expect(err).toBeNull();
expect(data).toEqual(['words\n', 'for\n', 'food\n']);
done();
});
});
});
2 changes: 2 additions & 0 deletions lab-christina/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

const reader = require('./lib/reader');
28 changes: 28 additions & 0 deletions lab-christina/lib/reader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

const fs = require('fs');


module.exports = (filepath, callback) => {
let pathArray = [];
fs.readFile(filepath[0], 'utf-8', (err, data) => {
if (err) {
return callback(err);
}
pathArray[2] = (data);
fs.readFile(filepath[1], 'utf-8', (err, data) => {
if (err) {
return callback(err);
}
pathArray[1] = (data);
fs.readFile(filepath[2], 'utf-8', (err, data) => {
if (err) {
return callback(err);
}
pathArray[0] = (data);
console.log(pathArray);
callback(null, pathArray);
});
});
});
};
19 changes: 19 additions & 0 deletions lab-christina/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "lab-christina",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest -i",
"test-watch":"test --watch -i"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"jest": "^21.0.2"
},
"dependencies": {
"fs": "0.0.1-security"
}
}