Video 22
This commit is contained in:
@@ -21,7 +21,7 @@ yargs.command({
|
||||
type: 'string'
|
||||
}
|
||||
},
|
||||
handler: function(argv) {
|
||||
handler(argv) {
|
||||
notes.addNote(argv.title, argv.body);
|
||||
}
|
||||
});
|
||||
@@ -37,7 +37,7 @@ yargs.command({
|
||||
type: 'string'
|
||||
}
|
||||
},
|
||||
handler: function(argv) {
|
||||
handler(argv) {
|
||||
notes.removeNote(argv.title);
|
||||
}
|
||||
});
|
||||
@@ -46,7 +46,7 @@ yargs.command({
|
||||
yargs.command({
|
||||
command: 'list',
|
||||
describe: 'List notes',
|
||||
handler: function() {
|
||||
handler() {
|
||||
console.log('Listing out all notes');
|
||||
}
|
||||
});
|
||||
@@ -55,7 +55,7 @@ yargs.command({
|
||||
yargs.command({
|
||||
command: 'read',
|
||||
describe: 'Read a note',
|
||||
handler: function() {
|
||||
handler() {
|
||||
console.log('Reading a note');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
const fs = require('fs');
|
||||
const chalk = require('chalk');
|
||||
|
||||
const getNotes = function() {
|
||||
const getNotes = () => {
|
||||
return 'Your notes...'
|
||||
}
|
||||
|
||||
const addNote = function(title, body) {
|
||||
const addNote = (title, body) => {
|
||||
const notes = loadNotes();
|
||||
const duplicateNotes = notes.filter(function(note) {
|
||||
return note.title === title;
|
||||
});
|
||||
const duplicateNotes = notes.filter((note) => note.title === title);
|
||||
|
||||
if (duplicateNotes.length === 0) {
|
||||
notes.push({
|
||||
@@ -24,11 +22,9 @@ const addNote = function(title, body) {
|
||||
}
|
||||
}
|
||||
|
||||
const removeNote = function(title) {
|
||||
const removeNote = (title) => {
|
||||
const notes = loadNotes();
|
||||
const notesToKeep = notes.filter(function(note) {
|
||||
return note.title !== title;
|
||||
});
|
||||
const notesToKeep = notes.filter((note) => note.title !== title);
|
||||
|
||||
if (notes.length > notesToKeep.length) {
|
||||
console.log(chalk.bgGreen.bold('Note removed!'));
|
||||
@@ -38,12 +34,12 @@ const removeNote = function(title) {
|
||||
}
|
||||
}
|
||||
|
||||
const saveNotes = function(notes) {
|
||||
const saveNotes = (notes) => {
|
||||
const dataJSON = JSON.stringify(notes);
|
||||
fs.writeFileSync('notes.json', dataJSON);
|
||||
}
|
||||
|
||||
const loadNotes = function() {
|
||||
const loadNotes = () => {
|
||||
try {
|
||||
const dataBuffer = fs.readFileSync('notes.json');
|
||||
const dataJSON = dataBuffer.toString();
|
||||
|
||||
Reference in New Issue
Block a user