mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 12:53:03 -05:00
feat(utils): add utils library with a fake ramdon generator
This commit is contained in:
@@ -20,7 +20,8 @@
|
||||
"apps/rxjs-pipe-bug/src/assets"
|
||||
],
|
||||
"styles": ["apps/rxjs-pipe-bug/src/styles.scss"],
|
||||
"scripts": []
|
||||
"scripts": [],
|
||||
"allowedCommonJsDependencies": ["seedrandom"]
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable @typescript-eslint/member-ordering */
|
||||
import { randomError } from '@angular-challenges/shared/utils';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { randNumber } from '@ngneat/falso';
|
||||
import { ComponentStore } from '@ngrx/component-store';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
@@ -47,12 +47,12 @@ export class LocalDBService extends ComponentStore<DBState> {
|
||||
})
|
||||
);
|
||||
|
||||
deleteOneTopic = (id: number) => {
|
||||
const randomNumber = randNumber({ min: 0.1, max: 1, fraction: 2 });
|
||||
if (randomNumber > 0.5) {
|
||||
deleteOneTopic = (id: number) =>
|
||||
randomError({
|
||||
success: () => {
|
||||
this.deleteOne(id);
|
||||
return of(true);
|
||||
}
|
||||
return of(false);
|
||||
};
|
||||
},
|
||||
error: () => of(false),
|
||||
});
|
||||
}
|
||||
|
||||
36
libs/shared/utils/.eslintrc.json
Normal file
36
libs/shared/utils/.eslintrc.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"extends": ["../../../.eslintrc.json"],
|
||||
"ignorePatterns": ["!**/*"],
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["*.ts"],
|
||||
"rules": {
|
||||
"@angular-eslint/directive-selector": [
|
||||
"error",
|
||||
{
|
||||
"type": "attribute",
|
||||
"prefix": "angularChallenges",
|
||||
"style": "camelCase"
|
||||
}
|
||||
],
|
||||
"@angular-eslint/component-selector": [
|
||||
"error",
|
||||
{
|
||||
"type": "element",
|
||||
"prefix": "angular-challenges",
|
||||
"style": "kebab-case"
|
||||
}
|
||||
]
|
||||
},
|
||||
"extends": [
|
||||
"plugin:@nrwl/nx/angular",
|
||||
"plugin:@angular-eslint/template/process-inline-templates"
|
||||
]
|
||||
},
|
||||
{
|
||||
"files": ["*.html"],
|
||||
"extends": ["plugin:@nrwl/nx/angular-template"],
|
||||
"rules": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
7
libs/shared/utils/README.md
Normal file
7
libs/shared/utils/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# shared-utils
|
||||
|
||||
This library was generated with [Nx](https://nx.dev).
|
||||
|
||||
## Running unit tests
|
||||
|
||||
Run `nx test shared-utils` to execute the unit tests.
|
||||
22
libs/shared/utils/jest.config.ts
Normal file
22
libs/shared/utils/jest.config.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/* eslint-disable */
|
||||
export default {
|
||||
displayName: 'shared-utils',
|
||||
preset: '../../../jest.preset.js',
|
||||
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
tsconfig: '<rootDir>/tsconfig.spec.json',
|
||||
stringifyContentPathRegex: '\\.(html|svg)$',
|
||||
},
|
||||
},
|
||||
coverageDirectory: '../../../coverage/libs/shared/utils',
|
||||
transform: {
|
||||
'^.+\\.(ts|mjs|js|html)$': 'jest-preset-angular',
|
||||
},
|
||||
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
|
||||
snapshotSerializers: [
|
||||
'jest-preset-angular/build/serializers/no-ng-attributes',
|
||||
'jest-preset-angular/build/serializers/ng-snapshot',
|
||||
'jest-preset-angular/build/serializers/html-comment',
|
||||
],
|
||||
};
|
||||
28
libs/shared/utils/project.json
Normal file
28
libs/shared/utils/project.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "shared-utils",
|
||||
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
||||
"projectType": "library",
|
||||
"sourceRoot": "libs/shared/utils/src",
|
||||
"prefix": "angular-challenges",
|
||||
"targets": {
|
||||
"test": {
|
||||
"executor": "@nrwl/jest:jest",
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
||||
"options": {
|
||||
"jestConfig": "libs/shared/utils/jest.config.ts",
|
||||
"passWithNoTests": true
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"executor": "@nrwl/linter:eslint",
|
||||
"outputs": ["{options.outputFile}"],
|
||||
"options": {
|
||||
"lintFilePatterns": [
|
||||
"libs/shared/utils/**/*.ts",
|
||||
"libs/shared/utils/**/*.html"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": []
|
||||
}
|
||||
1
libs/shared/utils/src/index.ts
Normal file
1
libs/shared/utils/src/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './lib/random-http-error.utils';
|
||||
24
libs/shared/utils/src/lib/random-http-error.utils.ts
Normal file
24
libs/shared/utils/src/lib/random-http-error.utils.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { randNumber } from '@ngneat/falso';
|
||||
|
||||
/**
|
||||
* Execute success function if value is above threshold and error function otherwise
|
||||
* Success and error function should return the same ReturnType
|
||||
* @param success
|
||||
* @param error
|
||||
* @param threashold default to 0.5
|
||||
*/
|
||||
export const randomError = <T>({
|
||||
success,
|
||||
error,
|
||||
threashold,
|
||||
}: {
|
||||
success: () => T;
|
||||
error: () => T;
|
||||
threashold?: number;
|
||||
}): T => {
|
||||
const randomNumber = randNumber({ min: 0.1, max: 1, fraction: 2 });
|
||||
if (randomNumber > (threashold ?? 0.5)) {
|
||||
return success();
|
||||
}
|
||||
return error();
|
||||
};
|
||||
1
libs/shared/utils/src/test-setup.ts
Normal file
1
libs/shared/utils/src/test-setup.ts
Normal file
@@ -0,0 +1 @@
|
||||
import 'jest-preset-angular/setup-jest';
|
||||
29
libs/shared/utils/tsconfig.json
Normal file
29
libs/shared/utils/tsconfig.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2022",
|
||||
"useDefineForClassFields": false,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"noImplicitOverride": true,
|
||||
"noPropertyAccessFromIndexSignature": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"files": [],
|
||||
"include": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.lib.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.spec.json"
|
||||
}
|
||||
],
|
||||
"extends": "../../../tsconfig.base.json",
|
||||
"angularCompilerOptions": {
|
||||
"enableI18nLegacyMessageIdFormat": false,
|
||||
"strictInjectionParameters": true,
|
||||
"strictInputAccessModifiers": true,
|
||||
"strictTemplates": true
|
||||
}
|
||||
}
|
||||
17
libs/shared/utils/tsconfig.lib.json
Normal file
17
libs/shared/utils/tsconfig.lib.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../../dist/out-tsc",
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"inlineSources": true,
|
||||
"types": []
|
||||
},
|
||||
"exclude": [
|
||||
"src/test-setup.ts",
|
||||
"src/**/*.spec.ts",
|
||||
"jest.config.ts",
|
||||
"src/**/*.test.ts"
|
||||
],
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
15
libs/shared/utils/tsconfig.spec.json
Normal file
15
libs/shared/utils/tsconfig.spec.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../../dist/out-tsc",
|
||||
"module": "commonjs",
|
||||
"types": ["jest", "node"]
|
||||
},
|
||||
"files": ["src/test-setup.ts"],
|
||||
"include": [
|
||||
"jest.config.ts",
|
||||
"src/**/*.test.ts",
|
||||
"src/**/*.spec.ts",
|
||||
"src/**/*.d.ts"
|
||||
]
|
||||
}
|
||||
@@ -21,6 +21,7 @@
|
||||
"@angular-challenges/ngrx-notification/model": [
|
||||
"libs/ngrx-notification/model/src/index.ts"
|
||||
],
|
||||
"@angular-challenges/shared/utils": ["libs/shared/utils/src/index.ts"],
|
||||
"@tomalaforge/ngrx-callstate-store": [
|
||||
"libs/shared/ngrx-callstate-store/src/index.ts"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user