├── LICENSE ├── README.md ├── angular-confirmation-dialog ├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.e2e.json ├── package-lock.json ├── package.json ├── src │ ├── app │ │ ├── app.component.css │ │ ├── app.component.html │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ └── components │ │ │ └── shared │ │ │ └── confirmation-dialog │ │ │ ├── confirmation-dialog.component.css │ │ │ ├── confirmation-dialog.component.html │ │ │ ├── confirmation-dialog.component.spec.ts │ │ │ └── confirmation-dialog.component.ts │ ├── assets │ │ └── .gitkeep │ ├── browserslist │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── karma.conf.js │ ├── main.ts │ ├── polyfills.ts │ ├── styles.css │ ├── test.ts │ ├── tsconfig.app.json │ ├── tsconfig.spec.json │ └── tslint.json ├── tsconfig.json └── tslint.json ├── angular-loader ├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.e2e.json ├── package-lock.json ├── package.json ├── src │ ├── app │ │ ├── app.component.css │ │ ├── app.component.html │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ ├── components │ │ │ └── shared │ │ │ │ └── loader │ │ │ │ ├── loader.component.css │ │ │ │ ├── loader.component.html │ │ │ │ ├── loader.component.spec.ts │ │ │ │ └── loader.component.ts │ │ ├── interceptors │ │ │ └── loader.interceptor.ts │ │ └── services │ │ │ └── loader.service.ts │ ├── assets │ │ └── .gitkeep │ ├── browserslist │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── karma.conf.js │ ├── main.ts │ ├── polyfills.ts │ ├── styles.css │ ├── test.ts │ ├── tsconfig.app.json │ ├── tsconfig.spec.json │ └── tslint.json ├── tsconfig.json └── tslint.json ├── angular-local-storage ├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── browserslist ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── src │ ├── app │ │ ├── app.component.css │ │ ├── app.component.html │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ ├── local-storage.service.spec.ts │ │ └── local-storage.service.ts │ ├── assets │ │ └── .gitkeep │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── main.ts │ ├── polyfills.ts │ ├── styles.css │ └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json └── tslint.json ├── angular-mock-api ├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.e2e.json ├── package-lock.json ├── package.json ├── src │ ├── app │ │ ├── app.component.css │ │ ├── app.component.html │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ └── mock │ │ │ ├── mock.config.ts │ │ │ ├── mock.interceptor.ts │ │ │ └── mock.module.ts │ ├── assets │ │ └── .gitkeep │ ├── browserslist │ ├── environments │ │ ├── environment.mock.ts │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── karma.conf.js │ ├── main.ts │ ├── polyfills.ts │ ├── styles.css │ ├── test.ts │ ├── tsconfig.app.json │ ├── tsconfig.spec.json │ └── tslint.json ├── tsconfig.json └── tslint.json ├── express-serverless-crud ├── .env ├── .gitignore ├── app-local.js ├── app.js ├── docker-compose.yml ├── employee-table-model.json ├── index.js ├── package-lock.json ├── package.json └── routes.js ├── nodejs-csv-to-json ├── .gitignore ├── package-lock.json ├── package.json ├── read-file.js ├── read-stream.js ├── test-data-output-stream.json └── test-data.csv └── nodejs-json-to-csv ├── .gitignore ├── package-lock.json ├── package.json ├── read-file.js ├── read-stream.js ├── test-data-output-stream.csv ├── test-data.csv └── test-data.json /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Viktor Borisov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # first-class-js -------------------------------------------------------------------------------- /angular-confirmation-dialog/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | 8 | # dependencies 9 | /node_modules 10 | 11 | # profiling files 12 | chrome-profiler-events.json 13 | speed-measure-plugin.json 14 | 15 | # IDEs and editors 16 | /.idea 17 | .project 18 | .classpath 19 | .c9/ 20 | *.launch 21 | .settings/ 22 | *.sublime-workspace 23 | 24 | # IDE - VSCode 25 | .vscode/* 26 | !.vscode/settings.json 27 | !.vscode/tasks.json 28 | !.vscode/launch.json 29 | !.vscode/extensions.json 30 | 31 | # misc 32 | /.sass-cache 33 | /connect.lock 34 | /coverage 35 | /libpeerconnection.log 36 | npm-debug.log 37 | yarn-error.log 38 | testem.log 39 | /typings 40 | 41 | # System Files 42 | .DS_Store 43 | Thumbs.db 44 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/README.md: -------------------------------------------------------------------------------- 1 | # AngularConfirmationDialog 2 | LIVE: https://firstclassjs.com/tutorials/angular-confirmation-dialog/ 3 | 4 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 7.1.2. 5 | 6 | ## Development server 7 | 8 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 9 | 10 | ## Code scaffolding 11 | 12 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 13 | 14 | ## Build 15 | 16 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 17 | 18 | ## Running unit tests 19 | 20 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 21 | 22 | ## Running end-to-end tests 23 | 24 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 25 | 26 | ## Further help 27 | 28 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 29 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "angular-confirmation-dialog": { 7 | "root": "", 8 | "sourceRoot": "src", 9 | "projectType": "application", 10 | "prefix": "app", 11 | "schematics": {}, 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/angular-confirmation-dialog", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "src/tsconfig.app.json", 21 | "assets": [ 22 | "src/favicon.ico", 23 | "src/assets" 24 | ], 25 | "styles": [ 26 | "src/styles.css" 27 | ], 28 | "scripts": [] 29 | }, 30 | "configurations": { 31 | "production": { 32 | "fileReplacements": [ 33 | { 34 | "replace": "src/environments/environment.ts", 35 | "with": "src/environments/environment.prod.ts" 36 | } 37 | ], 38 | "optimization": true, 39 | "outputHashing": "all", 40 | "sourceMap": false, 41 | "extractCss": true, 42 | "namedChunks": false, 43 | "aot": true, 44 | "extractLicenses": true, 45 | "vendorChunk": false, 46 | "buildOptimizer": true, 47 | "budgets": [ 48 | { 49 | "type": "initial", 50 | "maximumWarning": "2mb", 51 | "maximumError": "5mb" 52 | } 53 | ] 54 | } 55 | } 56 | }, 57 | "serve": { 58 | "builder": "@angular-devkit/build-angular:dev-server", 59 | "options": { 60 | "browserTarget": "angular-confirmation-dialog:build" 61 | }, 62 | "configurations": { 63 | "production": { 64 | "browserTarget": "angular-confirmation-dialog:build:production" 65 | } 66 | } 67 | }, 68 | "extract-i18n": { 69 | "builder": "@angular-devkit/build-angular:extract-i18n", 70 | "options": { 71 | "browserTarget": "angular-confirmation-dialog:build" 72 | } 73 | }, 74 | "test": { 75 | "builder": "@angular-devkit/build-angular:karma", 76 | "options": { 77 | "main": "src/test.ts", 78 | "polyfills": "src/polyfills.ts", 79 | "tsConfig": "src/tsconfig.spec.json", 80 | "karmaConfig": "src/karma.conf.js", 81 | "styles": [ 82 | "src/styles.css" 83 | ], 84 | "scripts": [], 85 | "assets": [ 86 | "src/favicon.ico", 87 | "src/assets" 88 | ] 89 | } 90 | }, 91 | "lint": { 92 | "builder": "@angular-devkit/build-angular:tslint", 93 | "options": { 94 | "tsConfig": [ 95 | "src/tsconfig.app.json", 96 | "src/tsconfig.spec.json" 97 | ], 98 | "exclude": [ 99 | "**/node_modules/**" 100 | ] 101 | } 102 | } 103 | } 104 | }, 105 | "angular-confirmation-dialog-e2e": { 106 | "root": "e2e/", 107 | "projectType": "application", 108 | "prefix": "", 109 | "architect": { 110 | "e2e": { 111 | "builder": "@angular-devkit/build-angular:protractor", 112 | "options": { 113 | "protractorConfig": "e2e/protractor.conf.js", 114 | "devServerTarget": "angular-confirmation-dialog:serve" 115 | }, 116 | "configurations": { 117 | "production": { 118 | "devServerTarget": "angular-confirmation-dialog:serve:production" 119 | } 120 | } 121 | }, 122 | "lint": { 123 | "builder": "@angular-devkit/build-angular:tslint", 124 | "options": { 125 | "tsConfig": "e2e/tsconfig.e2e.json", 126 | "exclude": [ 127 | "**/node_modules/**" 128 | ] 129 | } 130 | } 131 | } 132 | } 133 | }, 134 | "defaultProject": "angular-confirmation-dialog" 135 | } -------------------------------------------------------------------------------- /angular-confirmation-dialog/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './src/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: require('path').join(__dirname, './tsconfig.e2e.json') 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; -------------------------------------------------------------------------------- /angular-confirmation-dialog/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('workspace-project App', () => { 4 | let page: AppPage; 5 | 6 | beforeEach(() => { 7 | page = new AppPage(); 8 | }); 9 | 10 | it('should display welcome message', () => { 11 | page.navigateTo(); 12 | expect(page.getTitleText()).toEqual('Welcome to angular-confirmation-dialog!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getTitleText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } -------------------------------------------------------------------------------- /angular-confirmation-dialog/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-confirmation-dialog", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "^7.1.4", 15 | "@angular/cdk": "^7.3.3", 16 | "@angular/common": "~7.1.0", 17 | "@angular/compiler": "~7.1.0", 18 | "@angular/core": "~7.1.0", 19 | "@angular/forms": "~7.1.0", 20 | "@angular/material": "^7.3.3", 21 | "@angular/platform-browser": "~7.1.0", 22 | "@angular/platform-browser-dynamic": "~7.1.0", 23 | "@angular/router": "~7.1.0", 24 | "core-js": "^2.5.4", 25 | "rxjs": "~6.3.3", 26 | "tslib": "^1.9.0", 27 | "zone.js": "~0.8.26" 28 | }, 29 | "devDependencies": { 30 | "@angular-devkit/build-angular": "~0.11.0", 31 | "@angular/cli": "~7.1.2", 32 | "@angular/compiler-cli": "~7.1.0", 33 | "@angular/language-service": "~7.1.0", 34 | "@types/node": "~8.9.4", 35 | "@types/jasmine": "~2.8.8", 36 | "@types/jasminewd2": "~2.0.3", 37 | "codelyzer": "~4.5.0", 38 | "jasmine-core": "~2.99.1", 39 | "jasmine-spec-reporter": "~4.2.1", 40 | "karma": "~3.1.1", 41 | "karma-chrome-launcher": "~2.2.0", 42 | "karma-coverage-istanbul-reporter": "~2.0.1", 43 | "karma-jasmine": "~1.1.2", 44 | "karma-jasmine-html-reporter": "^0.2.2", 45 | "protractor": "~5.4.0", 46 | "ts-node": "~7.0.0", 47 | "tslint": "~5.11.0", 48 | "typescript": "~3.1.6" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/app/app.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikobg/first-class-js/68e3820bce279c3b19d12a3a5f766cb27a85ab0a/angular-confirmation-dialog/src/app/app.component.css -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { AppComponent } from './app.component'; 3 | 4 | describe('AppComponent', () => { 5 | beforeEach(async(() => { 6 | TestBed.configureTestingModule({ 7 | declarations: [ 8 | AppComponent 9 | ], 10 | }).compileComponents(); 11 | })); 12 | 13 | it('should create the app', () => { 14 | const fixture = TestBed.createComponent(AppComponent); 15 | const app = fixture.debugElement.componentInstance; 16 | expect(app).toBeTruthy(); 17 | }); 18 | 19 | it(`should have as title 'angular-confirmation-dialog'`, () => { 20 | const fixture = TestBed.createComponent(AppComponent); 21 | const app = fixture.debugElement.componentInstance; 22 | expect(app.title).toEqual('angular-confirmation-dialog'); 23 | }); 24 | 25 | it('should render title in a h1 tag', () => { 26 | const fixture = TestBed.createComponent(AppComponent); 27 | fixture.detectChanges(); 28 | const compiled = fixture.debugElement.nativeElement; 29 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to angular-confirmation-dialog!'); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { MatDialog } from '@angular/material'; 3 | 4 | import { ConfirmationDialogComponent } from './components/shared/confirmation-dialog/confirmation-dialog.component'; 5 | 6 | @Component({ 7 | selector: 'app-root', 8 | templateUrl: './app.component.html', 9 | styleUrls: ['./app.component.css'] 10 | }) 11 | export class AppComponent { 12 | title = 'angular-confirmation-dialog'; 13 | 14 | constructor(public dialog: MatDialog) {} 15 | 16 | openDialog(): void { 17 | const dialogRef = this.dialog.open(ConfirmationDialogComponent, { 18 | width: '350px', 19 | data: "Do you confirm the deletion of this data?" 20 | }); 21 | 22 | dialogRef.afterClosed().subscribe(result => { 23 | if(result) { 24 | console.log('Yes clicked'); 25 | // DO SOMETHING 26 | } 27 | }); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { MatDialogModule } from '@angular/material/dialog'; 4 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 5 | import { MatButtonModule } from '@angular/material/button'; 6 | 7 | import { AppComponent } from './app.component'; 8 | import { ConfirmationDialogComponent } from './components/shared/confirmation-dialog/confirmation-dialog.component'; 9 | 10 | @NgModule({ 11 | declarations: [ 12 | AppComponent, 13 | ConfirmationDialogComponent 14 | ], 15 | imports: [ 16 | BrowserModule, 17 | BrowserAnimationsModule, 18 | MatDialogModule, 19 | MatButtonModule 20 | ], 21 | entryComponents: [ 22 | ConfirmationDialogComponent 23 | ], 24 | providers: [], 25 | bootstrap: [AppComponent] 26 | }) 27 | export class AppModule { } 28 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/app/components/shared/confirmation-dialog/confirmation-dialog.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikobg/first-class-js/68e3820bce279c3b19d12a3a5f766cb27a85ab0a/angular-confirmation-dialog/src/app/components/shared/confirmation-dialog/confirmation-dialog.component.css -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/app/components/shared/confirmation-dialog/confirmation-dialog.component.html: -------------------------------------------------------------------------------- 1 |
2 | {{message}} 3 |
4 |
5 | 6 | 7 |
-------------------------------------------------------------------------------- /angular-confirmation-dialog/src/app/components/shared/confirmation-dialog/confirmation-dialog.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ConfirmationDialogComponent } from './confirmation-dialog.component'; 4 | 5 | describe('ConfirmationDialogComponent', () => { 6 | let component: ConfirmationDialogComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ConfirmationDialogComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ConfirmationDialogComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/app/components/shared/confirmation-dialog/confirmation-dialog.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Inject } from '@angular/core'; 2 | import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; 3 | 4 | @Component({ 5 | selector: 'app-confirmation-dialog', 6 | templateUrl: './confirmation-dialog.component.html', 7 | styleUrls: ['./confirmation-dialog.component.css'] 8 | }) 9 | export class ConfirmationDialogComponent { 10 | constructor( 11 | public dialogRef: MatDialogRef, 12 | @Inject(MAT_DIALOG_DATA) public message: string) { } 13 | 14 | onNoClick(): void { 15 | this.dialogRef.close(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikobg/first-class-js/68e3820bce279c3b19d12a3a5f766cb27a85ab0a/angular-confirmation-dialog/src/assets/.gitkeep -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/browserslist: -------------------------------------------------------------------------------- 1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | # 5 | # For IE 9-11 support, please remove 'not' from the last line of the file and adjust as needed 6 | 7 | > 0.5% 8 | last 2 versions 9 | Firefox ESR 10 | not dead 11 | not IE 9-11 -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikobg/first-class-js/68e3820bce279c3b19d12a3a5f766cb27a85ab0a/angular-confirmation-dialog/src/favicon.ico -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AngularConfirmationDialog 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../coverage'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false 30 | }); 31 | }; -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/weak-map'; 35 | // import 'core-js/es6/set'; 36 | 37 | /** 38 | * If the application will be indexed by Google Search, the following is required. 39 | * Googlebot uses a renderer based on Chrome 41. 40 | * https://developers.google.com/search/docs/guides/rendering 41 | **/ 42 | // import 'core-js/es6/array'; 43 | 44 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 45 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 46 | 47 | /** IE10 and IE11 requires the following for the Reflect API. */ 48 | // import 'core-js/es6/reflect'; 49 | 50 | /** 51 | * Web Animations `@angular/platform-browser/animations` 52 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 53 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 54 | **/ 55 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 56 | 57 | /** 58 | * By default, zone.js will patch all possible macroTask and DomEvents 59 | * user can disable parts of macroTask/DomEvents patch by setting following flags 60 | */ 61 | 62 | // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 63 | // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 64 | // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 65 | 66 | /* 67 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 68 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 69 | */ 70 | // (window as any).__Zone_enable_cross_context_check = true; 71 | 72 | /*************************************************************************************************** 73 | * Zone JS is required by default for Angular itself. 74 | */ 75 | import 'zone.js/dist/zone'; // Included with Angular CLI. 76 | 77 | 78 | /*************************************************************************************************** 79 | * APPLICATION IMPORTS 80 | */ 81 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/styles.css: -------------------------------------------------------------------------------- 1 | @import '~@angular/material/prebuilt-themes/deeppurple-amber.css'; 2 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "types": [] 6 | }, 7 | "exclude": [ 8 | "test.ts", 9 | "**/*.spec.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "test.ts", 12 | "polyfills.ts" 13 | ], 14 | "include": [ 15 | "**/*.spec.ts", 16 | "**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/src/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "app", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "app", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "module": "es2015", 9 | "moduleResolution": "node", 10 | "emitDecoratorMetadata": true, 11 | "experimentalDecorators": true, 12 | "importHelpers": true, 13 | "target": "es5", 14 | "typeRoots": [ 15 | "node_modules/@types" 16 | ], 17 | "lib": [ 18 | "es2018", 19 | "dom" 20 | ] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /angular-confirmation-dialog/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "deprecation": { 15 | "severity": "warn" 16 | }, 17 | "eofline": true, 18 | "forin": true, 19 | "import-blacklist": [ 20 | true, 21 | "rxjs/Rx" 22 | ], 23 | "import-spacing": true, 24 | "indent": [ 25 | true, 26 | "spaces" 27 | ], 28 | "interface-over-type-literal": true, 29 | "label-position": true, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-arg": true, 47 | "no-bitwise": true, 48 | "no-console": [ 49 | true, 50 | "debug", 51 | "info", 52 | "time", 53 | "timeEnd", 54 | "trace" 55 | ], 56 | "no-construct": true, 57 | "no-debugger": true, 58 | "no-duplicate-super": true, 59 | "no-empty": false, 60 | "no-empty-interface": true, 61 | "no-eval": true, 62 | "no-inferrable-types": [ 63 | true, 64 | "ignore-params" 65 | ], 66 | "no-misused-new": true, 67 | "no-non-null-assertion": true, 68 | "no-redundant-jsdoc": true, 69 | "no-shadowed-variable": true, 70 | "no-string-literal": false, 71 | "no-string-throw": true, 72 | "no-switch-case-fall-through": true, 73 | "no-trailing-whitespace": true, 74 | "no-unnecessary-initializer": true, 75 | "no-unused-expression": true, 76 | "no-use-before-declare": true, 77 | "no-var-keyword": true, 78 | "object-literal-sort-keys": false, 79 | "one-line": [ 80 | true, 81 | "check-open-brace", 82 | "check-catch", 83 | "check-else", 84 | "check-whitespace" 85 | ], 86 | "prefer-const": true, 87 | "quotemark": [ 88 | true, 89 | "single" 90 | ], 91 | "radix": true, 92 | "semicolon": [ 93 | true, 94 | "always" 95 | ], 96 | "triple-equals": [ 97 | true, 98 | "allow-null-check" 99 | ], 100 | "typedef-whitespace": [ 101 | true, 102 | { 103 | "call-signature": "nospace", 104 | "index-signature": "nospace", 105 | "parameter": "nospace", 106 | "property-declaration": "nospace", 107 | "variable-declaration": "nospace" 108 | } 109 | ], 110 | "unified-signatures": true, 111 | "variable-name": false, 112 | "whitespace": [ 113 | true, 114 | "check-branch", 115 | "check-decl", 116 | "check-operator", 117 | "check-separator", 118 | "check-type" 119 | ], 120 | "no-output-on-prefix": true, 121 | "use-input-property-decorator": true, 122 | "use-output-property-decorator": true, 123 | "use-host-property-decorator": true, 124 | "no-input-rename": true, 125 | "no-output-rename": true, 126 | "use-life-cycle-interface": true, 127 | "use-pipe-transform-interface": true, 128 | "component-class-suffix": true, 129 | "directive-class-suffix": true 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /angular-loader/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /angular-loader/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | 8 | # dependencies 9 | /node_modules 10 | 11 | # profiling files 12 | chrome-profiler-events.json 13 | speed-measure-plugin.json 14 | 15 | # IDEs and editors 16 | /.idea 17 | .project 18 | .classpath 19 | .c9/ 20 | *.launch 21 | .settings/ 22 | *.sublime-workspace 23 | 24 | # IDE - VSCode 25 | .vscode/* 26 | !.vscode/settings.json 27 | !.vscode/tasks.json 28 | !.vscode/launch.json 29 | !.vscode/extensions.json 30 | 31 | # misc 32 | /.sass-cache 33 | /connect.lock 34 | /coverage 35 | /libpeerconnection.log 36 | npm-debug.log 37 | yarn-error.log 38 | testem.log 39 | /typings 40 | 41 | # System Files 42 | .DS_Store 43 | Thumbs.db 44 | -------------------------------------------------------------------------------- /angular-loader/README.md: -------------------------------------------------------------------------------- 1 | # AngularLoader 2 | LIVE: https://firstclassjs.com/tutorials/angular-loader/ 3 | 4 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 7.1.4. 5 | 6 | ## Development server 7 | 8 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 9 | 10 | ## Code scaffolding 11 | 12 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 13 | 14 | ## Build 15 | 16 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 17 | 18 | ## Running unit tests 19 | 20 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 21 | 22 | ## Running end-to-end tests 23 | 24 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 25 | 26 | ## Further help 27 | 28 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 29 | -------------------------------------------------------------------------------- /angular-loader/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "angular-loader": { 7 | "root": "", 8 | "sourceRoot": "src", 9 | "projectType": "application", 10 | "prefix": "app", 11 | "schematics": {}, 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/angular-loader", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "src/tsconfig.app.json", 21 | "assets": [ 22 | "src/favicon.ico", 23 | "src/assets" 24 | ], 25 | "styles": [ 26 | "src/styles.css" 27 | ], 28 | "scripts": [] 29 | }, 30 | "configurations": { 31 | "production": { 32 | "fileReplacements": [ 33 | { 34 | "replace": "src/environments/environment.ts", 35 | "with": "src/environments/environment.prod.ts" 36 | } 37 | ], 38 | "optimization": true, 39 | "outputHashing": "all", 40 | "sourceMap": false, 41 | "extractCss": true, 42 | "namedChunks": false, 43 | "aot": true, 44 | "extractLicenses": true, 45 | "vendorChunk": false, 46 | "buildOptimizer": true, 47 | "budgets": [ 48 | { 49 | "type": "initial", 50 | "maximumWarning": "2mb", 51 | "maximumError": "5mb" 52 | } 53 | ] 54 | } 55 | } 56 | }, 57 | "serve": { 58 | "builder": "@angular-devkit/build-angular:dev-server", 59 | "options": { 60 | "browserTarget": "angular-loader:build" 61 | }, 62 | "configurations": { 63 | "production": { 64 | "browserTarget": "angular-loader:build:production" 65 | } 66 | } 67 | }, 68 | "extract-i18n": { 69 | "builder": "@angular-devkit/build-angular:extract-i18n", 70 | "options": { 71 | "browserTarget": "angular-loader:build" 72 | } 73 | }, 74 | "test": { 75 | "builder": "@angular-devkit/build-angular:karma", 76 | "options": { 77 | "main": "src/test.ts", 78 | "polyfills": "src/polyfills.ts", 79 | "tsConfig": "src/tsconfig.spec.json", 80 | "karmaConfig": "src/karma.conf.js", 81 | "styles": [ 82 | "src/styles.css" 83 | ], 84 | "scripts": [], 85 | "assets": [ 86 | "src/favicon.ico", 87 | "src/assets" 88 | ] 89 | } 90 | }, 91 | "lint": { 92 | "builder": "@angular-devkit/build-angular:tslint", 93 | "options": { 94 | "tsConfig": [ 95 | "src/tsconfig.app.json", 96 | "src/tsconfig.spec.json" 97 | ], 98 | "exclude": [ 99 | "**/node_modules/**" 100 | ] 101 | } 102 | } 103 | } 104 | }, 105 | "angular-loader-e2e": { 106 | "root": "e2e/", 107 | "projectType": "application", 108 | "prefix": "", 109 | "architect": { 110 | "e2e": { 111 | "builder": "@angular-devkit/build-angular:protractor", 112 | "options": { 113 | "protractorConfig": "e2e/protractor.conf.js", 114 | "devServerTarget": "angular-loader:serve" 115 | }, 116 | "configurations": { 117 | "production": { 118 | "devServerTarget": "angular-loader:serve:production" 119 | } 120 | } 121 | }, 122 | "lint": { 123 | "builder": "@angular-devkit/build-angular:tslint", 124 | "options": { 125 | "tsConfig": "e2e/tsconfig.e2e.json", 126 | "exclude": [ 127 | "**/node_modules/**" 128 | ] 129 | } 130 | } 131 | } 132 | } 133 | }, 134 | "defaultProject": "angular-loader" 135 | } -------------------------------------------------------------------------------- /angular-loader/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './src/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: require('path').join(__dirname, './tsconfig.e2e.json') 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; -------------------------------------------------------------------------------- /angular-loader/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('workspace-project App', () => { 4 | let page: AppPage; 5 | 6 | beforeEach(() => { 7 | page = new AppPage(); 8 | }); 9 | 10 | it('should display welcome message', () => { 11 | page.navigateTo(); 12 | expect(page.getTitleText()).toEqual('Welcome to angular-loader!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /angular-loader/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getTitleText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /angular-loader/e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } -------------------------------------------------------------------------------- /angular-loader/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-loader", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "^7.1.4", 15 | "@angular/cdk": "^7.3.3", 16 | "@angular/common": "~7.1.0", 17 | "@angular/compiler": "~7.1.0", 18 | "@angular/core": "~7.1.0", 19 | "@angular/forms": "~7.1.0", 20 | "@angular/material": "^7.3.3", 21 | "@angular/platform-browser": "~7.1.0", 22 | "@angular/platform-browser-dynamic": "~7.1.0", 23 | "@angular/router": "~7.1.0", 24 | "core-js": "^2.5.4", 25 | "rxjs": "~6.3.3", 26 | "tslib": "^1.9.0", 27 | "zone.js": "~0.8.26" 28 | }, 29 | "devDependencies": { 30 | "@angular-devkit/build-angular": "~0.11.0", 31 | "@angular/cli": "~7.1.4", 32 | "@angular/compiler-cli": "~7.1.0", 33 | "@angular/language-service": "~7.1.0", 34 | "@types/node": "~8.9.4", 35 | "@types/jasmine": "~2.8.8", 36 | "@types/jasminewd2": "~2.0.3", 37 | "codelyzer": "~4.5.0", 38 | "jasmine-core": "~2.99.1", 39 | "jasmine-spec-reporter": "~4.2.1", 40 | "karma": "~3.1.1", 41 | "karma-chrome-launcher": "~2.2.0", 42 | "karma-coverage-istanbul-reporter": "~2.0.1", 43 | "karma-jasmine": "~1.1.2", 44 | "karma-jasmine-html-reporter": "^0.2.2", 45 | "protractor": "~5.4.0", 46 | "ts-node": "~7.0.0", 47 | "tslint": "~5.11.0", 48 | "typescript": "~3.1.6" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /angular-loader/src/app/app.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikobg/first-class-js/68e3820bce279c3b19d12a3a5f766cb27a85ab0a/angular-loader/src/app/app.component.css -------------------------------------------------------------------------------- /angular-loader/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |
5 | -------------------------------------------------------------------------------- /angular-loader/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { AppComponent } from './app.component'; 3 | 4 | describe('AppComponent', () => { 5 | beforeEach(async(() => { 6 | TestBed.configureTestingModule({ 7 | declarations: [ 8 | AppComponent 9 | ], 10 | }).compileComponents(); 11 | })); 12 | 13 | it('should create the app', () => { 14 | const fixture = TestBed.createComponent(AppComponent); 15 | const app = fixture.debugElement.componentInstance; 16 | expect(app).toBeTruthy(); 17 | }); 18 | 19 | it(`should have as title 'angular-loader'`, () => { 20 | const fixture = TestBed.createComponent(AppComponent); 21 | const app = fixture.debugElement.componentInstance; 22 | expect(app.title).toEqual('angular-loader'); 23 | }); 24 | 25 | it('should render title in a h1 tag', () => { 26 | const fixture = TestBed.createComponent(AppComponent); 27 | fixture.detectChanges(); 28 | const compiled = fixture.debugElement.nativeElement; 29 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to angular-loader!'); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /angular-loader/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { HttpClient } from '@angular/common/http'; 3 | 4 | @Component({ 5 | selector: 'app-root', 6 | templateUrl: './app.component.html', 7 | styleUrls: ['./app.component.css'] 8 | }) 9 | export class AppComponent { 10 | title = 'angular-loader'; 11 | 12 | constructor(private http: HttpClient) { } 13 | 14 | callApi() { 15 | this.http.get('https://reqres.in/api/users?page=2') 16 | .subscribe(data => { 17 | console.log(data); 18 | }); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /angular-loader/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; 4 | import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http'; 5 | 6 | import { AppComponent } from './app.component'; 7 | import { LoaderComponent } from './components/shared/loader/loader.component'; 8 | import { LoaderService } from './services/loader.service'; 9 | import { LoaderInterceptor } from './interceptors/loader.interceptor'; 10 | 11 | @NgModule({ 12 | declarations: [ 13 | AppComponent, 14 | LoaderComponent 15 | ], 16 | imports: [ 17 | BrowserModule, 18 | MatProgressSpinnerModule, 19 | HttpClientModule 20 | ], 21 | providers: [ 22 | LoaderService, 23 | { provide: HTTP_INTERCEPTORS, useClass: LoaderInterceptor, multi: true }, 24 | ], 25 | bootstrap: [AppComponent] 26 | }) 27 | export class AppModule { } 28 | -------------------------------------------------------------------------------- /angular-loader/src/app/components/shared/loader/loader.component.css: -------------------------------------------------------------------------------- 1 | .overlay { 2 | position:fixed; 3 | display:block; 4 | width:100%; 5 | height:100%; 6 | top:0; 7 | left:0; 8 | background-color:rgba(74,74,74,.8); 9 | z-index:99999; 10 | } 11 | 12 | .spinner { 13 | position: absolute; 14 | top: 50%; 15 | left: 50%; 16 | transform: translate(-50%,-50%); 17 | } -------------------------------------------------------------------------------- /angular-loader/src/app/components/shared/loader/loader.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
-------------------------------------------------------------------------------- /angular-loader/src/app/components/shared/loader/loader.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { LoaderComponent } from './loader.component'; 4 | 5 | describe('LoaderComponent', () => { 6 | let component: LoaderComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ LoaderComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(LoaderComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /angular-loader/src/app/components/shared/loader/loader.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { Subject } from 'rxjs'; 3 | 4 | import { LoaderService } from '../../../services/loader.service'; 5 | 6 | @Component({ 7 | selector: 'app-loader', 8 | templateUrl: './loader.component.html', 9 | styleUrls: ['./loader.component.css'] 10 | }) 11 | export class LoaderComponent { 12 | color = 'primary'; 13 | mode = 'indeterminate'; 14 | value = 50; 15 | isLoading: Subject = this.loaderService.isLoading; 16 | 17 | constructor(private loaderService: LoaderService){} 18 | } 19 | -------------------------------------------------------------------------------- /angular-loader/src/app/interceptors/loader.interceptor.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from "@angular/core"; 2 | import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from "@angular/common/http"; 3 | import { Observable } from "rxjs"; 4 | import { finalize } from "rxjs/operators"; 5 | 6 | import { LoaderService } from '../services/loader.service'; 7 | 8 | @Injectable() 9 | export class LoaderInterceptor implements HttpInterceptor { 10 | 11 | constructor(public loaderService: LoaderService) { } 12 | 13 | intercept(req: HttpRequest, next: HttpHandler): Observable> { 14 | this.loaderService.show(); 15 | return next.handle(req).pipe( 16 | finalize(() => this.loaderService.hide()) 17 | ); 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /angular-loader/src/app/services/loader.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Subject } from 'rxjs'; 3 | 4 | @Injectable() 5 | export class LoaderService { 6 | isLoading = new Subject(); 7 | 8 | show() { 9 | this.isLoading.next(true); 10 | } 11 | 12 | hide() { 13 | this.isLoading.next(false); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /angular-loader/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikobg/first-class-js/68e3820bce279c3b19d12a3a5f766cb27a85ab0a/angular-loader/src/assets/.gitkeep -------------------------------------------------------------------------------- /angular-loader/src/browserslist: -------------------------------------------------------------------------------- 1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | # 5 | # For IE 9-11 support, please remove 'not' from the last line of the file and adjust as needed 6 | 7 | > 0.5% 8 | last 2 versions 9 | Firefox ESR 10 | not dead 11 | not IE 9-11 -------------------------------------------------------------------------------- /angular-loader/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /angular-loader/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /angular-loader/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikobg/first-class-js/68e3820bce279c3b19d12a3a5f766cb27a85ab0a/angular-loader/src/favicon.ico -------------------------------------------------------------------------------- /angular-loader/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AngularLoader 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /angular-loader/src/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../coverage'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false 30 | }); 31 | }; -------------------------------------------------------------------------------- /angular-loader/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /angular-loader/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10, IE11, and Chrome <55 requires all of the following polyfills. 22 | * This also includes Android Emulators with older versions of Chrome and Google Search/Googlebot 23 | */ 24 | 25 | // import 'core-js/es6/symbol'; 26 | // import 'core-js/es6/object'; 27 | // import 'core-js/es6/function'; 28 | // import 'core-js/es6/parse-int'; 29 | // import 'core-js/es6/parse-float'; 30 | // import 'core-js/es6/number'; 31 | // import 'core-js/es6/math'; 32 | // import 'core-js/es6/string'; 33 | // import 'core-js/es6/date'; 34 | // import 'core-js/es6/array'; 35 | // import 'core-js/es6/regexp'; 36 | // import 'core-js/es6/map'; 37 | // import 'core-js/es6/weak-map'; 38 | // import 'core-js/es6/set'; 39 | 40 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 41 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 42 | 43 | /** IE10 and IE11 requires the following for the Reflect API. */ 44 | // import 'core-js/es6/reflect'; 45 | 46 | /** 47 | * Web Animations `@angular/platform-browser/animations` 48 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 49 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 50 | */ 51 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 52 | 53 | /** 54 | * By default, zone.js will patch all possible macroTask and DomEvents 55 | * user can disable parts of macroTask/DomEvents patch by setting following flags 56 | * because those flags need to be set before `zone.js` being loaded, and webpack 57 | * will put import in the top of bundle, so user need to create a separate file 58 | * in this directory (for example: zone-flags.ts), and put the following flags 59 | * into that file, and then add the following code before importing zone.js. 60 | * import './zone-flags.ts'; 61 | * 62 | * The flags allowed in zone-flags.ts are listed here. 63 | * 64 | * The following flags will work for all browsers. 65 | * 66 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 67 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 68 | * (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 69 | * 70 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 71 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 72 | * 73 | * (window as any).__Zone_enable_cross_context_check = true; 74 | * 75 | */ 76 | 77 | /*************************************************************************************************** 78 | * Zone JS is required by default for Angular itself. 79 | */ 80 | import 'zone.js/dist/zone'; // Included with Angular CLI. 81 | 82 | 83 | /*************************************************************************************************** 84 | * APPLICATION IMPORTS 85 | */ 86 | -------------------------------------------------------------------------------- /angular-loader/src/styles.css: -------------------------------------------------------------------------------- 1 | @import '~@angular/material/prebuilt-themes/deeppurple-amber.css'; 2 | -------------------------------------------------------------------------------- /angular-loader/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /angular-loader/src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "types": [] 6 | }, 7 | "exclude": [ 8 | "test.ts", 9 | "**/*.spec.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /angular-loader/src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "test.ts", 12 | "polyfills.ts" 13 | ], 14 | "include": [ 15 | "**/*.spec.ts", 16 | "**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /angular-loader/src/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "app", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "app", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /angular-loader/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "module": "es2015", 9 | "moduleResolution": "node", 10 | "emitDecoratorMetadata": true, 11 | "experimentalDecorators": true, 12 | "importHelpers": true, 13 | "target": "es5", 14 | "typeRoots": [ 15 | "node_modules/@types" 16 | ], 17 | "lib": [ 18 | "es2018", 19 | "dom" 20 | ] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /angular-loader/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "deprecation": { 15 | "severity": "warn" 16 | }, 17 | "eofline": true, 18 | "forin": true, 19 | "import-blacklist": [ 20 | true, 21 | "rxjs/Rx" 22 | ], 23 | "import-spacing": true, 24 | "indent": [ 25 | true, 26 | "spaces" 27 | ], 28 | "interface-over-type-literal": true, 29 | "label-position": true, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-arg": true, 47 | "no-bitwise": true, 48 | "no-console": [ 49 | true, 50 | "debug", 51 | "info", 52 | "time", 53 | "timeEnd", 54 | "trace" 55 | ], 56 | "no-construct": true, 57 | "no-debugger": true, 58 | "no-duplicate-super": true, 59 | "no-empty": false, 60 | "no-empty-interface": true, 61 | "no-eval": true, 62 | "no-inferrable-types": [ 63 | true, 64 | "ignore-params" 65 | ], 66 | "no-misused-new": true, 67 | "no-non-null-assertion": true, 68 | "no-redundant-jsdoc": true, 69 | "no-shadowed-variable": true, 70 | "no-string-literal": false, 71 | "no-string-throw": true, 72 | "no-switch-case-fall-through": true, 73 | "no-trailing-whitespace": true, 74 | "no-unnecessary-initializer": true, 75 | "no-unused-expression": true, 76 | "no-use-before-declare": true, 77 | "no-var-keyword": true, 78 | "object-literal-sort-keys": false, 79 | "one-line": [ 80 | true, 81 | "check-open-brace", 82 | "check-catch", 83 | "check-else", 84 | "check-whitespace" 85 | ], 86 | "prefer-const": true, 87 | "quotemark": [ 88 | true, 89 | "single" 90 | ], 91 | "radix": true, 92 | "semicolon": [ 93 | true, 94 | "always" 95 | ], 96 | "triple-equals": [ 97 | true, 98 | "allow-null-check" 99 | ], 100 | "typedef-whitespace": [ 101 | true, 102 | { 103 | "call-signature": "nospace", 104 | "index-signature": "nospace", 105 | "parameter": "nospace", 106 | "property-declaration": "nospace", 107 | "variable-declaration": "nospace" 108 | } 109 | ], 110 | "unified-signatures": true, 111 | "variable-name": false, 112 | "whitespace": [ 113 | true, 114 | "check-branch", 115 | "check-decl", 116 | "check-operator", 117 | "check-separator", 118 | "check-type" 119 | ], 120 | "no-output-on-prefix": true, 121 | "use-input-property-decorator": true, 122 | "use-output-property-decorator": true, 123 | "use-host-property-decorator": true, 124 | "no-input-rename": true, 125 | "no-output-rename": true, 126 | "use-life-cycle-interface": true, 127 | "use-pipe-transform-interface": true, 128 | "component-class-suffix": true, 129 | "directive-class-suffix": true 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /angular-local-storage/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.ts] 12 | quote_type = single 13 | 14 | [*.md] 15 | max_line_length = off 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /angular-local-storage/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /angular-local-storage/README.md: -------------------------------------------------------------------------------- 1 | # AngularLocalStorage 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.1. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 28 | -------------------------------------------------------------------------------- /angular-local-storage/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "angular-local-storage": { 7 | "projectType": "application", 8 | "schematics": {}, 9 | "root": "", 10 | "sourceRoot": "src", 11 | "prefix": "app", 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/angular-local-storage", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "tsconfig.app.json", 21 | "aot": true, 22 | "assets": [ 23 | "src/favicon.ico", 24 | "src/assets" 25 | ], 26 | "styles": [ 27 | "src/styles.css" 28 | ], 29 | "scripts": [] 30 | }, 31 | "configurations": { 32 | "production": { 33 | "fileReplacements": [ 34 | { 35 | "replace": "src/environments/environment.ts", 36 | "with": "src/environments/environment.prod.ts" 37 | } 38 | ], 39 | "optimization": true, 40 | "outputHashing": "all", 41 | "sourceMap": false, 42 | "extractCss": true, 43 | "namedChunks": false, 44 | "extractLicenses": true, 45 | "vendorChunk": false, 46 | "buildOptimizer": true, 47 | "budgets": [ 48 | { 49 | "type": "initial", 50 | "maximumWarning": "2mb", 51 | "maximumError": "5mb" 52 | }, 53 | { 54 | "type": "anyComponentStyle", 55 | "maximumWarning": "6kb", 56 | "maximumError": "10kb" 57 | } 58 | ] 59 | } 60 | } 61 | }, 62 | "serve": { 63 | "builder": "@angular-devkit/build-angular:dev-server", 64 | "options": { 65 | "browserTarget": "angular-local-storage:build" 66 | }, 67 | "configurations": { 68 | "production": { 69 | "browserTarget": "angular-local-storage:build:production" 70 | } 71 | } 72 | }, 73 | "extract-i18n": { 74 | "builder": "@angular-devkit/build-angular:extract-i18n", 75 | "options": { 76 | "browserTarget": "angular-local-storage:build" 77 | } 78 | }, 79 | "test": { 80 | "builder": "@angular-devkit/build-angular:karma", 81 | "options": { 82 | "main": "src/test.ts", 83 | "polyfills": "src/polyfills.ts", 84 | "tsConfig": "tsconfig.spec.json", 85 | "karmaConfig": "karma.conf.js", 86 | "assets": [ 87 | "src/favicon.ico", 88 | "src/assets" 89 | ], 90 | "styles": [ 91 | "src/styles.css" 92 | ], 93 | "scripts": [] 94 | } 95 | }, 96 | "lint": { 97 | "builder": "@angular-devkit/build-angular:tslint", 98 | "options": { 99 | "tsConfig": [ 100 | "tsconfig.app.json", 101 | "tsconfig.spec.json", 102 | "e2e/tsconfig.json" 103 | ], 104 | "exclude": [ 105 | "**/node_modules/**" 106 | ] 107 | } 108 | }, 109 | "e2e": { 110 | "builder": "@angular-devkit/build-angular:protractor", 111 | "options": { 112 | "protractorConfig": "e2e/protractor.conf.js", 113 | "devServerTarget": "angular-local-storage:serve" 114 | }, 115 | "configurations": { 116 | "production": { 117 | "devServerTarget": "angular-local-storage:serve:production" 118 | } 119 | } 120 | } 121 | } 122 | }}, 123 | "defaultProject": "angular-local-storage" 124 | } 125 | -------------------------------------------------------------------------------- /angular-local-storage/browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /angular-local-storage/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | browserName: 'chrome' 17 | }, 18 | directConnect: true, 19 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 31 | } 32 | }; -------------------------------------------------------------------------------- /angular-local-storage/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('angular-local-storage app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /angular-local-storage/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo(): Promise { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText(): Promise { 9 | return element(by.css('app-root .content span')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /angular-local-storage/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /angular-local-storage/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, './coverage/angular-local-storage'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /angular-local-storage/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-local-storage", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "~9.1.1", 15 | "@angular/common": "~9.1.1", 16 | "@angular/compiler": "~9.1.1", 17 | "@angular/core": "~9.1.1", 18 | "@angular/forms": "~9.1.1", 19 | "@angular/platform-browser": "~9.1.1", 20 | "@angular/platform-browser-dynamic": "~9.1.1", 21 | "@angular/router": "~9.1.1", 22 | "rxjs": "~6.5.4", 23 | "tslib": "^1.10.0", 24 | "zone.js": "~0.10.2" 25 | }, 26 | "devDependencies": { 27 | "@angular-devkit/build-angular": "~0.901.1", 28 | "@angular/cli": "~9.1.1", 29 | "@angular/compiler-cli": "~9.1.1", 30 | "@angular/language-service": "~9.1.1", 31 | "@types/node": "^12.11.1", 32 | "@types/jasmine": "~3.5.0", 33 | "@types/jasminewd2": "~2.0.3", 34 | "codelyzer": "^5.1.2", 35 | "jasmine-core": "~3.5.0", 36 | "jasmine-spec-reporter": "~4.2.1", 37 | "karma": "~4.4.1", 38 | "karma-chrome-launcher": "~3.1.0", 39 | "karma-coverage-istanbul-reporter": "~2.1.0", 40 | "karma-jasmine": "~3.0.1", 41 | "karma-jasmine-html-reporter": "^1.4.2", 42 | "protractor": "~5.4.3", 43 | "ts-node": "~8.3.0", 44 | "tslint": "~6.1.0", 45 | "typescript": "~3.8.3" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /angular-local-storage/src/app/app.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikobg/first-class-js/68e3820bce279c3b19d12a3a5f766cb27a85ab0a/angular-local-storage/src/app/app.component.css -------------------------------------------------------------------------------- /angular-local-storage/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | {{ localStorageChanges.type }} 5 | {{ localStorageChanges.key }} 6 | {{ localStorageChanges.value }} 7 |
-------------------------------------------------------------------------------- /angular-local-storage/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { AppComponent } from './app.component'; 3 | 4 | describe('AppComponent', () => { 5 | beforeEach(async(() => { 6 | TestBed.configureTestingModule({ 7 | declarations: [ 8 | AppComponent 9 | ], 10 | }).compileComponents(); 11 | })); 12 | 13 | it('should create the app', () => { 14 | const fixture = TestBed.createComponent(AppComponent); 15 | const app = fixture.componentInstance; 16 | expect(app).toBeTruthy(); 17 | }); 18 | 19 | it(`should have as title 'angular-local-storage'`, () => { 20 | const fixture = TestBed.createComponent(AppComponent); 21 | const app = fixture.componentInstance; 22 | expect(app.title).toEqual('angular-local-storage'); 23 | }); 24 | 25 | it('should render title', () => { 26 | const fixture = TestBed.createComponent(AppComponent); 27 | fixture.detectChanges(); 28 | const compiled = fixture.nativeElement; 29 | expect(compiled.querySelector('.content span').textContent).toContain('angular-local-storage app is running!'); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /angular-local-storage/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { LocalStorageService } from './local-storage.service'; 3 | 4 | @Component({ 5 | selector: 'app-root', 6 | templateUrl: './app.component.html', 7 | styleUrls: ['./app.component.css'] 8 | }) 9 | export class AppComponent { 10 | localStorageChanges$ = this.localStorageService.changes$; 11 | 12 | constructor(private localStorageService: LocalStorageService) {} 13 | persist(key: string, value: any) { 14 | this.localStorageService.set(key, value); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /angular-local-storage/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | 4 | import { AppComponent } from './app.component'; 5 | 6 | @NgModule({ 7 | declarations: [ 8 | AppComponent 9 | ], 10 | imports: [ 11 | BrowserModule 12 | ], 13 | providers: [], 14 | bootstrap: [AppComponent] 15 | }) 16 | export class AppModule { } 17 | -------------------------------------------------------------------------------- /angular-local-storage/src/app/local-storage.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { LocalStorageService } from './local-storage.service'; 4 | 5 | describe('LocalStorageService', () => { 6 | let service: LocalStorageService; 7 | 8 | beforeEach(() => { 9 | TestBed.configureTestingModule({}); 10 | service = TestBed.inject(LocalStorageService); 11 | }); 12 | 13 | it('should be created', () => { 14 | expect(service).toBeTruthy(); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /angular-local-storage/src/app/local-storage.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Subject } from 'rxjs'; 3 | 4 | @Injectable({ 5 | providedIn: 'root' 6 | }) 7 | export class LocalStorageService { 8 | localStorage: Storage; 9 | 10 | changes$ = new Subject(); 11 | 12 | constructor() { 13 | this.localStorage = window.localStorage; 14 | } 15 | 16 | get(key: string): any { 17 | if (this.isLocalStorageSupported) { 18 | return JSON.parse(this.localStorage.getItem(key)); 19 | } 20 | 21 | return null; 22 | } 23 | 24 | set(key: string, value: any): boolean { 25 | if (this.isLocalStorageSupported) { 26 | this.localStorage.setItem(key, JSON.stringify(value)); 27 | this.changes$.next({ 28 | type: 'set', 29 | key, 30 | value 31 | }); 32 | return true; 33 | } 34 | 35 | return false; 36 | } 37 | 38 | remove(key: string): boolean { 39 | if (this.isLocalStorageSupported) { 40 | this.localStorage.removeItem(key); 41 | this.changes$.next({ 42 | type: 'remove', 43 | key 44 | }); 45 | return true; 46 | } 47 | 48 | return false; 49 | } 50 | 51 | get isLocalStorageSupported(): boolean { 52 | return !!this.localStorage 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /angular-local-storage/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikobg/first-class-js/68e3820bce279c3b19d12a3a5f766cb27a85ab0a/angular-local-storage/src/assets/.gitkeep -------------------------------------------------------------------------------- /angular-local-storage/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /angular-local-storage/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /angular-local-storage/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikobg/first-class-js/68e3820bce279c3b19d12a3a5f766cb27a85ab0a/angular-local-storage/src/favicon.ico -------------------------------------------------------------------------------- /angular-local-storage/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AngularLocalStorage 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /angular-local-storage/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /angular-local-storage/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | -------------------------------------------------------------------------------- /angular-local-storage/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /angular-local-storage/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: { 11 | context(path: string, deep?: boolean, filter?: RegExp): { 12 | keys(): string[]; 13 | (id: string): T; 14 | }; 15 | }; 16 | 17 | // First, initialize the Angular testing environment. 18 | getTestBed().initTestEnvironment( 19 | BrowserDynamicTestingModule, 20 | platformBrowserDynamicTesting() 21 | ); 22 | // Then we find all the tests. 23 | const context = require.context('./', true, /\.spec\.ts$/); 24 | // And load the modules. 25 | context.keys().map(context); 26 | -------------------------------------------------------------------------------- /angular-local-storage/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": [ 8 | "src/main.ts", 9 | "src/polyfills.ts" 10 | ], 11 | "include": [ 12 | "src/**/*.d.ts" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /angular-local-storage/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "lib": [ 15 | "es2018", 16 | "dom" 17 | ] 18 | }, 19 | "angularCompilerOptions": { 20 | "fullTemplateTypeCheck": true, 21 | "strictInjectionParameters": true 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /angular-local-storage/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /angular-local-storage/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "align": { 5 | "options": [ 6 | "parameters", 7 | "statements" 8 | ] 9 | }, 10 | "array-type": false, 11 | "arrow-return-shorthand": true, 12 | "curly": true, 13 | "deprecation": { 14 | "severity": "warning" 15 | }, 16 | "component-class-suffix": true, 17 | "contextual-lifecycle": true, 18 | "directive-class-suffix": true, 19 | "directive-selector": [ 20 | true, 21 | "attribute", 22 | "app", 23 | "camelCase" 24 | ], 25 | "component-selector": [ 26 | true, 27 | "element", 28 | "app", 29 | "kebab-case" 30 | ], 31 | "eofline": true, 32 | "import-blacklist": [ 33 | true, 34 | "rxjs/Rx" 35 | ], 36 | "import-spacing": true, 37 | "indent": { 38 | "options": [ 39 | "spaces" 40 | ] 41 | }, 42 | "max-classes-per-file": false, 43 | "max-line-length": [ 44 | true, 45 | 140 46 | ], 47 | "member-ordering": [ 48 | true, 49 | { 50 | "order": [ 51 | "static-field", 52 | "instance-field", 53 | "static-method", 54 | "instance-method" 55 | ] 56 | } 57 | ], 58 | "no-console": [ 59 | true, 60 | "debug", 61 | "info", 62 | "time", 63 | "timeEnd", 64 | "trace" 65 | ], 66 | "no-empty": false, 67 | "no-inferrable-types": [ 68 | true, 69 | "ignore-params" 70 | ], 71 | "no-non-null-assertion": true, 72 | "no-redundant-jsdoc": true, 73 | "no-switch-case-fall-through": true, 74 | "no-var-requires": false, 75 | "object-literal-key-quotes": [ 76 | true, 77 | "as-needed" 78 | ], 79 | "quotemark": [ 80 | true, 81 | "single" 82 | ], 83 | "semicolon": { 84 | "options": [ 85 | "always" 86 | ] 87 | }, 88 | "space-before-function-paren": { 89 | "options": { 90 | "anonymous": "never", 91 | "asyncArrow": "always", 92 | "constructor": "never", 93 | "method": "never", 94 | "named": "never" 95 | } 96 | }, 97 | "typedef-whitespace": { 98 | "options": [ 99 | { 100 | "call-signature": "nospace", 101 | "index-signature": "nospace", 102 | "parameter": "nospace", 103 | "property-declaration": "nospace", 104 | "variable-declaration": "nospace" 105 | }, 106 | { 107 | "call-signature": "onespace", 108 | "index-signature": "onespace", 109 | "parameter": "onespace", 110 | "property-declaration": "onespace", 111 | "variable-declaration": "onespace" 112 | } 113 | ] 114 | }, 115 | "variable-name": { 116 | "options": [ 117 | "ban-keywords", 118 | "check-format", 119 | "allow-pascal-case" 120 | ] 121 | }, 122 | "whitespace": { 123 | "options": [ 124 | "check-branch", 125 | "check-decl", 126 | "check-operator", 127 | "check-separator", 128 | "check-type", 129 | "check-typecast" 130 | ] 131 | }, 132 | "no-conflicting-lifecycle": true, 133 | "no-host-metadata-property": true, 134 | "no-input-rename": true, 135 | "no-inputs-metadata-property": true, 136 | "no-output-native": true, 137 | "no-output-on-prefix": true, 138 | "no-output-rename": true, 139 | "no-outputs-metadata-property": true, 140 | "template-banana-in-box": true, 141 | "template-no-negated-async": true, 142 | "use-lifecycle-interface": true, 143 | "use-pipe-transform-interface": true 144 | }, 145 | "rulesDirectory": [ 146 | "codelyzer" 147 | ] 148 | } -------------------------------------------------------------------------------- /angular-mock-api/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /angular-mock-api/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | 8 | # dependencies 9 | /node_modules 10 | 11 | # profiling files 12 | chrome-profiler-events.json 13 | speed-measure-plugin.json 14 | 15 | # IDEs and editors 16 | /.idea 17 | .project 18 | .classpath 19 | .c9/ 20 | *.launch 21 | .settings/ 22 | *.sublime-workspace 23 | 24 | # IDE - VSCode 25 | .vscode/* 26 | !.vscode/settings.json 27 | !.vscode/tasks.json 28 | !.vscode/launch.json 29 | !.vscode/extensions.json 30 | 31 | # misc 32 | /.sass-cache 33 | /connect.lock 34 | /coverage 35 | /libpeerconnection.log 36 | npm-debug.log 37 | yarn-error.log 38 | testem.log 39 | /typings 40 | 41 | # System Files 42 | .DS_Store 43 | Thumbs.db 44 | -------------------------------------------------------------------------------- /angular-mock-api/README.md: -------------------------------------------------------------------------------- 1 | # AngularMockApi 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 7.1.2. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 28 | -------------------------------------------------------------------------------- /angular-mock-api/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "angular-mock-api": { 7 | "root": "", 8 | "sourceRoot": "src", 9 | "projectType": "application", 10 | "prefix": "app", 11 | "schematics": {}, 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/angular-mock-api", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "src/tsconfig.app.json", 21 | "assets": [ 22 | "src/favicon.ico", 23 | "src/assets" 24 | ], 25 | "styles": [ 26 | "src/styles.css" 27 | ], 28 | "scripts": [] 29 | }, 30 | "configurations": { 31 | "production": { 32 | "fileReplacements": [ 33 | { 34 | "replace": "src/environments/environment.ts", 35 | "with": "src/environments/environment.prod.ts" 36 | } 37 | ], 38 | "optimization": true, 39 | "outputHashing": "all", 40 | "sourceMap": false, 41 | "extractCss": true, 42 | "namedChunks": false, 43 | "aot": true, 44 | "extractLicenses": true, 45 | "vendorChunk": false, 46 | "buildOptimizer": true, 47 | "budgets": [ 48 | { 49 | "type": "initial", 50 | "maximumWarning": "2mb", 51 | "maximumError": "5mb" 52 | } 53 | ] 54 | }, 55 | "mock": { 56 | "fileReplacements": [ 57 | { 58 | "replace": "src/environments/environment.ts", 59 | "with": "src/environments/environment.mock.ts" 60 | } 61 | ] 62 | } 63 | } 64 | }, 65 | "serve": { 66 | "builder": "@angular-devkit/build-angular:dev-server", 67 | "options": { 68 | "browserTarget": "angular-mock-api:build" 69 | }, 70 | "configurations": { 71 | "production": { 72 | "browserTarget": "angular-mock-api:build:production" 73 | }, 74 | "mock": { 75 | "browserTarget": "angular-mock-api:build:mock" 76 | } 77 | } 78 | }, 79 | "extract-i18n": { 80 | "builder": "@angular-devkit/build-angular:extract-i18n", 81 | "options": { 82 | "browserTarget": "angular-mock-api:build" 83 | } 84 | }, 85 | "test": { 86 | "builder": "@angular-devkit/build-angular:karma", 87 | "options": { 88 | "main": "src/test.ts", 89 | "polyfills": "src/polyfills.ts", 90 | "tsConfig": "src/tsconfig.spec.json", 91 | "karmaConfig": "src/karma.conf.js", 92 | "styles": [ 93 | "src/styles.css" 94 | ], 95 | "scripts": [], 96 | "assets": [ 97 | "src/favicon.ico", 98 | "src/assets" 99 | ] 100 | } 101 | }, 102 | "lint": { 103 | "builder": "@angular-devkit/build-angular:tslint", 104 | "options": { 105 | "tsConfig": [ 106 | "src/tsconfig.app.json", 107 | "src/tsconfig.spec.json" 108 | ], 109 | "exclude": [ 110 | "**/node_modules/**" 111 | ] 112 | } 113 | } 114 | } 115 | }, 116 | "angular-mock-api-e2e": { 117 | "root": "e2e/", 118 | "projectType": "application", 119 | "prefix": "", 120 | "architect": { 121 | "e2e": { 122 | "builder": "@angular-devkit/build-angular:protractor", 123 | "options": { 124 | "protractorConfig": "e2e/protractor.conf.js", 125 | "devServerTarget": "angular-mock-api:serve" 126 | }, 127 | "configurations": { 128 | "production": { 129 | "devServerTarget": "angular-mock-api:serve:production" 130 | } 131 | } 132 | }, 133 | "lint": { 134 | "builder": "@angular-devkit/build-angular:tslint", 135 | "options": { 136 | "tsConfig": "e2e/tsconfig.e2e.json", 137 | "exclude": [ 138 | "**/node_modules/**" 139 | ] 140 | } 141 | } 142 | } 143 | } 144 | }, 145 | "defaultProject": "angular-mock-api" 146 | } -------------------------------------------------------------------------------- /angular-mock-api/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './src/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: require('path').join(__dirname, './tsconfig.e2e.json') 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; -------------------------------------------------------------------------------- /angular-mock-api/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('workspace-project App', () => { 4 | let page: AppPage; 5 | 6 | beforeEach(() => { 7 | page = new AppPage(); 8 | }); 9 | 10 | it('should display welcome message', () => { 11 | page.navigateTo(); 12 | expect(page.getTitleText()).toEqual('Welcome to angular-mock-api!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /angular-mock-api/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getTitleText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /angular-mock-api/e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } -------------------------------------------------------------------------------- /angular-mock-api/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-mock-api", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "start:mock": "ng serve --c=mock", 8 | "build": "ng build", 9 | "test": "ng test", 10 | "lint": "ng lint", 11 | "e2e": "ng e2e" 12 | }, 13 | "private": true, 14 | "dependencies": { 15 | "@angular/animations": "~7.1.0", 16 | "@angular/common": "~7.1.0", 17 | "@angular/compiler": "~7.1.0", 18 | "@angular/core": "~7.1.0", 19 | "@angular/forms": "~7.1.0", 20 | "@angular/platform-browser": "~7.1.0", 21 | "@angular/platform-browser-dynamic": "~7.1.0", 22 | "@angular/router": "~7.1.0", 23 | "core-js": "^2.5.4", 24 | "rxjs": "~6.3.3", 25 | "tslib": "^1.9.0", 26 | "zone.js": "~0.8.26" 27 | }, 28 | "devDependencies": { 29 | "@angular-devkit/build-angular": "~0.11.0", 30 | "@angular/cli": "~7.1.2", 31 | "@angular/compiler-cli": "~7.1.0", 32 | "@angular/language-service": "~7.1.0", 33 | "@types/node": "~8.9.4", 34 | "@types/jasmine": "~2.8.8", 35 | "@types/jasminewd2": "~2.0.3", 36 | "codelyzer": "~4.5.0", 37 | "jasmine-core": "~2.99.1", 38 | "jasmine-spec-reporter": "~4.2.1", 39 | "karma": "~3.1.1", 40 | "karma-chrome-launcher": "~2.2.0", 41 | "karma-coverage-istanbul-reporter": "~2.0.1", 42 | "karma-jasmine": "~1.1.2", 43 | "karma-jasmine-html-reporter": "^0.2.2", 44 | "protractor": "~5.4.0", 45 | "ts-node": "~7.0.0", 46 | "tslint": "~5.11.0", 47 | "typescript": "~3.1.6" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /angular-mock-api/src/app/app.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikobg/first-class-js/68e3820bce279c3b19d12a3a5f766cb27a85ab0a/angular-mock-api/src/app/app.component.css -------------------------------------------------------------------------------- /angular-mock-api/src/app/app.component.html: -------------------------------------------------------------------------------- 1 |
2 | {{ user.name }} 3 |
-------------------------------------------------------------------------------- /angular-mock-api/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { AppComponent } from './app.component'; 3 | 4 | describe('AppComponent', () => { 5 | beforeEach(async(() => { 6 | TestBed.configureTestingModule({ 7 | declarations: [ 8 | AppComponent 9 | ], 10 | }).compileComponents(); 11 | })); 12 | 13 | it('should create the app', () => { 14 | const fixture = TestBed.createComponent(AppComponent); 15 | const app = fixture.debugElement.componentInstance; 16 | expect(app).toBeTruthy(); 17 | }); 18 | 19 | it(`should have as title 'angular-mock-api'`, () => { 20 | const fixture = TestBed.createComponent(AppComponent); 21 | const app = fixture.debugElement.componentInstance; 22 | expect(app.title).toEqual('angular-mock-api'); 23 | }); 24 | 25 | it('should render title in a h1 tag', () => { 26 | const fixture = TestBed.createComponent(AppComponent); 27 | fixture.detectChanges(); 28 | const compiled = fixture.debugElement.nativeElement; 29 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to angular-mock-api!'); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /angular-mock-api/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { HttpClient } from '@angular/common/http'; 3 | 4 | @Component({ 5 | selector: 'app-root', 6 | templateUrl: './app.component.html', 7 | styleUrls: ['./app.component.css'] 8 | }) 9 | export class AppComponent { 10 | users$ = this.http.get('https://jsonplaceholder.typicode.com/users'); 11 | 12 | constructor(private http: HttpClient) { } 13 | } 14 | -------------------------------------------------------------------------------- /angular-mock-api/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { HttpClientModule } from '@angular/common/http'; 4 | import { environment } from '../environments/environment'; 5 | import { AppComponent } from './app.component'; 6 | import { MockModule } from './mock/mock.module'; 7 | 8 | let extraModules = environment.mockApi ? [MockModule] : []; 9 | 10 | @NgModule({ 11 | declarations: [ 12 | AppComponent 13 | ], 14 | imports: [ 15 | BrowserModule, 16 | HttpClientModule, 17 | ...extraModules 18 | ], 19 | providers: [], 20 | bootstrap: [AppComponent] 21 | }) 22 | export class AppModule { } 23 | -------------------------------------------------------------------------------- /angular-mock-api/src/app/mock/mock.config.ts: -------------------------------------------------------------------------------- 1 | import { HttpResponse } from '@angular/common/http'; 2 | import { of } from 'rxjs'; 3 | 4 | export default { 5 | GET: { 6 | 'https://jsonplaceholder.typicode.com/users': { 7 | handler: getAllUsers 8 | } 9 | } 10 | } 11 | 12 | function getAllUsers() { 13 | return of(new HttpResponse({ status: 200, body: [ 14 | { 15 | id:1, 16 | name: "Viktor" 17 | }, 18 | { 19 | id: 2, 20 | name: "John" 21 | } 22 | ]})) 23 | } -------------------------------------------------------------------------------- /angular-mock-api/src/app/mock/mock.interceptor.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http'; 3 | import { Observable } from 'rxjs'; 4 | import { default as mockEndpoints } from './mock.config'; 5 | 6 | let currentMockEndpoint; 7 | 8 | @Injectable() 9 | export class HttpMockApiInterceptor implements HttpInterceptor { 10 | constructor() {} 11 | 12 | intercept(request: HttpRequest, next: HttpHandler): Observable> { 13 | currentMockEndpoint = mockEndpoints[request.method] && mockEndpoints[request.method][request.url] || null; 14 | 15 | return currentMockEndpoint ? currentMockEndpoint.handler() : next.handle(request); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /angular-mock-api/src/app/mock/mock.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { HTTP_INTERCEPTORS } from '@angular/common/http'; 3 | import { HttpMockApiInterceptor } from './mock.interceptor'; 4 | 5 | 6 | @NgModule({ 7 | declarations: [ 8 | 9 | ], 10 | imports: [ 11 | ], 12 | providers: [ 13 | { 14 | provide: HTTP_INTERCEPTORS, 15 | useClass: HttpMockApiInterceptor, 16 | multi: true 17 | } 18 | ] 19 | }) 20 | export class MockModule { } 21 | -------------------------------------------------------------------------------- /angular-mock-api/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikobg/first-class-js/68e3820bce279c3b19d12a3a5f766cb27a85ab0a/angular-mock-api/src/assets/.gitkeep -------------------------------------------------------------------------------- /angular-mock-api/src/browserslist: -------------------------------------------------------------------------------- 1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | # 5 | # For IE 9-11 support, please remove 'not' from the last line of the file and adjust as needed 6 | 7 | > 0.5% 8 | last 2 versions 9 | Firefox ESR 10 | not dead 11 | not IE 9-11 -------------------------------------------------------------------------------- /angular-mock-api/src/environments/environment.mock.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: false, 3 | mockApi: true 4 | }; 5 | -------------------------------------------------------------------------------- /angular-mock-api/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true, 3 | mockApi: false 4 | }; 5 | -------------------------------------------------------------------------------- /angular-mock-api/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false, 7 | mockApi: false 8 | }; 9 | 10 | /* 11 | * For easier debugging in development mode, you can import the following file 12 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 13 | * 14 | * This import should be commented out in production mode because it will have a negative impact 15 | * on performance if an error is thrown. 16 | */ 17 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 18 | -------------------------------------------------------------------------------- /angular-mock-api/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikobg/first-class-js/68e3820bce279c3b19d12a3a5f766cb27a85ab0a/angular-mock-api/src/favicon.ico -------------------------------------------------------------------------------- /angular-mock-api/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AngularMockApi 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /angular-mock-api/src/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../coverage'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false 30 | }); 31 | }; -------------------------------------------------------------------------------- /angular-mock-api/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /angular-mock-api/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/weak-map'; 35 | // import 'core-js/es6/set'; 36 | 37 | /** 38 | * If the application will be indexed by Google Search, the following is required. 39 | * Googlebot uses a renderer based on Chrome 41. 40 | * https://developers.google.com/search/docs/guides/rendering 41 | **/ 42 | // import 'core-js/es6/array'; 43 | 44 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 45 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 46 | 47 | /** IE10 and IE11 requires the following for the Reflect API. */ 48 | // import 'core-js/es6/reflect'; 49 | 50 | /** 51 | * Web Animations `@angular/platform-browser/animations` 52 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 53 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 54 | **/ 55 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 56 | 57 | /** 58 | * By default, zone.js will patch all possible macroTask and DomEvents 59 | * user can disable parts of macroTask/DomEvents patch by setting following flags 60 | */ 61 | 62 | // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 63 | // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 64 | // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 65 | 66 | /* 67 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 68 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 69 | */ 70 | // (window as any).__Zone_enable_cross_context_check = true; 71 | 72 | /*************************************************************************************************** 73 | * Zone JS is required by default for Angular itself. 74 | */ 75 | import 'zone.js/dist/zone'; // Included with Angular CLI. 76 | 77 | 78 | /*************************************************************************************************** 79 | * APPLICATION IMPORTS 80 | */ 81 | -------------------------------------------------------------------------------- /angular-mock-api/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /angular-mock-api/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /angular-mock-api/src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "types": [] 6 | }, 7 | "exclude": [ 8 | "test.ts", 9 | "**/*.spec.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /angular-mock-api/src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "test.ts", 12 | "polyfills.ts" 13 | ], 14 | "include": [ 15 | "**/*.spec.ts", 16 | "**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /angular-mock-api/src/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "app", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "app", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /angular-mock-api/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "module": "es2015", 9 | "moduleResolution": "node", 10 | "emitDecoratorMetadata": true, 11 | "experimentalDecorators": true, 12 | "importHelpers": true, 13 | "target": "es5", 14 | "typeRoots": [ 15 | "node_modules/@types" 16 | ], 17 | "lib": [ 18 | "es2018", 19 | "dom" 20 | ] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /angular-mock-api/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "deprecation": { 15 | "severity": "warn" 16 | }, 17 | "eofline": true, 18 | "forin": true, 19 | "import-blacklist": [ 20 | true, 21 | "rxjs/Rx" 22 | ], 23 | "import-spacing": true, 24 | "indent": [ 25 | true, 26 | "spaces" 27 | ], 28 | "interface-over-type-literal": true, 29 | "label-position": true, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-arg": true, 47 | "no-bitwise": true, 48 | "no-console": [ 49 | true, 50 | "debug", 51 | "info", 52 | "time", 53 | "timeEnd", 54 | "trace" 55 | ], 56 | "no-construct": true, 57 | "no-debugger": true, 58 | "no-duplicate-super": true, 59 | "no-empty": false, 60 | "no-empty-interface": true, 61 | "no-eval": true, 62 | "no-inferrable-types": [ 63 | true, 64 | "ignore-params" 65 | ], 66 | "no-misused-new": true, 67 | "no-non-null-assertion": true, 68 | "no-redundant-jsdoc": true, 69 | "no-shadowed-variable": true, 70 | "no-string-literal": false, 71 | "no-string-throw": true, 72 | "no-switch-case-fall-through": true, 73 | "no-trailing-whitespace": true, 74 | "no-unnecessary-initializer": true, 75 | "no-unused-expression": true, 76 | "no-use-before-declare": true, 77 | "no-var-keyword": true, 78 | "object-literal-sort-keys": false, 79 | "one-line": [ 80 | true, 81 | "check-open-brace", 82 | "check-catch", 83 | "check-else", 84 | "check-whitespace" 85 | ], 86 | "prefer-const": true, 87 | "quotemark": [ 88 | true, 89 | "single" 90 | ], 91 | "radix": true, 92 | "semicolon": [ 93 | true, 94 | "always" 95 | ], 96 | "triple-equals": [ 97 | true, 98 | "allow-null-check" 99 | ], 100 | "typedef-whitespace": [ 101 | true, 102 | { 103 | "call-signature": "nospace", 104 | "index-signature": "nospace", 105 | "parameter": "nospace", 106 | "property-declaration": "nospace", 107 | "variable-declaration": "nospace" 108 | } 109 | ], 110 | "unified-signatures": true, 111 | "variable-name": false, 112 | "whitespace": [ 113 | true, 114 | "check-branch", 115 | "check-decl", 116 | "check-operator", 117 | "check-separator", 118 | "check-type" 119 | ], 120 | "no-output-on-prefix": true, 121 | "use-input-property-decorator": true, 122 | "use-output-property-decorator": true, 123 | "use-host-property-decorator": true, 124 | "no-input-rename": true, 125 | "no-output-rename": true, 126 | "use-life-cycle-interface": true, 127 | "use-pipe-transform-interface": true, 128 | "component-class-suffix": true, 129 | "directive-class-suffix": true 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /express-serverless-crud/.env: -------------------------------------------------------------------------------- 1 | COMPOSE_PROJECT_NAME=lala -------------------------------------------------------------------------------- /express-serverless-crud/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /archive 3 | archive.zip 4 | build.zip -------------------------------------------------------------------------------- /express-serverless-crud/app-local.js: -------------------------------------------------------------------------------- 1 | const app = require('./app'); 2 | const port = 3000; 3 | 4 | app.listen(port, () => { 5 | console.log(`listening on http://localhost:${port}`); 6 | }); 7 | -------------------------------------------------------------------------------- /express-serverless-crud/app.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const app = express(); 3 | const bodyParser = require('body-parser'); 4 | const cors = require('cors'); 5 | const awsServerlessExpressMiddleware = require('aws-serverless-express/middleware') 6 | 7 | const routes = require('./routes'); 8 | 9 | app.use(cors()); 10 | app.use(bodyParser.json()); 11 | app.use(bodyParser.urlencoded({ extended: true })); 12 | app.use(awsServerlessExpressMiddleware.eventContext()); 13 | 14 | app.use('/', routes); 15 | 16 | module.exports = app; -------------------------------------------------------------------------------- /express-serverless-crud/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | dynamodb: 4 | container_name: dynamodb 5 | image: 'amazon/dynamodb-local:latest' 6 | entrypoint: java 7 | command: '-jar DynamoDBLocal.jar -sharedDb' 8 | restart: always 9 | volumes: 10 | - 'dynamodb-data:/data' 11 | ports: 12 | - '8080:8000' 13 | volumes: 14 | dynamodb-data: 15 | external: true 16 | -------------------------------------------------------------------------------- /express-serverless-crud/employee-table-model.json: -------------------------------------------------------------------------------- 1 | { 2 | "TableName": "employees", 3 | "KeySchema": [ 4 | { 5 | "AttributeName": "id", 6 | "KeyType": "HASH" 7 | } 8 | ], 9 | "AttributeDefinitions": [ 10 | { 11 | "AttributeName": "id", 12 | "AttributeType": "S" 13 | } 14 | ], 15 | "ProvisionedThroughput": { 16 | "ReadCapacityUnits": 1, 17 | "WriteCapacityUnits": 1 18 | } 19 | } -------------------------------------------------------------------------------- /express-serverless-crud/index.js: -------------------------------------------------------------------------------- 1 | const awsServerlessExpress = require('aws-serverless-express') 2 | const app = require('./app') 3 | const server = awsServerlessExpress.createServer(app) 4 | 5 | exports.handler = (event, context) => { awsServerlessExpress.proxy(server, event, context) } 6 | -------------------------------------------------------------------------------- /express-serverless-crud/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "employee-management", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "accepts": { 8 | "version": "1.3.5", 9 | "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz", 10 | "integrity": "sha1-63d99gEXI6OxTopywIBcjoZ0a9I=", 11 | "requires": { 12 | "mime-types": "~2.1.18", 13 | "negotiator": "0.6.1" 14 | } 15 | }, 16 | "array-flatten": { 17 | "version": "1.1.1", 18 | "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", 19 | "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" 20 | }, 21 | "aws-sdk": { 22 | "version": "2.430.0", 23 | "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.430.0.tgz", 24 | "integrity": "sha512-xJC1Sd6pjiIUg0W6v189QFWaY/jo+dVdQEJpplzqqBWmdUhZrBVmuWBVjC/wf5r6+Tj2KCc0G1fvjZqVutYnMw==", 25 | "requires": { 26 | "buffer": "4.9.1", 27 | "events": "1.1.1", 28 | "ieee754": "1.1.8", 29 | "jmespath": "0.15.0", 30 | "querystring": "0.2.0", 31 | "sax": "1.2.1", 32 | "url": "0.10.3", 33 | "uuid": "3.3.2", 34 | "xml2js": "0.4.19" 35 | } 36 | }, 37 | "aws-serverless-express": { 38 | "version": "3.3.6", 39 | "resolved": "https://registry.npmjs.org/aws-serverless-express/-/aws-serverless-express-3.3.6.tgz", 40 | "integrity": "sha512-VTn8YQpPpMAEdMeGjyaSygy7Rc0057C9MUjeZION0NBqmwTyphpu9Tc5DCHRNF4qNFQ9x1xcOte6OXKzJvvDhw==", 41 | "requires": { 42 | "binary-case": "^1.0.0", 43 | "type-is": "^1.6.16" 44 | } 45 | }, 46 | "base64-js": { 47 | "version": "1.3.0", 48 | "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.0.tgz", 49 | "integrity": "sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw==" 50 | }, 51 | "binary-case": { 52 | "version": "1.1.4", 53 | "resolved": "https://registry.npmjs.org/binary-case/-/binary-case-1.1.4.tgz", 54 | "integrity": "sha512-9Kq8m6NZTAgy05Ryuh7U3Qc4/ujLQU1AZ5vMw4cr3igTdi5itZC6kCNrRr2X8NzPiDn2oUIFTfa71DKMnue/Zg==" 55 | }, 56 | "body-parser": { 57 | "version": "1.18.3", 58 | "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.3.tgz", 59 | "integrity": "sha1-WykhmP/dVTs6DyDe0FkrlWlVyLQ=", 60 | "requires": { 61 | "bytes": "3.0.0", 62 | "content-type": "~1.0.4", 63 | "debug": "2.6.9", 64 | "depd": "~1.1.2", 65 | "http-errors": "~1.6.3", 66 | "iconv-lite": "0.4.23", 67 | "on-finished": "~2.3.0", 68 | "qs": "6.5.2", 69 | "raw-body": "2.3.3", 70 | "type-is": "~1.6.16" 71 | } 72 | }, 73 | "buffer": { 74 | "version": "4.9.1", 75 | "resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz", 76 | "integrity": "sha1-bRu2AbB6TvztlwlBMgkwJ8lbwpg=", 77 | "requires": { 78 | "base64-js": "^1.0.2", 79 | "ieee754": "^1.1.4", 80 | "isarray": "^1.0.0" 81 | } 82 | }, 83 | "bytes": { 84 | "version": "3.0.0", 85 | "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", 86 | "integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=" 87 | }, 88 | "content-disposition": { 89 | "version": "0.5.2", 90 | "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz", 91 | "integrity": "sha1-DPaLud318r55YcOoUXjLhdunjLQ=" 92 | }, 93 | "content-type": { 94 | "version": "1.0.4", 95 | "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", 96 | "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" 97 | }, 98 | "cookie": { 99 | "version": "0.3.1", 100 | "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", 101 | "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=" 102 | }, 103 | "cookie-signature": { 104 | "version": "1.0.6", 105 | "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", 106 | "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" 107 | }, 108 | "cors": { 109 | "version": "2.8.5", 110 | "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", 111 | "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", 112 | "requires": { 113 | "object-assign": "^4", 114 | "vary": "^1" 115 | } 116 | }, 117 | "debug": { 118 | "version": "2.6.9", 119 | "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", 120 | "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", 121 | "requires": { 122 | "ms": "2.0.0" 123 | } 124 | }, 125 | "depd": { 126 | "version": "1.1.2", 127 | "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", 128 | "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" 129 | }, 130 | "destroy": { 131 | "version": "1.0.4", 132 | "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", 133 | "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" 134 | }, 135 | "ee-first": { 136 | "version": "1.1.1", 137 | "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", 138 | "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" 139 | }, 140 | "encodeurl": { 141 | "version": "1.0.2", 142 | "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", 143 | "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=" 144 | }, 145 | "escape-html": { 146 | "version": "1.0.3", 147 | "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", 148 | "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" 149 | }, 150 | "etag": { 151 | "version": "1.8.1", 152 | "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", 153 | "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" 154 | }, 155 | "events": { 156 | "version": "1.1.1", 157 | "resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz", 158 | "integrity": "sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ=" 159 | }, 160 | "express": { 161 | "version": "4.16.4", 162 | "resolved": "https://registry.npmjs.org/express/-/express-4.16.4.tgz", 163 | "integrity": "sha512-j12Uuyb4FMrd/qQAm6uCHAkPtO8FDTRJZBDd5D2KOL2eLaz1yUNdUB/NOIyq0iU4q4cFarsUCrnFDPBcnksuOg==", 164 | "requires": { 165 | "accepts": "~1.3.5", 166 | "array-flatten": "1.1.1", 167 | "body-parser": "1.18.3", 168 | "content-disposition": "0.5.2", 169 | "content-type": "~1.0.4", 170 | "cookie": "0.3.1", 171 | "cookie-signature": "1.0.6", 172 | "debug": "2.6.9", 173 | "depd": "~1.1.2", 174 | "encodeurl": "~1.0.2", 175 | "escape-html": "~1.0.3", 176 | "etag": "~1.8.1", 177 | "finalhandler": "1.1.1", 178 | "fresh": "0.5.2", 179 | "merge-descriptors": "1.0.1", 180 | "methods": "~1.1.2", 181 | "on-finished": "~2.3.0", 182 | "parseurl": "~1.3.2", 183 | "path-to-regexp": "0.1.7", 184 | "proxy-addr": "~2.0.4", 185 | "qs": "6.5.2", 186 | "range-parser": "~1.2.0", 187 | "safe-buffer": "5.1.2", 188 | "send": "0.16.2", 189 | "serve-static": "1.13.2", 190 | "setprototypeof": "1.1.0", 191 | "statuses": "~1.4.0", 192 | "type-is": "~1.6.16", 193 | "utils-merge": "1.0.1", 194 | "vary": "~1.1.2" 195 | } 196 | }, 197 | "finalhandler": { 198 | "version": "1.1.1", 199 | "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.1.tgz", 200 | "integrity": "sha512-Y1GUDo39ez4aHAw7MysnUD5JzYX+WaIj8I57kO3aEPT1fFRL4sr7mjei97FgnwhAyyzRYmQZaTHb2+9uZ1dPtg==", 201 | "requires": { 202 | "debug": "2.6.9", 203 | "encodeurl": "~1.0.2", 204 | "escape-html": "~1.0.3", 205 | "on-finished": "~2.3.0", 206 | "parseurl": "~1.3.2", 207 | "statuses": "~1.4.0", 208 | "unpipe": "~1.0.0" 209 | } 210 | }, 211 | "forwarded": { 212 | "version": "0.1.2", 213 | "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", 214 | "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=" 215 | }, 216 | "fresh": { 217 | "version": "0.5.2", 218 | "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", 219 | "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" 220 | }, 221 | "http-errors": { 222 | "version": "1.6.3", 223 | "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz", 224 | "integrity": "sha1-i1VoC7S+KDoLW/TqLjhYC+HZMg0=", 225 | "requires": { 226 | "depd": "~1.1.2", 227 | "inherits": "2.0.3", 228 | "setprototypeof": "1.1.0", 229 | "statuses": ">= 1.4.0 < 2" 230 | } 231 | }, 232 | "iconv-lite": { 233 | "version": "0.4.23", 234 | "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.23.tgz", 235 | "integrity": "sha512-neyTUVFtahjf0mB3dZT77u+8O0QB89jFdnBkd5P1JgYPbPaia3gXXOVL2fq8VyU2gMMD7SaN7QukTB/pmXYvDA==", 236 | "requires": { 237 | "safer-buffer": ">= 2.1.2 < 3" 238 | } 239 | }, 240 | "ieee754": { 241 | "version": "1.1.8", 242 | "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.8.tgz", 243 | "integrity": "sha1-vjPUCsEO8ZJnAfbwii2G+/0a0+Q=" 244 | }, 245 | "inherits": { 246 | "version": "2.0.3", 247 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", 248 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" 249 | }, 250 | "ipaddr.js": { 251 | "version": "1.8.0", 252 | "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.8.0.tgz", 253 | "integrity": "sha1-6qM9bd16zo9/b+DJygRA5wZzix4=" 254 | }, 255 | "isarray": { 256 | "version": "1.0.0", 257 | "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", 258 | "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" 259 | }, 260 | "jmespath": { 261 | "version": "0.15.0", 262 | "resolved": "https://registry.npmjs.org/jmespath/-/jmespath-0.15.0.tgz", 263 | "integrity": "sha1-o/Iiqarp+Wb10nx5ZRDigJF2Qhc=" 264 | }, 265 | "media-typer": { 266 | "version": "0.3.0", 267 | "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", 268 | "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" 269 | }, 270 | "merge-descriptors": { 271 | "version": "1.0.1", 272 | "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", 273 | "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" 274 | }, 275 | "methods": { 276 | "version": "1.1.2", 277 | "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", 278 | "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" 279 | }, 280 | "mime": { 281 | "version": "1.4.1", 282 | "resolved": "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz", 283 | "integrity": "sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ==" 284 | }, 285 | "mime-db": { 286 | "version": "1.38.0", 287 | "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.38.0.tgz", 288 | "integrity": "sha512-bqVioMFFzc2awcdJZIzR3HjZFX20QhilVS7hytkKrv7xFAn8bM1gzc/FOX2awLISvWe0PV8ptFKcon+wZ5qYkg==" 289 | }, 290 | "mime-types": { 291 | "version": "2.1.22", 292 | "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.22.tgz", 293 | "integrity": "sha512-aGl6TZGnhm/li6F7yx82bJiBZwgiEa4Hf6CNr8YO+r5UHr53tSTYZb102zyU50DOWWKeOv0uQLRL0/9EiKWCog==", 294 | "requires": { 295 | "mime-db": "~1.38.0" 296 | } 297 | }, 298 | "ms": { 299 | "version": "2.0.0", 300 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", 301 | "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" 302 | }, 303 | "negotiator": { 304 | "version": "0.6.1", 305 | "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", 306 | "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" 307 | }, 308 | "object-assign": { 309 | "version": "4.1.1", 310 | "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", 311 | "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" 312 | }, 313 | "on-finished": { 314 | "version": "2.3.0", 315 | "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", 316 | "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", 317 | "requires": { 318 | "ee-first": "1.1.1" 319 | } 320 | }, 321 | "parseurl": { 322 | "version": "1.3.2", 323 | "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz", 324 | "integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M=" 325 | }, 326 | "path-to-regexp": { 327 | "version": "0.1.7", 328 | "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", 329 | "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" 330 | }, 331 | "proxy-addr": { 332 | "version": "2.0.4", 333 | "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.4.tgz", 334 | "integrity": "sha512-5erio2h9jp5CHGwcybmxmVqHmnCBZeewlfJ0pex+UW7Qny7OOZXTtH56TGNyBizkgiOwhJtMKrVzDTeKcySZwA==", 335 | "requires": { 336 | "forwarded": "~0.1.2", 337 | "ipaddr.js": "1.8.0" 338 | } 339 | }, 340 | "punycode": { 341 | "version": "1.3.2", 342 | "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz", 343 | "integrity": "sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0=" 344 | }, 345 | "qs": { 346 | "version": "6.5.2", 347 | "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", 348 | "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==" 349 | }, 350 | "querystring": { 351 | "version": "0.2.0", 352 | "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz", 353 | "integrity": "sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA=" 354 | }, 355 | "range-parser": { 356 | "version": "1.2.0", 357 | "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz", 358 | "integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4=" 359 | }, 360 | "raw-body": { 361 | "version": "2.3.3", 362 | "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.3.tgz", 363 | "integrity": "sha512-9esiElv1BrZoI3rCDuOuKCBRbuApGGaDPQfjSflGxdy4oyzqghxu6klEkkVIvBje+FF0BX9coEv8KqW6X/7njw==", 364 | "requires": { 365 | "bytes": "3.0.0", 366 | "http-errors": "1.6.3", 367 | "iconv-lite": "0.4.23", 368 | "unpipe": "1.0.0" 369 | } 370 | }, 371 | "safe-buffer": { 372 | "version": "5.1.2", 373 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", 374 | "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" 375 | }, 376 | "safer-buffer": { 377 | "version": "2.1.2", 378 | "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", 379 | "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" 380 | }, 381 | "sax": { 382 | "version": "1.2.1", 383 | "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.1.tgz", 384 | "integrity": "sha1-e45lYZCyKOgaZq6nSEgNgozS03o=" 385 | }, 386 | "send": { 387 | "version": "0.16.2", 388 | "resolved": "https://registry.npmjs.org/send/-/send-0.16.2.tgz", 389 | "integrity": "sha512-E64YFPUssFHEFBvpbbjr44NCLtI1AohxQ8ZSiJjQLskAdKuriYEP6VyGEsRDH8ScozGpkaX1BGvhanqCwkcEZw==", 390 | "requires": { 391 | "debug": "2.6.9", 392 | "depd": "~1.1.2", 393 | "destroy": "~1.0.4", 394 | "encodeurl": "~1.0.2", 395 | "escape-html": "~1.0.3", 396 | "etag": "~1.8.1", 397 | "fresh": "0.5.2", 398 | "http-errors": "~1.6.2", 399 | "mime": "1.4.1", 400 | "ms": "2.0.0", 401 | "on-finished": "~2.3.0", 402 | "range-parser": "~1.2.0", 403 | "statuses": "~1.4.0" 404 | } 405 | }, 406 | "serve-static": { 407 | "version": "1.13.2", 408 | "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.13.2.tgz", 409 | "integrity": "sha512-p/tdJrO4U387R9oMjb1oj7qSMaMfmOyd4j9hOFoxZe2baQszgHcSWjuya/CiT5kgZZKRudHNOA0pYXOl8rQ5nw==", 410 | "requires": { 411 | "encodeurl": "~1.0.2", 412 | "escape-html": "~1.0.3", 413 | "parseurl": "~1.3.2", 414 | "send": "0.16.2" 415 | } 416 | }, 417 | "setprototypeof": { 418 | "version": "1.1.0", 419 | "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz", 420 | "integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ==" 421 | }, 422 | "statuses": { 423 | "version": "1.4.0", 424 | "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz", 425 | "integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew==" 426 | }, 427 | "type-is": { 428 | "version": "1.6.16", 429 | "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.16.tgz", 430 | "integrity": "sha512-HRkVv/5qY2G6I8iab9cI7v1bOIdhm94dVjQCPFElW9W+3GeDOSHmy2EBYe4VTApuzolPcmgFTN3ftVJRKR2J9Q==", 431 | "requires": { 432 | "media-typer": "0.3.0", 433 | "mime-types": "~2.1.18" 434 | } 435 | }, 436 | "unpipe": { 437 | "version": "1.0.0", 438 | "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", 439 | "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" 440 | }, 441 | "url": { 442 | "version": "0.10.3", 443 | "resolved": "https://registry.npmjs.org/url/-/url-0.10.3.tgz", 444 | "integrity": "sha1-Ah5NnHcF8hu/N9A861h2dAJ3TGQ=", 445 | "requires": { 446 | "punycode": "1.3.2", 447 | "querystring": "0.2.0" 448 | } 449 | }, 450 | "utils-merge": { 451 | "version": "1.0.1", 452 | "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", 453 | "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" 454 | }, 455 | "uuid": { 456 | "version": "3.3.2", 457 | "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz", 458 | "integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==" 459 | }, 460 | "vary": { 461 | "version": "1.1.2", 462 | "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", 463 | "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" 464 | }, 465 | "xml2js": { 466 | "version": "0.4.19", 467 | "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.19.tgz", 468 | "integrity": "sha512-esZnJZJOiJR9wWKMyuvSE1y6Dq5LCuJanqhxslH2bxM6duahNZ+HMpCLhBQGZkbX6xRf8x1Y2eJlgt2q3qo49Q==", 469 | "requires": { 470 | "sax": ">=0.6.0", 471 | "xmlbuilder": "~9.0.1" 472 | } 473 | }, 474 | "xmlbuilder": { 475 | "version": "9.0.7", 476 | "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz", 477 | "integrity": "sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0=" 478 | } 479 | } 480 | } 481 | -------------------------------------------------------------------------------- /express-serverless-crud/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "employee-management", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "deploy": "npm run clean && npm run build && aws lambda update-function-code --function-name employees --zip-file fileb://build.zip --publish", 9 | "clean": "rm build.zip", 10 | "build": "zip -r build.zip node_modules index.js app.js routes.js", 11 | "start": "TABLE='employees' node app-local", 12 | "dynamodb-local-run": "docker-compose up", 13 | "create-database": "aws dynamodb create-table --cli-input-json file://employee-table-model.json --endpoint-url http://localhost:8080" 14 | }, 15 | "author": "", 16 | "license": "ISC", 17 | "dependencies": { 18 | "aws-sdk": "^2.430.0", 19 | "aws-serverless-express": "^3.3.6", 20 | "cors": "^2.8.5", 21 | "express": "^4.16.4", 22 | "uuid": "^3.3.2" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /express-serverless-crud/routes.js: -------------------------------------------------------------------------------- 1 | const AWS = require('aws-sdk'); 2 | const express = require('express'); 3 | const uuid = require('uuid'); 4 | 5 | const IS_OFFLINE = process.env.NODE_ENV !== 'production'; 6 | const EMPLOYEES_TABLE = process.env.TABLE; 7 | 8 | const dynamoDb = IS_OFFLINE === true ? 9 | new AWS.DynamoDB.DocumentClient({ 10 | region: 'eu-west-2', 11 | endpoint: 'http://127.0.0.1:8080', 12 | }) : 13 | new AWS.DynamoDB.DocumentClient(); 14 | 15 | const router = express.Router(); 16 | 17 | router.get('/employees', (req, res) => { 18 | const params = { 19 | TableName: EMPLOYEES_TABLE 20 | }; 21 | dynamoDb.scan(params, (error, result) => { 22 | if (error) { 23 | res.status(400).json({ error: 'Error fetching the employees' }); 24 | } 25 | res.json(result.Items); 26 | }); 27 | }); 28 | 29 | router.get('/employees/:id', (req, res) => { 30 | const id = req.params.id; 31 | 32 | const params = { 33 | TableName: EMPLOYEES_TABLE, 34 | Key: { 35 | id 36 | } 37 | }; 38 | 39 | dynamoDb.get(params, (error, result) => { 40 | if (error) { 41 | res.status(400).json({ error: 'Error retrieving Employee' }); 42 | } 43 | if (result.Item) { 44 | res.json(result.Item); 45 | } else { 46 | res.status(404).json({ error: `Employee with id: ${id} not found` }); 47 | } 48 | }); 49 | }); 50 | 51 | router.post('/employees', (req, res) => { 52 | const name = req.body.name; 53 | const id = uuid.v4(); 54 | 55 | const params = { 56 | TableName: EMPLOYEES_TABLE, 57 | Item: { 58 | id, 59 | name 60 | }, 61 | }; 62 | 63 | dynamoDb.put(params, (error) => { 64 | if (error) { 65 | res.status(400).json({ error: 'Could not create Employee' }); 66 | } 67 | res.json({ 68 | id, 69 | name 70 | }); 71 | }); 72 | }); 73 | 74 | router.delete('/employees/:id', (req, res) => { 75 | const id = req.params.id; 76 | 77 | const params = { 78 | TableName: EMPLOYEES_TABLE, 79 | Key: { 80 | id 81 | } 82 | }; 83 | 84 | dynamoDb.delete(params, (error) => { 85 | if (error) { 86 | res.status(400).json({ error: 'Could not delete Employee' }); 87 | } 88 | res.json({ success: true }); 89 | }); 90 | }); 91 | 92 | router.put('/employees', (req, res) => { 93 | const id = req.body.id; 94 | const name = req.body.name; 95 | 96 | const params = { 97 | TableName: EMPLOYEES_TABLE, 98 | Key: { 99 | id 100 | }, 101 | UpdateExpression: 'set #name = :name', 102 | ExpressionAttributeNames: { '#name': 'name' }, 103 | ExpressionAttributeValues: { ':name': name }, 104 | ReturnValues: "ALL_NEW" 105 | } 106 | 107 | dynamoDb.update(params, (error, result) => { 108 | if (error) { 109 | res.status(400).json({ error: 'Could not update Employee' }); 110 | } 111 | res.json(result.Attributes); 112 | }) 113 | }); 114 | 115 | module.exports = router; -------------------------------------------------------------------------------- /nodejs-csv-to-json/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules -------------------------------------------------------------------------------- /nodejs-csv-to-json/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nodejs-csv-to-json", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "csvjson": { 8 | "version": "5.1.0", 9 | "resolved": "https://registry.npmjs.org/csvjson/-/csvjson-5.1.0.tgz", 10 | "integrity": "sha512-OqALQHA0k2rEGluOWikwFq5qtkRUDyoWP2u0UJy8uFjFx5FPMjPzx7D2Hn2KjBLpc8jkGrT9HDNgTUfopDlqVg==" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /nodejs-csv-to-json/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nodejs-csv-to-json", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "csvjson": "^5.1.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /nodejs-csv-to-json/read-file.js: -------------------------------------------------------------------------------- 1 | const csvjson = require('csvjson'); 2 | const readFile = require('fs').readFile; 3 | 4 | readFile('./test-data.csv', 'utf-8', (err, fileContent) => { 5 | if(err) { 6 | console.log(err); // Do something to handle the error or just throw it 7 | throw new Error(err); 8 | } 9 | const jsonObj = csvjson.toObject(fileContent); 10 | console.log(jsonObj); 11 | }); -------------------------------------------------------------------------------- /nodejs-csv-to-json/read-stream.js: -------------------------------------------------------------------------------- 1 | const csvjson = require('csvjson'); 2 | const createReadStream = require('fs').createReadStream; 3 | const createWriteStream = require('fs').createWriteStream; 4 | 5 | const stringify = csvjson.stream.stringify(); 6 | const toObject = csvjson.stream.toObject(); 7 | 8 | createReadStream('./test-data.csv', 'utf-8') 9 | .pipe(toObject) 10 | .pipe(stringify) 11 | .pipe(createWriteStream('./test-data-output-stream.json')); 12 | -------------------------------------------------------------------------------- /nodejs-csv-to-json/test-data-output-stream.json: -------------------------------------------------------------------------------- 1 | [{"id":"1","name":"John Smith","position":"Manager"},{"id":"2","name":"Johny Bravo","position":"Employee"},{"id":"3","name":"Peter","position":"N/A"}] -------------------------------------------------------------------------------- /nodejs-csv-to-json/test-data.csv: -------------------------------------------------------------------------------- 1 | id,name,position 2 | 1,John Smith, Manager 3 | 2,Johny Bravo, Employee 4 | 3,Peter, N/A -------------------------------------------------------------------------------- /nodejs-json-to-csv/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules -------------------------------------------------------------------------------- /nodejs-json-to-csv/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nodejs-json-to-csv", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "csvjson": { 8 | "version": "5.1.0", 9 | "resolved": "https://registry.npmjs.org/csvjson/-/csvjson-5.1.0.tgz", 10 | "integrity": "sha512-OqALQHA0k2rEGluOWikwFq5qtkRUDyoWP2u0UJy8uFjFx5FPMjPzx7D2Hn2KjBLpc8jkGrT9HDNgTUfopDlqVg==" 11 | }, 12 | "jsonparse": { 13 | "version": "1.0.0", 14 | "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.0.0.tgz", 15 | "integrity": "sha1-JiL05mwI4arH7b63YFPJt+EhH3Y=" 16 | }, 17 | "jsonstream": { 18 | "version": "1.0.3", 19 | "resolved": "https://registry.npmjs.org/jsonstream/-/jsonstream-1.0.3.tgz", 20 | "integrity": "sha1-/y1JxPR5tbvN+fnlbIQc+H8O+h0=", 21 | "requires": { 22 | "jsonparse": "~1.0.0", 23 | "through": ">=2.2.7 <3" 24 | } 25 | }, 26 | "through": { 27 | "version": "2.3.8", 28 | "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", 29 | "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=" 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /nodejs-json-to-csv/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nodejs-json-to-csv", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "csvjson": "^5.1.0", 14 | "jsonstream": "^1.0.3" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /nodejs-json-to-csv/read-file.js: -------------------------------------------------------------------------------- 1 | const csvjson = require('csvjson'); 2 | const readFile = require('fs').readFile; 3 | const writeFile = require('fs').writeFile; 4 | 5 | readFile('./test-data.json', 'utf-8', (err, fileContent) => { 6 | if (err) { 7 | console.log(err); // Do something to handle the error or just throw it 8 | throw new Error(err); 9 | } 10 | 11 | const csvData = csvjson.toCSV(fileContent, { 12 | headers: 'key' 13 | }); 14 | writeFile('./test-data.csv', csvData, (err) => { 15 | if(err) { 16 | console.log(err); // Do something to handle the error or just throw it 17 | throw new Error(err); 18 | } 19 | console.log('Success!'); 20 | }); 21 | }); -------------------------------------------------------------------------------- /nodejs-json-to-csv/read-stream.js: -------------------------------------------------------------------------------- 1 | const csvjson = require('csvjson'); 2 | const fs = require('fs'); 3 | 4 | const stream = require('stream'); 5 | const JSONStream = require('jsonstream'); 6 | 7 | const createReadStream = fs.createReadStream; 8 | const createWriteStream = fs.createWriteStream; 9 | 10 | let line = 0; 11 | const transformJsonToCSV = new stream.Transform({ 12 | transform: function transformer(chunk, encoding, callback) { 13 | line++; 14 | callback(false, csvjson.toCSV(chunk, { 15 | headers: line > 1 ? 'none' : 'key' 16 | })); 17 | }, 18 | readableObjectMode: true, 19 | writableObjectMode: true, 20 | }); 21 | 22 | createReadStream('./test-data.json', 'utf-8') 23 | .pipe(JSONStream.parse('*')) 24 | .pipe(transformJsonToCSV) 25 | .pipe(createWriteStream('./test-data-output-stream.csv')); 26 | -------------------------------------------------------------------------------- /nodejs-json-to-csv/test-data-output-stream.csv: -------------------------------------------------------------------------------- 1 | id,name,position 2 | 1,John Smith,Manager 3 | 2,Johny Bravo,Employee 4 | 3,Peter,N/A -------------------------------------------------------------------------------- /nodejs-json-to-csv/test-data.csv: -------------------------------------------------------------------------------- 1 | id,name,position 2 | 1,John Smith,Manager 3 | 2,Johny Bravo,Employee 4 | 3,Peter,N/A -------------------------------------------------------------------------------- /nodejs-json-to-csv/test-data.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id":"1", 4 | "name":"John Smith", 5 | "position":"Manager" 6 | }, 7 | { 8 | "id":"2", 9 | "name":"Johny Bravo", 10 | "position":"Employee" 11 | }, 12 | { 13 | "id":"3", 14 | "name":"Peter", 15 | "position":"N/A" 16 | } 17 | ] --------------------------------------------------------------------------------