Skip to content
This repository has been archived by the owner on May 29, 2023. It is now read-only.

Commit

Permalink
Merge 7e27624 into e84e95e
Browse files Browse the repository at this point in the history
  • Loading branch information
waterplea committed Aug 10, 2020
2 parents e84e95e + 7e27624 commit f2a0fef
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 40 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ you will get type-safe mocks and you can at least be sure you will not have
- `CSS` — no need to do anything, mock object is already injected as if you were using Internet Explorer
- `LOCATION` — see _special cases_ below
- `LOCAL_STORAGE` — add `UNIVERSAL_LOCAL_STORAGE` for a `Map` based mock for `window.localStorage`
- `SESSION_STORAGE` — add `UNIVERSAL_SESSION_STORAGE` for a `Map` based mock for `window.sessionStorage`
- `PAGE_VISIBILITY` — no need to do anything

You can also provide all the tokens at once with `UNIVERSAL_TOKENS` constant
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 3 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
"name": "Alex Inkin",
"email": "alexander@inkin.ru"
},
"contributors": [
"Roman Sedov <79601794011@ya.ru> (http://marsibarsi.me/)"
],
"contributors": ["Roman Sedov <79601794011@ya.ru> (http://marsibarsi.me/)"],
"repository": "https://github.com/ng-web-apis/universal",
"bugs": "https://github.com/ng-web-apis/universal/issues",
"homepage": "https://github.com/ng-web-apis/universal#README",
Expand All @@ -53,7 +51,7 @@
"@nguniversal/common": "^7.1.1",
"@nguniversal/express-engine": "^7.1.1",
"@nguniversal/module-map-ngfactory-loader": "^7.1.1",
"@ng-web-apis/common": "1.4.0",
"@ng-web-apis/common": "latest",
"core-js": "^2.5.4",
"rxjs": "^6.5.2",
"tslib": "^1.10.0",
Expand Down Expand Up @@ -104,10 +102,7 @@
}
},
"lint-staged": {
"*.{js,ts,html,md,less,json}": [
"prettier --write",
"git add"
],
"*.{js,ts,html,md,less,json}": ["prettier --write", "git add"],
"*.ts": "tslint"
},
"standard-version": {
Expand Down
2 changes: 1 addition & 1 deletion projects/universal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.5.0",
"peerDependencies": {
"@angular/core": ">=6.0.0",
"@ng-web-apis/common": "1.4.0",
"@ng-web-apis/common": "1.6.0",
"@types/node": ">=10.0.0",
"rxjs": ">=6.0.0"
},
Expand Down
27 changes: 27 additions & 0 deletions projects/universal/src/classes/storage-mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export class StorageMock implements Storage {
private readonly storage = new Map<string, string>();

get length(): number {
return this.storage.size;
}

getItem(key: string): string | null {
return this.storage.has(key) ? this.storage.get(key)! : null;
}

setItem(key: string, value: string) {
this.storage.set(key, value);
}

clear() {
this.storage.clear();
}

key(index: number): string | null {
return index < this.storage.size ? [...this.storage.keys()][index] : null;
}

removeItem(key: string): void {
this.storage.delete(key);
}
}
29 changes: 1 addition & 28 deletions projects/universal/src/constants/universal-local-storage.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,6 @@
import {ClassProvider} from '@angular/core';
import {LOCAL_STORAGE} from '@ng-web-apis/common';

export class StorageMock implements Storage {
private readonly storage = new Map<string, string>();

get length(): number {
return this.storage.size;
}

getItem(key: string): string | null {
return this.storage.has(key) ? this.storage.get(key)! : null;
}

setItem(key: string, value: string) {
this.storage.set(key, value);
}

clear() {
this.storage.clear();
}

key(index: number): string | null {
return index < this.storage.size ? [...this.storage.keys()][index] : null;
}

removeItem(key: string): void {
this.storage.delete(key);
}
}
import {StorageMock} from '../classes/storage-mock';

export const UNIVERSAL_LOCAL_STORAGE: ClassProvider = {
provide: LOCAL_STORAGE,
Expand Down
8 changes: 8 additions & 0 deletions projects/universal/src/constants/universal-session-storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {ClassProvider} from '@angular/core';
import {SESSION_STORAGE} from '@ng-web-apis/common';
import {StorageMock} from '../classes/storage-mock';

export const UNIVERSAL_SESSION_STORAGE: ClassProvider = {
provide: SESSION_STORAGE,
useClass: StorageMock,
};

0 comments on commit f2a0fef

Please sign in to comment.