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

# Created by https://www.gitignore.io/api/node,macos,visualstudiocode

### macOS ###
*.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

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


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

# End of https://www.gitignore.io/api/node,macos,visualstudiocodes
18 changes: 18 additions & 0 deletions lab-david/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## reader program for CF-401 JS
This program will read through the specified asset file(s) and render back to the specified amount of character(s) from the file(s). Tests are run through jest.

## read.file function
This function takes file paths to files in an array as a method and and then spits out the first 50 characters of each file into a new array.

## exported values
the reader should export 50 characters from each file in the array.

## installation of dependencies
*dependencies*
- Jest
- Eslint

To install dependencies, run `npm install` to install eslint and jest.

## ipsum generator used
[Monty Python Ipsum](https://montypythonipsum.com/)
18 changes: 18 additions & 0 deletions lab-david/__test__/reader.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

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

describe('reader.test.js', () => {
test('the first 50 characters of each file should be returned if there are no errors', (done) => {

reader.readFile(((error, paths) => {
expect(error).toBeNull();
expect(paths).toBe('array');
}),
(error,newArray) => {
expect(error).toBeNull();
expect(newArray).toEqual([`Not necessarily. I could be arguing in my spare ti`, `Are you suggesting coconuts migrate? You don't fri`, `This is boring. Let's go watch a stoning. Manacles`]);
done();
});
});
});
3 changes: 3 additions & 0 deletions lab-david/assets/flying-circus.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Not necessarily. I could be arguing in my spare time. Nobody expects the Spanish Inquisition! Well, er, yes Mr. Anchovy, but you see your report here says that you are an extremely dull person. You see, our experts describe you as an appallingly dull fellow, unimaginative, timid, lacking in initiative, spineless, easily dominated, no sense of humour, tedious company and irrepressibly drab and awful. And whereas in most professions these would be considerable drawbacks, in chartered accountancy, they're a positive boon.
I object to all this sex on the television. I mean, I keep falling off! I told you to lay off the beans, you whore!
Why is it the world never remembered the name of Johann Gambolputty de von Ausfern-schplenden-schlitter-crasscrenbon-fried-digger-dangle-dongle-dungle-burstein-Von-knacker-thrasher-apple-banger-horowitz-ticolensic-grander-knotty-spelltinkle-grandlich-grumblemeyer-spelterwasser-kurstlich-himbleeisen-bahnwagen-gutenabend-bitte-ein-nürnburger-bratwurstle-gerspurten-mit-zwei-macheluber-hundsfut-gumberaber-shoenendanker-kalbsfleisch-mittler-aucher von Hautkopft of Ulm? This morning, shortly after 11:00, comedy struck this little house on Dibley Road. Sudden, violent comedy.
3 changes: 3 additions & 0 deletions lab-david/assets/holy-grail.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Are you suggesting coconuts migrate? You don't frighten us, English pig dogs. Go and boil your bottoms, you sons of a silly person. I blow my nose at you, so-called "Arthur King," you and all your silly English K-nig-hts.
I'm Brian, and so's my wife! Oh, king eh? Very nice. And how'd you get that, eh? By exploiting the workers. By hanging on to outdated imperialist dogma which perpetuates the economic and social differences in our society.
I don't want to talk to you no more, you empty-headed animal food trough wiper! I fart in your general direction! Your mother was a hamster and your father smelt of elderberries!
3 changes: 3 additions & 0 deletions lab-david/assets/life-of-brian.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This is boring. Let's go watch a stoning. Manacles! Ooooh, my idea of heaven, is to be allowed to be put in manacles. Just for a few hours. They must think the sun shines out your ass, sonny.
I will not have my fwends widiculed by the common soldiewy. Anybody else feel like a little... giggle... when I mention my fwiend... Biggus... Dickus?
At this time, a friend shall lose his friend's hammer and the young shall not know where lieth the things possessed by their fathers that their fathers put there only just the night before, about eight o'clock.
24 changes: 24 additions & 0 deletions lab-david/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

// not even sure if I need this - DELETE ME ?

const fs = require('fs');

let flyingCircusPath = `${__dirname}/data/flying-circus.txt`;
let holyGrailPath = `${__dirname}/../assets/holy-grail.txt`;
let lifeOfBrianPath = `${__dirname}/../assets/life-of-brian.txt`;

fs.flyingCircusPath(flyingCircusPath, (error,data) => {
if(error)
throw(error);
console.log('======== break between ipsums ==========');
console.log(data.toString('utf-8',0,50));

let readFile(filePath,(error,data) => {
if(error)
throw error;

console.log('======== break between ipsums ==========');
console.log(data.toString('utf-8',0,50));
});
});
34 changes: 34 additions & 0 deletions lab-david/lib/reader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

const reader = module.exports = {};
const fs = require('fs');

let filePathsArray =
[
`${__dirname}/../assets/flying-circus.txt`,
`${__dirname}/../assets/holy-grail.txt`,
`${__dirname}/../assets/life-of-brian.txt`,
];

reader.readFile = (paths, callback) => {
let newArray = [];
fs.readFile(filePathsArray[0], (error,data) => {
if(error)
callback(error);
newArray.push(data.toString('utf-8',0,50));

fs.readFile(filePathsArray[1], (error,data) => {
if(error)
callback(error);
newArray.push(data.toString('utf-8',0,50));

fs.readFile(filePathsArray[2], (error,data) => {
if(error)
callback(error);
newArray.push(data.toString('utf-8',0,50));
callback(null,newArray);

});
});
});
};
Loading