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-matt/.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-matt/.eslintrc
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" ]
}
}
149 changes: 149 additions & 0 deletions lab-matt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@

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

### 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

### Vim ###
# swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]
# session
Session.vim
# temporary
.netrwhist
# auto-generated tag files
tags

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history

### 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,vim,node,linux,windows,visualstudiocode
7 changes: 7 additions & 0 deletions lab-matt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 03: Node Ecosystem
Description: **Lab 03 of Code Fellows JavaScript 401d19** </br>
Author: **Matthew LeBlanc** </br>
Date: **11/29/17**

### `read.files`
has an arity of one that takes in a callback function that returns an error, if there is one, and data. The expected data for `data` would be an array of the file text for three individual files.
46 changes: 46 additions & 0 deletions lab-matt/__test__/reader.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

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

const linebreak = ' \n -------------------------------------------------------------------------------';
const expected = ['I am cat, meow meow meow. Watch me run, lie in sun, fun fun fun.', 'I am mini cooper vroom vroom vroom. Watch me go, drive so fast, be home very soon soon soon.', 'I am poodle, woof woof woof. I chase cat, then steal car, vroom vroom vroom.'];

describe('reader.js', () => {
describe(`reading the files in /assets ${linebreak}`, () => {

test(`recieves an array that includes the text of each .txt file${linebreak}`, (done) => {
read.files((error, data) => {
expect(error).toBeNull();
expect(data).toEqual(expected);
done();
});
});

test(`index [0] of the array is the cat.txt`, (done) => {
read.files((error, data) => {
expect(error).toBeNull();
expect(data[0].includes('I am cat')).toBeTruthy();

done();
});
});

test('index [1] of the array is the mini.txt', (done) => {
read.files((error, data) => {
expect(error).toBeNull();
expect(data[1].includes('I am mini cooper')).toBeTruthy();

done();
});
});

test('index [2] of the array is the poodle.txt', (done) => {
read.files((error, data) => {
expect(error).toBeNull();
expect(data[2].includes('I am poodle')).toBeTruthy();

done();
});
});
});
});
1 change: 1 addition & 0 deletions lab-matt/assets/cats.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I am cat, meow meow meow. Watch me run, lie in sun, fun fun fun.
1 change: 1 addition & 0 deletions lab-matt/assets/mini-cooper.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I am mini cooper vroom vroom vroom. Watch me go, drive so fast, be home very soon soon soon.
1 change: 1 addition & 0 deletions lab-matt/assets/poodle.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I am poodle, woof woof woof. I chase cat, then steal car, vroom vroom vroom.
6 changes: 6 additions & 0 deletions lab-matt/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

// MattL - node package to show all files in specified folder
const read = require('fs-readdir-recursive');

console.log(read(`${__dirname}/assets`));
29 changes: 29 additions & 0 deletions lab-matt/lib/reader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const fs = require('fs');
const readFolder = require('fs-readdir-recursive');

const read = module.exports = {};

const files = [];
let folder = readFolder(`${__dirname}/../assets`);
console.log('all files in assets folder', folder);

read.files = (callback) => {
fs.readFile(`${__dirname}/../assets/cats.txt`, (err, data) => {
if (err) callback(err);
if (files.length < 1) files.push(data.toString());

fs.readFile(`${__dirname}/../assets/mini-cooper.txt`, (err, data) => {
if (err) callback(err);
if (files.length < 2) files.push(data.toString());

fs.readFile(`${__dirname}/../assets/poodle.txt`, (err, data) => {
if (err) callback(err);
if (files.length < 3) files.push(data.toString());

callback(null, files);
});
});
});
};
Loading