This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return new Promise(async (resolve, reject) => { | |
try { | |
const depnString = JSON.stringify(this.depn); | |
await fs.writeFile(path.join(this.dest, this.fileName), depnString); | |
} catch (err) { | |
reject(err); | |
} | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict" | |
const bodyParser = require('body-parser') | |
const serveStatic = require('serve-static') | |
function wrapper = () => { | |
const locals = {} | |
return (path, callback) => { | |
on, | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import config from '../config' | |
import { User } from '../resources/user/user.model' | |
import jwt from 'jsonwebtoken' | |
export const newToken = user => { | |
return jwt.sign({ id: user.id }, config.secrets.jwt, { | |
expiresIn: config.secrets.jwtExp | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (typeof module !== 'undefined') { | |
var JSONParser = require('../src/main.js'); | |
var expect = require('chai').expect; | |
} | |
describe('JSON Parser', function() { | |
describe('Numbers', function() { | |
it('should work on single-digit', function() { | |
expect(JSONParser(JSON.stringify(1))).to.eql(1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* returns a javascript object from a JSON formatted string | |
* Example json to javascript object: | |
* "5" -> 5 | |
* "'hello'" -> 'hello' | |
* "[]" -> [] | |
* "{}" -> {} | |
* "["hello"]" -> ['hello'] | |
* | |
* For more examples, use the JSON.stringify method in the console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createArray() { | |
this.array = []; | |
} | |
createArray.prototype.push = val => { | |
this.array.push(val); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Declare a function named censor with no parameter. | |
// 1-1. Declare a backpack variable named censorObject, and assign it an empty object. | |
// 1-2. Declare a function named getCensor with two parameters: a string named str1, a string named str2. | |
// 1-2-1. use if statement to check if str2 is not undefined. If so, set censorObject's key to str1, and its value to str2. | |
// 1-2-2. Else, iterate through censorObject using for...in looop | |
// 1-2-2-1. Check if any of keys' strings found on str1's string. If so, replace the string with the value associated with key using regex and String.replace method. | |
// 1-2-2-2. Return str1. | |
// 1-3. Return getCensor. | |
function censor() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Challenge: | |
Create a function censor that accepts no arguments. censor will return a function that will accept either two strings, or one string. When two strings are given, the returned function will hold onto the two strings as a pair, for future use. When one string is given, the returned function will return the same string, except all instances of a first string (of a saved pair) will be replaced with the second string (of a saved pair). | |
*/ | |
// 1. Declare a function named censor with no parameter. | |
// 1-1. Declare a backpack variable named censorObject, and assign it an empty object. | |
// 1-2. Declare a function named getCensor with two parameters: a string named str1, a string named str2. | |
// 1-2-1. use if statement to check if str2 is not undefined. If so, set censorObject's key to str1, and its value to str2. | |
// 1-2-2. Else, iterate through censorObject using for...in looop | |
// 1-2-2-1. Check if any of keys' strings found on str1's string. If so, replace the string with the value associated with key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Challenge: | |
Create a function censor that accepts no arguments. censor will return a function that will accept either two strings, or one string. When two strings are given, the returned function will hold onto the two strings as a pair, for future use. When one string is given, the returned function will return the same string, except all instances of a first string (of a saved pair) will be replaced with the second string (of a saved pair). | |
*/ | |
// 1. Declare a function named censor with no parameter. | |
// 1-1. Declare a backpack variable named censorObject, and assign it an empty object. | |
// 1-2. Declare a function named getCensor with two parameters: a string named str1, a string named str2. | |
// 1-2-1. use if statement to check if str2 is not undefined. If so, set censorObject's key to str1, and its value to str2. | |
// 1-2-2. Else, iterate through censorObject using for...in looop | |
// 1-2-2-1. Check if any of keys' strings found on str1's string. If so, replace the string with the value associated with key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Declare a function named censor with no parameter. | |
// 1-1. Declare a backpack variable named censorObject, and assign it an empty object. | |
// 1-2. Declare a function named getCensor with two parameters: a string named str1, a string named str2. | |
// 1-2-1. use if statement to check if str2 is not undefined. If so, set censorObject's key to str1, and its value to str2. | |
// 1-2-2. Else, iterate through censorObject using for...in looop | |
// 1-2-2-1. Check if any of keys' strings found on str1's string. If so, replace the string with the value associated with key using regex and String.replace method. | |
// 1-2-2-2. Return str1. | |
// 1-3. Return getCensor. | |
function censor() { |