Last active
February 27, 2017 16:02
-
-
Save SBejga/5d1aaef02e45a25dddbf16ab0f174815 to your computer and use it in GitHub Desktop.
pwa-3 practice: read json file async with promises (typescript)
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
var fs = require('fs'); | |
//npm install @types/node @types/es6-promise | |
function loadFromJson(filename: string) { | |
//TODO: read files async with Promises | |
} | |
var files: string[] = [ | |
"good.json", "absent.json", "good2.json", "invalid.json", "good3.json" | |
]; | |
//TODO: | |
// Read Files in order of array and abort if error occurs | |
// Hints: | |
// fs.readFile(file: str, (err, data) => {}) | |
// JSON.parse(str): any |
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
{"message": "first file"} |
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
{"message": "second file"} |
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
{"message": "third file"} |
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
{invalid: json} |
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
{ | |
"name": "fspromise", | |
"version": "1.0.0", | |
"description": "", | |
"main": "build/js/fsPromise.js", | |
"scripts": { | |
"demo": "tsc && node build/js/fsPromise.js", | |
"setGist": "gist -o -u 5d1aaef02e45a25dddbf16ab0f174815 fsPromise.ts package.json tsconfig.json good.json good2.json good3.json invalid.json .gitignore" | |
}, | |
"author": "", | |
"license": "Apache-2.0", | |
"devDependencies": { | |
"@types/node": "^6.0.45", | |
"@types/es6-promise": "0.0.32" | |
} | |
} |
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
Show hidden characters
{ | |
"compilerOptions": { | |
"target": "es5", | |
"module": "commonjs", | |
"removeComments": true, | |
"typeRoots": [ | |
"node_modules/@types" | |
], | |
"outDir": "build/js", | |
"inlineSourceMap": true | |
}, | |
"exclude": [ | |
"node_modules" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment