From feed468527db1665bc49804f8e000f0c890bf22a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 3 Aug 2021 16:05:22 +0200 Subject: [PATCH 01/16] Initial commit --- .gitignore | 132 ++++++ LICENSE | 2 +- README.md | 364 +++++++++++++++ karma.conf.js | 44 ++ ng-package.json | 7 + package-lock.json | 426 ++++++++++++++++++ package.json | 36 ++ src/interface/error-message.interface.ts | 13 + src/lib/error-custom.class.ts | 49 ++ src/lib/error-messages.class.ts | 0 src/lib/validation-error.class.ts | 58 +++ src/message-builder/index.ts | 0 .../lib/message-builder-class.class.ts | 83 ++++ .../lib/message-builder-function.class.ts | 63 +++ .../lib/message-builder-templates.class.ts | 19 + .../lib/message-builder.class.ts | 57 +++ src/public-api.ts | 7 + src/test.ts | 26 ++ src/test/validation-error.spec.ts | 93 ++++ tsconfig.lib.json | 20 + tsconfig.lib.prod.json | 10 + tsconfig.spec.json | 20 + 22 files changed, 1528 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 karma.conf.js create mode 100644 ng-package.json create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 src/interface/error-message.interface.ts create mode 100644 src/lib/error-custom.class.ts create mode 100644 src/lib/error-messages.class.ts create mode 100644 src/lib/validation-error.class.ts create mode 100644 src/message-builder/index.ts create mode 100644 src/message-builder/lib/message-builder-class.class.ts create mode 100644 src/message-builder/lib/message-builder-function.class.ts create mode 100644 src/message-builder/lib/message-builder-templates.class.ts create mode 100644 src/message-builder/lib/message-builder.class.ts create mode 100644 src/public-api.ts create mode 100644 src/test.ts create mode 100644 src/test/validation-error.spec.ts create mode 100644 tsconfig.lib.json create mode 100644 tsconfig.lib.prod.json create mode 100644 tsconfig.spec.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bd724fb --- /dev/null +++ b/.gitignore @@ -0,0 +1,132 @@ +# See http://help.github.com/ignore-files/ for more about ignoring files. + +# compiled output +/dist +/tmp +/out-tsc +# Only exists if Bazel was run +/bazel-out + +# profiling files +chrome-profiler-events*.json +speed-measure-plugin*.json + +# IDEs and editors +/.idea +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# IDE - VSCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +.history/* + +# misc +/.sass-cache +/connect.lock + +# Logs +/libpeerconnection.log +logs +*.log +npm-debug.log* +testem.log +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# next.js build output +.next + +# nuxt.js build output +.nuxt + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +#DynamoDB Local files +.dynamodb/ + +# OS generated files +Thumbs.db +.DS_Store + +# Ignored files +/.vscode/* +*.code-workspace +!.vscode/tasks.json +build +dist +graphics +fonts +*.ignore* + +# demos +demo diff --git a/LICENSE b/LICENSE index 1b01fe0..5c0c291 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 angular package +Copyright (c) 2021 angular-package Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md new file mode 100644 index 0000000..f24f7bd --- /dev/null +++ b/README.md @@ -0,0 +1,364 @@ +# Packages + +Useful and simple to use packages based on the [angular.io][angulario]. + +| Package | Description | Status | +| :----------------------------------- | :------------------------------------------------------ | -----: | +| [callback][callback-github-readme] | Manages the callback [`function`][js-function]. | [![npm version][callback-npm-badge-svg]][callback-npm-badge] | +| [change-detection][cd-github-readme] | Improves application performance. | [![npm version][cd-npm-badge-svg]][cd-npm-badge] | +| [component-loader][cl-github-readme] | Handles dynamic loading components. | [![npm version][cl-npm-badge-svg]][cl-npm-badge] | +| [core][core-github-readme] | Core features. | [![npm version][core-npm-badge-svg]][core-npm-badge] | +| [error][error-github-readme] | Manages an [`Error`][js-error]. | [![npm version][error-npm-badge-svg]][error-npm-badge] | +| [prism][prism-github-readme] | [`Prism`][prism-js] highlighter module. | [![npm version][prism-npm-badge-svg]][prism-npm-badge] | +| [property][property-github-readme] | Handles object properties. | [![npm version][property-npm-badge-svg]][property-npm-badge] | +| [reactive][reactive-github-readme] | Automatize the process of creating some rxjs features. | [![npm version][reactive-npm-badge-svg]][reactive-npm-badge] | +| [testing][testing-github-readme] | Support for testing other packages. | [![npm version][testing-npm-badge-svg]][testing-npm-badge] | +| [type][type-github-readme] | Common types, type guards, and type checkers. | [![npm version][type-npm-badge-svg]][type-npm-badge] | +| [ui][ui-github-readme] | User interface. | *In Progress* | + +> Click on the package name to visit the package. + +## angular-package/error + +Manages an [`Error`][js-error]. + + +[![npm version][error-npm-badge-svg]][error-npm-badge] + +[![GitHub issues][error-badge-issues]][error-issues] +[![GitHub forks][error-badge-forks]][error-forks] +[![GitHub stars][error-badge-stars]][error-stars] +[![GitHub license][error-badge-license]][error-license] + +[![GitHub sponsors][github-badge-sponsor]][github-sponsor-link] +[![Support me on Patreon][patreon-badge]][patreon-link] + +---- + +## Table of contents + +* [Basic concepts](#basic-concepts) +* [Skeleton](#skeleton) +* [Installation](#installation) +* [Api](#api) +* [`ValidationError`](#validationerror) +* [Git](#git) + * [Commit](#commit) + * [Versioning](#versioning) +* [License](#license) + +---- + +
+ +## Basic concepts + +Checks +> It's to check the provided value to be **the same** as **expected**. + +Type guard (constrain) +> Constrains the parameter type to **not let** input **unexpected** value in the **code editor**. + +Guards +> It's a **combination** of both above, **constrains** the type of the parameter in the **code editor**, and checks its provided argument. + +Sets +> Sets the existing given value in the `object`. + +Defines +> Returns defined value from the method of the `object`. +> Defines the new value in the `object`. +> Both above at the same time. + +
+ +## Skeleton + +This package was built by the [library skeleton][skeleton] which was generated with [Angular CLI](https://github.com/angular/angular-cli) version 12.1.1. + +Copy this package to the `packages/error` folder of the [library skeleton][skeleton] then run the commands below. + +### Build + +Run `ng build error` to build the package. The build artifacts will be stored in the `dist/` directory. + +### Running unit tests + +Run `ng test error` to execute the unit tests via [Karma](https://karma-runner.github.io). + +
+ +## Installation + +Install `@angular-package/error` package with command: + +```bash +npm i --save @angular-package/error +``` + +
+ +## Api + +```typescript +import { + // Class. + ValidationError, +} from '@angular-package/error'; +``` + +
+ +## `ValidationError` + +## GIT + +### Commit + +* [AngularJS Git Commit Message Conventions][git-commit-angular] +* [Karma Git Commit Msg][git-commit-karma] +* [Conventional Commits][git-commit-conventional] + +### Versioning + +[Semantic Versioning 2.0.0][git-semver] + +**Given a version number MAJOR.MINOR.PATCH, increment the:** + +* MAJOR version when you make incompatible API changes, +* MINOR version when you add functionality in a backwards-compatible manner, and +* PATCH version when you make backwards-compatible bug fixes. + +Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format. + +**FAQ** +How should I deal with revisions in the 0.y.z initial development phase? + +> The simplest thing to do is start your initial development release at 0.1.0 and then increment the minor version for each subsequent release. + +How do I know when to release 1.0.0? + +> If your software is being used in production, it should probably already be 1.0.0. If you have a stable API on which users have come to depend, you should be 1.0.0. If you’re worrying a lot about backwards compatibility, you should probably already be 1.0.0. + +## License + +MIT © angular-package ([license][callback-license]) + + +[github-badge-sponsor]: https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&link=https://github.com/sponsors/angular-package +[github-sponsor-link]: https://github.com/sponsors/angular-package +[patreon-badge]: https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3Dsciborrudnicki%26type%3Dpatrons&style=flat +[patreon-link]: https://patreon.com/sciborrudnicki + +[angulario]: https://angular.io +[skeleton]: https://github.com/angular-package/skeleton + + +[fix]: https://img.shields.io/badge/-fix-red +[new]: https://img.shields.io/badge/-new-green +[update]: https://img.shields.io/badge/-update-red + + +[git-semver]: http://semver.org/ + + +[git-commit-angular]: https://gist.github.com/stephenparish/9941e89d80e2bc58a153 +[git-commit-karma]: http://karma-runner.github.io/0.10/dev/git-commit-msg.html +[git-commit-conventional]: https://www.conventionalcommits.org/en/v1.0.0/ + + + + [callback-badge-issues]: https://img.shields.io/github/issues/angular-package/callback + [callback-badge-forks]: https://img.shields.io/github/forks/angular-package/callback + [callback-badge-stars]: https://img.shields.io/github/stars/angular-package/callback + [callback-badge-license]: https://img.shields.io/github/license/angular-package/callback + + [callback-issues]: https://github.com/angular-package/callback/issues + [callback-forks]: https://github.com/angular-package/callback/network + [callback-license]: https://github.com/angular-package/callback/blob/master/LICENSE + [callback-stars]: https://github.com/angular-package/callback/stargazers + + + + [callback-npm-badge-svg]: https://badge.fury.io/js/%40angular-package%2Fcallback.svg + [callback-npm-badge]: https://badge.fury.io/js/%40angular-package%2Fcallback + [callback-npm-readme]: https://www.npmjs.com/package/@angular-package/callback#readme + + + [callback-github-readme]: https://github.com/angular-package/callback#readme + + + + [cd-npm-badge-svg]: https://badge.fury.io/js/%40angular-package%2Fchange-detection.svg + [cd-npm-badge]: https://badge.fury.io/js/%40angular-package%2Fchange-detection + [cd-npm-readme]: https://www.npmjs.com/package/@angular-package/change-detection#readme + + + [cd-github-readme]: https://github.com/angular-package/change-detection#readme + + + + [cl-npm-badge-svg]: https://badge.fury.io/js/%40angular-package%2Fcomponent-loader.svg + [cl-npm-badge]: https://badge.fury.io/js/%40angular-package%2Fcomponent-loader + [cl-npm-readme]: https://www.npmjs.com/package/@angular-package/component-loader#readme + + + [cl-github-readme]: https://github.com/angular-package/component-loader#readme + + + + [core-npm-badge-svg]: https://badge.fury.io/js/%40angular-package%2Fcore.svg + [core-npm-badge]: https://badge.fury.io/js/%40angular-package%2Fcore + [core-npm-readme]: https://www.npmjs.com/package/@angular-package/core#readme + + + [core-github-readme]: https://github.com/angular-package/core#readme + + + + [error-npm-badge-svg]: https://badge.fury.io/js/%40angular-package%2Ferror.svg + [error-npm-badge]: https://badge.fury.io/js/%40angular-package%2Ferror + [error-npm-readme]: https://www.npmjs.com/package/@angular-package/error#readme + + + [error-github-readme]: https://github.com/angular-package/error#readme + + + + [prism-npm-badge-svg]: https://badge.fury.io/js/%40angular-package%2Fprism.svg + [prism-npm-badge]: https://badge.fury.io/js/%40angular-package%2Fprism + [prism-npm-readme]: https://www.npmjs.com/package/@angular-package/prism#readme + + + [prism-github-readme]: https://github.com/angular-package/prism#readme + + + + [property-npm-badge-svg]: https://badge.fury.io/js/%40angular-package%2Fproperty.svg + [property-npm-badge]: https://badge.fury.io/js/%40angular-package%2Fproperty + [property-npm-readme]: https://www.npmjs.com/package/@angular-package/property#readme + + + [property-github-readme]: https://github.com/angular-package/property#readme + + + + [reactive-npm-badge-svg]: https://badge.fury.io/js/%40angular-package%2Freactive.svg + [reactive-npm-badge]: https://badge.fury.io/js/%40angular-package%2Freactive + [reactive-npm-readme]: https://www.npmjs.com/package/@angular-package/reactive#readme + + + [reactive-github-readme]: https://github.com/angular-package/reactive#readme + + + + [testing-npm-badge-svg]: https://badge.fury.io/js/%40angular-package%2Ftesting.svg + [testing-npm-badge]: https://badge.fury.io/js/%40angular-package%2Ftesting + [testing-npm-readme]: https://www.npmjs.com/package/@angular-package/testing#readme + + + [testing-github-readme]: https://github.com/angular-package/testing#readme + + + + [type-npm-badge-svg]: https://badge.fury.io/js/%40angular-package%2Ftype.svg + [type-npm-badge]: https://badge.fury.io/js/%40angular-package%2Ftype + [type-npm-readme]: https://www.npmjs.com/package/@angular-package/type#readme + + + [type-github-readme]: https://github.com/angular-package/type#readme + + [package-type-resultcallback]: https://github.com/angular-package/type#resultcallback + [package-type-key]: https://github.com/angular-package/type#key + + + + [ui-npm-badge-svg]: https://badge.fury.io/js/%40angular-package%2Fui.svg + [ui-npm-badge]: https://badge.fury.io/js/%40angular-package%2Fui + [ui-npm-readme]: https://www.npmjs.com/package/@angular-package/ui#readme + + + [ui-github-readme]: https://github.com/angular-package/ui#readme + + +[angular-component-factory-resolver]: https://angular.io/api/core/ComponentFactoryResolver +[angular-view-container-ref]: https://angular.io/api/core/ViewContainerRef + + +[jasmine-describe]: https://jasmine.github.io/api/3.8/global.html#describe +[jasmine-expect]: https://jasmine.github.io/api/3.8/global.html#expect +[jasmine-it]: https://jasmine.github.io/api/3.8/global.html#it + + +[js-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array +[js-array-every]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every +[js-array-some]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some + +[js-bigint]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt +[js-bigintconstructor]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt + +[js-boolean]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean +[js-booleanconstructor]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/Boolean + +[js-classes]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes + +[js-date]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date + +[js-error]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error + +[js-function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions +[js-function-rest-parameter]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters + +[js-getter]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get +[js-object-getownpropertydescriptor]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor +[js-object-getOwnpropertydescriptors]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors + +[js-setter]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set + +[js-hasownproperty]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty + +[js-instanceof]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof +[js-in-operator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/in + +[js-map]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map + +[js-null]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null +[js-number]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number +[js-numberconstructor]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/Number + +[js-object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object +[js-object-define-property]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty + +[js-primitive]: https://developer.mozilla.org/en-US/docs/Glossary/Primitive +[js-promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise + +[js-rangeerror]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError +[js-referenceerror]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError +[js-regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp + +[js-set]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set +[js-storage]: https://developer.mozilla.org/en-US/docs/Web/API/Storage +[js-string]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String +[js-stringconstructor]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/String + +[js-symbol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol +[js-symbolconstructor]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/Symbol +[js-syntaxerror]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError + +[js-typeerror]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError + +[js-undefined]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined +[js-urlerror]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError + +[js-weakset]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet + + +[karma]: http://karma-runner.github.io/0.10/index.html + + +[prism-js]: https://prismjs.com/ + + +[ts-classes]: https://www.typescriptlang.org/docs/handbook/2/classes.html +[ts-function]: https://www.typescriptlang.org/docs/handbook/2/functions.html +[ts-interface]: https://www.typescriptlang.org/docs/handbook/interfaces.html#our-first-interface diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000..be9ad6b --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,44 @@ +// Karma configuration file, see link for more information +// https://karma-runner.github.io/1.0/config/configuration-file.html + +module.exports = function (config) { + config.set({ + basePath: '', + frameworks: ['jasmine', '@angular-devkit/build-angular'], + plugins: [ + require('karma-jasmine'), + require('karma-chrome-launcher'), + require('karma-jasmine-html-reporter'), + require('karma-coverage'), + require('@angular-devkit/build-angular/plugins/karma') + ], + client: { + jasmine: { + // you can add configuration options for Jasmine here + // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html + // for example, you can disable the random execution with `random: false` + // or set a specific seed with `seed: 4321` + }, + clearContext: false // leave Jasmine Spec Runner output visible in browser + }, + jasmineHtmlReporter: { + suppressAll: true // removes the duplicated traces + }, + coverageReporter: { + dir: require('path').join(__dirname, '../../coverage/error'), + subdir: '.', + reporters: [ + { type: 'html' }, + { type: 'text-summary' } + ] + }, + reporters: ['progress', 'kjhtml'], + port: 9876, + colors: true, + logLevel: config.LOG_INFO, + autoWatch: true, + browsers: ['Chrome'], + singleRun: false, + restartOnFileChange: true + }); +}; diff --git a/ng-package.json b/ng-package.json new file mode 100644 index 0000000..87acb8b --- /dev/null +++ b/ng-package.json @@ -0,0 +1,7 @@ +{ + "$schema": "../../node_modules/ng-packagr/ng-package.schema.json", + "dest": "../../dist/error", + "lib": { + "entryFile": "src/public-api.ts" + } +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..6e283c4 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,426 @@ +{ + "name": "error", + "version": "0.0.1", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "version": "0.0.1", + "dependencies": { + "tslib": "^2.2.0" + }, + "devDependencies": { + "@angular-package/testing": "^1.1.0" + }, + "peerDependencies": { + "@angular-package/type": "^4.2.0", + "@angular/common": "^12.1.1", + "@angular/core": "^12.1.1" + } + }, + "node_modules/@angular-package/testing": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@angular-package/testing/-/testing-1.1.0.tgz", + "integrity": "sha512-N/c75WBG4GPcgj7NYWAKSE9IwcPSqVMOYjkZ3RU4rUZW5equkjZvQ4zWKc8S4lbxr1wPD6KxPy3T52xTsBW3Dw==", + "dev": true, + "dependencies": { + "tslib": "^2.2.0" + }, + "peerDependencies": { + "@angular-package/type": ">= 4.2.0", + "jasmine": "^3.8.0" + } + }, + "node_modules/@angular-package/type": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/@angular-package/type/-/type-4.2.0.tgz", + "integrity": "sha512-Y7HT94Gia4soR2ynwK8qva0WTOplau++gInEQCwDnhXmYy/r/1J/XhW0+aVj5XIa3SLWWa70nHvI0ivBM7O1nw==", + "peer": true, + "dependencies": { + "tslib": "^2.1.0" + } + }, + "node_modules/@angular/common": { + "version": "12.1.4", + "resolved": "https://registry.npmjs.org/@angular/common/-/common-12.1.4.tgz", + "integrity": "sha512-cyh2m5veGgWRFsrmPnwB/Ised90bFNZAjZepvW8WXrpEUa/tmi1yWU9+8ayRG7ztE08lyXncJSSut2Ss2PEhTA==", + "peer": true, + "dependencies": { + "tslib": "^2.2.0" + }, + "engines": { + "node": "^12.14.1 || >=14.0.0" + }, + "peerDependencies": { + "@angular/core": "12.1.4", + "rxjs": "^6.5.3" + } + }, + "node_modules/@angular/core": { + "version": "12.1.4", + "resolved": "https://registry.npmjs.org/@angular/core/-/core-12.1.4.tgz", + "integrity": "sha512-dG7KtW0l3jI8lapmenSu1wV/d3VOphAjDxVqWOrwh+kI0da7677cEg0Ms5YIF8Nf/++WleyNxk6AIHbDIig+Sw==", + "peer": true, + "dependencies": { + "tslib": "^2.2.0" + }, + "engines": { + "node": "^12.14.1 || >=14.0.0" + }, + "peerDependencies": { + "rxjs": "^6.5.3", + "zone.js": "~0.11.4" + } + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true, + "peer": true + }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "peer": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true, + "peer": true + }, + "node_modules/fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true, + "peer": true + }, + "node_modules/glob": { + "version": "7.1.7", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz", + "integrity": "sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==", + "dev": true, + "peer": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "peer": true, + "dependencies": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true, + "peer": true + }, + "node_modules/jasmine": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-3.8.0.tgz", + "integrity": "sha512-kdQ3SfcNpMbbMdgJPLyFe9IksixdnrgYaCJapP9sS0aLgdWdIZADNXEr+11Zafxm1VDfRSC5ZL4fzXT0bexzXw==", + "dev": true, + "peer": true, + "dependencies": { + "glob": "^7.1.6", + "jasmine-core": "~3.8.0" + }, + "bin": { + "jasmine": "bin/jasmine.js" + } + }, + "node_modules/jasmine-core": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.8.0.tgz", + "integrity": "sha512-zl0nZWDrmbCiKns0NcjkFGYkVTGCPUgoHypTaj+G2AzaWus7QGoXARSlYsSle2VRpSdfJmM+hzmFKzQNhF2kHg==", + "dev": true, + "peer": true + }, + "node_modules/minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "peer": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "peer": true, + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true, + "peer": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/rxjs": { + "version": "6.6.7", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", + "integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==", + "peer": true, + "dependencies": { + "tslib": "^1.9.0" + }, + "engines": { + "npm": ">=2.0.0" + } + }, + "node_modules/rxjs/node_modules/tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "peer": true + }, + "node_modules/tslib": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz", + "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==" + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true, + "peer": true + }, + "node_modules/zone.js": { + "version": "0.11.4", + "resolved": "https://registry.npmjs.org/zone.js/-/zone.js-0.11.4.tgz", + "integrity": "sha512-DDh2Ab+A/B+9mJyajPjHFPWfYU1H+pdun4wnnk0OcQTNjem1XQSZ2CDW+rfZEUDjv5M19SBqAkjZi0x5wuB5Qw==", + "peer": true, + "dependencies": { + "tslib": "^2.0.0" + } + } + }, + "dependencies": { + "@angular-package/testing": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@angular-package/testing/-/testing-1.1.0.tgz", + "integrity": "sha512-N/c75WBG4GPcgj7NYWAKSE9IwcPSqVMOYjkZ3RU4rUZW5equkjZvQ4zWKc8S4lbxr1wPD6KxPy3T52xTsBW3Dw==", + "dev": true, + "requires": { + "tslib": "^2.2.0" + } + }, + "@angular-package/type": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/@angular-package/type/-/type-4.2.0.tgz", + "integrity": "sha512-Y7HT94Gia4soR2ynwK8qva0WTOplau++gInEQCwDnhXmYy/r/1J/XhW0+aVj5XIa3SLWWa70nHvI0ivBM7O1nw==", + "peer": true, + "requires": { + "tslib": "^2.1.0" + } + }, + "@angular/common": { + "version": "12.1.4", + "resolved": "https://registry.npmjs.org/@angular/common/-/common-12.1.4.tgz", + "integrity": "sha512-cyh2m5veGgWRFsrmPnwB/Ised90bFNZAjZepvW8WXrpEUa/tmi1yWU9+8ayRG7ztE08lyXncJSSut2Ss2PEhTA==", + "peer": true, + "requires": { + "tslib": "^2.2.0" + } + }, + "@angular/core": { + "version": "12.1.4", + "resolved": "https://registry.npmjs.org/@angular/core/-/core-12.1.4.tgz", + "integrity": "sha512-dG7KtW0l3jI8lapmenSu1wV/d3VOphAjDxVqWOrwh+kI0da7677cEg0Ms5YIF8Nf/++WleyNxk6AIHbDIig+Sw==", + "peer": true, + "requires": { + "tslib": "^2.2.0" + } + }, + "balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true, + "peer": true + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "peer": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true, + "peer": true + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true, + "peer": true + }, + "glob": { + "version": "7.1.7", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz", + "integrity": "sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==", + "dev": true, + "peer": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "peer": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true, + "peer": true + }, + "jasmine": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-3.8.0.tgz", + "integrity": "sha512-kdQ3SfcNpMbbMdgJPLyFe9IksixdnrgYaCJapP9sS0aLgdWdIZADNXEr+11Zafxm1VDfRSC5ZL4fzXT0bexzXw==", + "dev": true, + "peer": true, + "requires": { + "glob": "^7.1.6", + "jasmine-core": "~3.8.0" + } + }, + "jasmine-core": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.8.0.tgz", + "integrity": "sha512-zl0nZWDrmbCiKns0NcjkFGYkVTGCPUgoHypTaj+G2AzaWus7QGoXARSlYsSle2VRpSdfJmM+hzmFKzQNhF2kHg==", + "dev": true, + "peer": true + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "peer": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "peer": true, + "requires": { + "wrappy": "1" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true, + "peer": true + }, + "rxjs": { + "version": "6.6.7", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", + "integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==", + "peer": true, + "requires": { + "tslib": "^1.9.0" + }, + "dependencies": { + "tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "peer": true + } + } + }, + "tslib": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz", + "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==" + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true, + "peer": true + }, + "zone.js": { + "version": "0.11.4", + "resolved": "https://registry.npmjs.org/zone.js/-/zone.js-0.11.4.tgz", + "integrity": "sha512-DDh2Ab+A/B+9mJyajPjHFPWfYU1H+pdun4wnnk0OcQTNjem1XQSZ2CDW+rfZEUDjv5M19SBqAkjZi0x5wuB5Qw==", + "peer": true, + "requires": { + "tslib": "^2.0.0" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..6188824 --- /dev/null +++ b/package.json @@ -0,0 +1,36 @@ +{ + "description": "Manages the callback function.", + "author": "Angular Package (https://wvvw.dev)", + "homepage": "https://github.com/angular-package/testing#readme", + "peerDependencies": { + "@angular-package/type": "^4.2.0", + "@angular/common": "^12.1.1", + "@angular/core": "^12.1.1" + }, + "dependencies": { + "tslib": "^2.2.0" + }, + "devDependencies": { + "@angular-package/testing": "^1.1.0" + }, + "publishConfig": { + "access": "public", + "registry": "https://registry.npmjs.org" + }, + "keywords": [ + "@angular", + "@angular-package", + "@angular-package/error", + "angular-package", + "Error" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/angular-package/error.git" + }, + "bugs": { + "url": "https://github.com/angular-package/error/issues" + }, + "license": "MIT" + +} diff --git a/src/interface/error-message.interface.ts b/src/interface/error-message.interface.ts new file mode 100644 index 0000000..614e954 --- /dev/null +++ b/src/interface/error-message.interface.ts @@ -0,0 +1,13 @@ +/** + * The shape of an `object` for the error message that contains a possible solution to the described problem. + */ +export interface ErrorMessage { + /** + * Possible solution to the described problem of a `string` type. + */ + fix: string; + /** + * Error problem of a `string` type. + */ + problem: string; +} diff --git a/src/lib/error-custom.class.ts b/src/lib/error-custom.class.ts new file mode 100644 index 0000000..23a10d2 --- /dev/null +++ b/src/lib/error-custom.class.ts @@ -0,0 +1,49 @@ +import { guard } from '@angular-package/type'; +import { MessageBuilderClass } from '../message-builder/lib/message-builder-class.class'; +import { MessageBuilderFunction } from '../message-builder/lib/message-builder-function.class'; +import { MessageBuilder } from '../message-builder/lib/message-builder.class'; + +export interface ConfigError { + problem: string; + fix?: string; +} + +new MessageBuilderClass(); +new MessageBuilderFunction(); + +export class ErrorCustom { + + public date: Date = new Date(); + public fix: string; + public problem: string; + + constructor(config: ConfigError) { + if (guard.is.string(config?.fix)) { + this.fix = config.fix; + } + if (guard.is.string(config?.problem)) { + this.problem = config.problem; + } + this.date = new Date(); + } + + private message(): string { + return ` + Problem: ${this.problem} + Fix: ${this.fix} + Date: ${this.date} + `; + } + + public error(): void { + throw new Error(this.message()); + } + + public syntax(): void { + throw new SyntaxError(this.message()); + } + + public type(): void { + throw new TypeError(this.message()); + } +} diff --git a/src/lib/error-messages.class.ts b/src/lib/error-messages.class.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/lib/validation-error.class.ts b/src/lib/validation-error.class.ts new file mode 100644 index 0000000..e111767 --- /dev/null +++ b/src/lib/validation-error.class.ts @@ -0,0 +1,58 @@ +// Object. +import { is } from '@angular-package/type'; +// Interface. +import { ErrorMessage } from '../interface/error-message.interface'; +/** + * Manages an `Error` of the validation. + */ +export class ValidationError extends Error { + /** + * Template of the error message with the replaceable [problem] and [fix]. + */ + static template = `Problem: [problem] => Fix: [fix]`; + + /** + * Possible solution to the described problem of a `string` type. + */ + public fix = ''; + + /** + * Error name of a string type that is being thrown. By default, it's `ValidationError`. + */ + public name = ValidationError.name; + + /** + * The validation problem of a `string` type. By default, it's an empty string. + */ + public problem = ''; + + /** + * Defines the validation error message of a `string` type from the provided `message` of `ErrorMessage` interface. + * @param message An object of an `ErrorMessage` interface to build the message of a `string` type. The value is checked against + * the proper object. + * @returns The return value is a message of a `string` type created from the provided `message` of `ErrorMessage` interface. + */ + static defineMessage(message: ErrorMessage): string { + if (is.objectKey(message, ['fix', 'problem'])) { + return ValidationError.template + .replace(`[fix]`, message.fix) + .replace(`[problem]`, message.problem); + } + return ''; + } + + /** + * Creates a new instance with the message. If the provided `message` is an `object`, then its properties are assigned + * to the instance. + * @param message The message of a `string` type or of an `ErrorMessage` interface that is used to throw with an `error`. + */ + constructor(message: string | ErrorMessage) { + super(is.string(message) ? message : ValidationError.defineMessage(message)); + if (is.object(message)) { + Object.assign(this, { + problem: message.problem, + fix: message.fix, + }); + } + } +} diff --git a/src/message-builder/index.ts b/src/message-builder/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/message-builder/lib/message-builder-class.class.ts b/src/message-builder/lib/message-builder-class.class.ts new file mode 100644 index 0000000..f5bd1c7 --- /dev/null +++ b/src/message-builder/lib/message-builder-class.class.ts @@ -0,0 +1,83 @@ +import { is, guard } from '@angular-package/type'; +import { MessageBuilderTemplates } from './message-builder-templates.class'; +import { MessageBuilder } from './message-builder.class'; + +export class MessageBuilderClass extends MessageBuilder { + private class$$: string; + private param$$: { + name?: string; + type?: string; + } = {}; + private method$$: string; + + constructor() { + super('class'); + } + + /** + * Build class message. + */ + public build(): this { + // class. + // this.replace('class', this.class$$); + // // method. + // this.replace('method', is.string(this.method$$) && is.string(this.class$$) ? `.${this.method$$}` : this.method$$); + // // param. + // const param = `${this.param$$.name}${this.param$$.type}`; + // this + // .replace('param.type', this.param$$.type) + // .replace('param.name', this.param$$.name) + // .replace(param, `(${param})`) + // .replace(this.param$$.type, `: ${this.param$$.type}`); + return this; + } + + /** + * Set class name to build message. + * @param name Class name. + * @returns this. + */ + public class(name: string): this { + if (guard.is.string(name)) { + this.class$$ = name; + } + return this; + } + + /** + * Set class method name to build message. + * @param name Class method name. + * @returns this. + */ + public method(name: string): this { + if (guard.is.string(name)) { + this.method$$ = name; + } + return this; + } + + /** + * Set method param name with type to build message. + * @param name Method param name. + * @param type Method param type. + * @returns this. + */ + public param(name: string, type?: string): this { + if (guard.is.string(name)) { + this.param$$.name = name; + } + if (guard.is.string(type)) { + this.param$$.type = type; + } + return this; + } +} + +const messageBuilderClass: MessageBuilderClass = new MessageBuilderClass() + .class('NameProperty') + .method('set') + .param('name', 'Array') + .build(); + +console.log(`messageBuilderClass`, messageBuilderClass.get); + diff --git a/src/message-builder/lib/message-builder-function.class.ts b/src/message-builder/lib/message-builder-function.class.ts new file mode 100644 index 0000000..ea8a618 --- /dev/null +++ b/src/message-builder/lib/message-builder-function.class.ts @@ -0,0 +1,63 @@ +import { guard } from '@angular-package/type'; +import { MessageBuilder } from './message-builder.class'; + +export class MessageBuilderFunction { + private builder$$: MessageBuilder; + private function$$: string; + private param$$: { + name?: string; + type?: string; + } = {}; + private method$$: string; + + get get(): string { + return this.builder$$.get; + } + + constructor() { + this.builder$$ = new MessageBuilder('function'); + } + + /** + * Build function message. + */ + public build(): this { + // function. + this.builder$$.function(this.function$$); + // param. + this.builder$$.param(this.param$$.name, this.param$$.type) + return this; + } + + /** + * Set class name to build message. + * @param name Class name. + * @returns this. + */ + public function(name: string): this { + if (guard.is.string(name)) { + this.function$$ = name; + } + return this; + } + + /** + * Set method param name with type to build message. + * @param name Method param name. + * @param type Method param type. + * @returns this. + */ + public param(name: string, type?: string): this { + if (guard.is.string(name)) { + this.param$$.name = name; + } + if (guard.is.string(type)) { + this.param$$.type = type; + } + return this; + } +} + +const messageBuilderFunction: MessageBuilderFunction = new MessageBuilderFunction(); +messageBuilderFunction.function('myFunction').param('one', 'string').build(); +console.log(`messageBuilderFunction`, messageBuilderFunction.get); diff --git a/src/message-builder/lib/message-builder-templates.class.ts b/src/message-builder/lib/message-builder-templates.class.ts new file mode 100644 index 0000000..d4ac0bf --- /dev/null +++ b/src/message-builder/lib/message-builder-templates.class.ts @@ -0,0 +1,19 @@ +import { is } from '@angular-package/type'; + +export class MessageBuilderTemplates { + private templates$$ = { + class: `[class][method][param.name][param.type]`, // argument value is [value.type] type, must be [param.type] type + function: `[function][param.name][param.type]` + }; + private type$$: string; + + get get(): string { + return this.templates$$[this.type$$]; + } + + constructor(type: 'class' | 'function') { + if (is.string(type)) { + this.type$$ = type; + } + } +} diff --git a/src/message-builder/lib/message-builder.class.ts b/src/message-builder/lib/message-builder.class.ts new file mode 100644 index 0000000..b95a229 --- /dev/null +++ b/src/message-builder/lib/message-builder.class.ts @@ -0,0 +1,57 @@ +import { is } from '@angular-package/type'; +import { MessageBuilderTemplates } from './message-builder-templates.class'; + +// export type RegExpPreDefined = 'class' | 'function' | 'method' | 'param.name' | 'param.type'; + +export class MessageBuilder { + private regExp$$ = { + class: /\[class\]/i, + function: /\[function\]/i, + method: /\[method\]/i, + param: { + name: /\[param.name\]/i, + type: /\[param.type\]/i + } + }; + private template$$: string; + + get get(): string { + return this.template$$; + } + + constructor(template: 'class' | 'function') { + this.template$$ = new MessageBuilderTemplates(template).get; + } + + public class(name: string): this { + this.replace(this.regExp$$.class, name); + return this; + } + + public function(name: string): this { + this.replace(this.regExp$$.function, name); + return this; + } + + public method(name: string): this { + this.replace(this.regExp$$.method, name); + return this; + } + + public param(name: string, type?: string): this { + const param = `${name}${type}`; + this + .replace(this.regExp$$.param.type, type) + .replace(this.regExp$$.param.name, name) + .replace(param, `(${param})`) + .replace(type, `: ${type}`); + return this; + } + + public replace(searchValue: string | RegExp, replaceValue: string): this { + if (is.defined(searchValue)) { + this.template$$ = this.template$$.replace(searchValue, is.string(replaceValue) ? replaceValue : ''); + } + return this; + } +} diff --git a/src/public-api.ts b/src/public-api.ts new file mode 100644 index 0000000..b43a6fd --- /dev/null +++ b/src/public-api.ts @@ -0,0 +1,7 @@ +/* + * Public API Surface of error + */ +// Class. +export { ValidationError } from './lib/validation-error.class'; +// Interface. +export { ErrorMessage } from './interface/error-message.interface'; diff --git a/src/test.ts b/src/test.ts new file mode 100644 index 0000000..52e5516 --- /dev/null +++ b/src/test.ts @@ -0,0 +1,26 @@ +// This file is required by karma.conf.js and loads recursively all the .spec and framework files + +import 'zone.js'; +import 'zone.js/testing'; +import { getTestBed } from '@angular/core/testing'; +import { + BrowserDynamicTestingModule, + platformBrowserDynamicTesting +} from '@angular/platform-browser-dynamic/testing'; + +declare const require: { + context(path: string, deep?: boolean, filter?: RegExp): { + keys(): string[]; + (id: string): T; + }; +}; + +// First, initialize the Angular testing environment. +getTestBed().initTestEnvironment( + BrowserDynamicTestingModule, + platformBrowserDynamicTesting() +); +// Then we find all the tests. +const context = require.context('./', true, /\.spec\.ts$/); +// And load the modules. +context.keys().map(context); diff --git a/src/test/validation-error.spec.ts b/src/test/validation-error.spec.ts new file mode 100644 index 0000000..b03e9b5 --- /dev/null +++ b/src/test/validation-error.spec.ts @@ -0,0 +1,93 @@ +// External class. +import { Testing, TestingToBeMatchers } from '@angular-package/testing'; +// Class. +import { ValidationError } from '../lib/validation-error.class'; +/** + * Initialize `Testing`. + */ +const testing = new Testing(false, true); +const toBe = new TestingToBeMatchers(); +/** + * Tests. + */ +testing.describe('ValidationError', () => { + testing.describe('throw', () => { + const problem = 'My callback problem'; + const fix = 'Possible fix does not exist'; + try { + throw new ValidationError({ problem, fix }); + } catch (e: any) { + testing + .toBeClass(ValidationError) + .toBe('instanceof ValidationError', e instanceof ValidationError, true) + .toBeStringType( + e.problem, + undefined, + '`e.problem` must be of a `string` type' + ) + .toBeStringType(e.fix, undefined, '`e.fix` must be of a `string` type'); + } + }); + + testing.describe('instantiate', () => { + let fix: any; + let problem: any; + let validationError: any; + + beforeEach(() => { + fix = 'There is no solution to the described problem.'; + problem = 'The problem has no solution.'; + validationError = new ValidationError({ fix, problem }); + }); + + testing.it(`with the message of a \`string\` type`, () => { + const message = 'Validation error message'; + validationError = new ValidationError(message); + toBe.string(validationError.message); + expect(validationError.message).toContain(message); + }); + + testing.it(`with the message of the \`ErrorMessage\` interface`, () => { + toBe + .string(validationError.message) + .string(validationError.problem) + .string(validationError.fix); + + // to Equal. + expect(validationError.problem).toEqual(problem); + expect(validationError.fix).toEqual(fix); + expect(validationError.message).toEqual( + ValidationError.template + .replace(`[fix]`, fix) + .replace(`[problem]`, problem) + ); + // toContain. + expect(validationError.message).toContain(fix); + expect(validationError.message).toContain(problem); + }); + }); + + testing.describe('static defineMessage()', () => { + let fix: any; + let problem: any; + let errorMessage: any; + + beforeEach(() => { + fix = 'There is no solution to the described problem.'; + problem = 'The problem has no solution.'; + errorMessage = ValidationError.defineMessage({ fix, problem }); + }); + + testing.it(`with the message of the \`ErrorMessage\` interface`, () => { + toBe.string(errorMessage); + expect(errorMessage).toEqual( + ValidationError.template + .replace(`[fix]`, fix) + .replace(`[problem]`, problem) + ); + // toContain. + expect(errorMessage).toContain(fix); + expect(errorMessage).toContain(problem); + }); + }); +}); diff --git a/tsconfig.lib.json b/tsconfig.lib.json new file mode 100644 index 0000000..1407202 --- /dev/null +++ b/tsconfig.lib.json @@ -0,0 +1,20 @@ +/* To learn more about this file see: https://angular.io/config/tsconfig. */ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "../../out-tsc/lib", + "target": "es2015", + "declaration": true, + "declarationMap": true, + "inlineSources": true, + "types": [], + "lib": [ + "dom", + "es2018" + ] + }, + "exclude": [ + "src/test.ts", + "**/*.spec.ts" + ] +} diff --git a/tsconfig.lib.prod.json b/tsconfig.lib.prod.json new file mode 100644 index 0000000..06de549 --- /dev/null +++ b/tsconfig.lib.prod.json @@ -0,0 +1,10 @@ +/* To learn more about this file see: https://angular.io/config/tsconfig. */ +{ + "extends": "./tsconfig.lib.json", + "compilerOptions": { + "declarationMap": false + }, + "angularCompilerOptions": { + "compilationMode": "partial" + } +} diff --git a/tsconfig.spec.json b/tsconfig.spec.json new file mode 100644 index 0000000..bc7fbe9 --- /dev/null +++ b/tsconfig.spec.json @@ -0,0 +1,20 @@ +/* To learn more about this file see: https://angular.io/config/tsconfig. */ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "../../out-tsc/spec", + "paths": { + "@angular/*": [ "./node_modules/@angular/*" ] + }, + "types": [ + "jasmine" + ] + }, + "files": [ + "src/test.ts" + ], + "include": [ + "**/*.spec.ts", + "**/*.d.ts" + ] +} From a503b8929c98b2646f676a9572437b2c6c9349ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 3 Aug 2021 16:06:39 +0200 Subject: [PATCH 02/16] docs(README.md): fix badges --- README.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index f24f7bd..0cd1290 100644 --- a/README.md +++ b/README.md @@ -166,17 +166,18 @@ MIT © angular-package ([license][callback-license]) [git-commit-karma]: http://karma-runner.github.io/0.10/dev/git-commit-msg.html [git-commit-conventional]: https://www.conventionalcommits.org/en/v1.0.0/ - + - [callback-badge-issues]: https://img.shields.io/github/issues/angular-package/callback - [callback-badge-forks]: https://img.shields.io/github/forks/angular-package/callback - [callback-badge-stars]: https://img.shields.io/github/stars/angular-package/callback - [callback-badge-license]: https://img.shields.io/github/license/angular-package/callback + [error-badge-issues]: https://img.shields.io/github/issues/angular-package/error + [error-badge-forks]: https://img.shields.io/github/forks/angular-package/error + [error-badge-stars]: https://img.shields.io/github/stars/angular-package/error + [error-badge-license]: https://img.shields.io/github/license/angular-package/error - [callback-issues]: https://github.com/angular-package/callback/issues - [callback-forks]: https://github.com/angular-package/callback/network - [callback-license]: https://github.com/angular-package/callback/blob/master/LICENSE - [callback-stars]: https://github.com/angular-package/callback/stargazers + [error-issues]: https://github.com/angular-package/error/issues + [error-forks]: https://github.com/angular-package/error/network + [error-license]: https://github.com/angular-package/error/blob/master/LICENSE + [error-stars]: https://github.com/angular-package/error/stargazers + From 5cf36f1a1b965449ac28ed87b9fbb616d25ee4fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 3 Aug 2021 16:07:49 +0200 Subject: [PATCH 03/16] docs(README.md): fix license --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0cd1290..8b55ff0 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ How do I know when to release 1.0.0? ## License -MIT © angular-package ([license][callback-license]) +MIT © angular-package ([license][error-license]) [github-badge-sponsor]: https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&link=https://github.com/sponsors/angular-package From e6ae428a9dca04c0735272c7abd7ce7809f7d739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 3 Aug 2021 18:22:43 +0200 Subject: [PATCH 04/16] docs(README.md): add description --- README.md | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) diff --git a/README.md b/README.md index 8b55ff0..029e1e3 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Manages an [`Error`][js-error]. * [Installation](#installation) * [Api](#api) * [`ValidationError`](#validationerror) +* [Interface](#interface) * [Git](#git) * [Commit](#commit) * [Versioning](#versioning) @@ -104,6 +105,8 @@ npm i --save @angular-package/error import { // Class. ValidationError, + // Interface. + ErrorMessage, } from '@angular-package/error'; ``` @@ -111,6 +114,178 @@ import { ## `ValidationError` +Manages an [`Error`][js-error] of the validation. + +**Static methods:** + +| Methods | Description | +| :----------------------------------------------------------------- | :---------- | +| [`ValidationError.defineMessage()`](#validationerrordefinemessage) | Defines the error message of a [`string`][js-string] type from the provided `message` of an [`object`][js-object] | + +**Constructor:** + +| Constructor | Description | +| :-------------------------------------------------- | :---------- | +| [`ValidationError()`](#validationerror-constructor) | Creates a new instance with the message. If the provided `message` is an [`object`][js-object], then its properties are assigned to the instance | + +
+ +## `ValidationError` static properties + +### `ValidationError.template` + +Template of the error message with the replaceable `[problem]` and `[fix]`. + +```typescript +static template = `Problem: [problem] => Fix: [fix]`; +``` + +
+ +## `ValidationError` instance public properties + +### `ValidationError.prototype.fix` + +A possible solution to the described problem of a [`string`][js-string] type. By default, it's an empty [`string`][js-string]. + +```typescript +public fix = ''; +``` + +
+ +### `ValidationError.prototype.name` + +Error name of a string type that is being thrown. By default, it's `ValidationError`. + +```typescript +public name = ValidationError.name; +``` + +
+ +### `ValidationError.prototype.problem` + +The validation problem of a [`string`][js-string] type. By default, it's an empty string. + +```typescript +public problem = ''; +``` + +
+ +## `ValidationError` static methods + +### `ValidationError.defineMessage()` + +Defines the validation error message of a [`string`][js-string] type from the provided `message` of the [`ErrorMessage`](#errormessage) interface. + +```typescript +static defineMessage(message: ErrorMessage): string { + if (is.objectKey(message, ['fix', 'problem'])) { + return `Problem: ${message.problem}. ${ + is.string(message.fix) ? `Fix: ${message.fix}` : '' + }`; + } + return ''; +} +``` + +**Parameters:** + +| Name: type | Description | +| :---------------------- | :---------- | +| `message: ErrorMessage` | An [`object`][js-object] of the [`ErrorMessage`](#errormessage) interface to build a message of a [`string`][js-string] type. The value is checked against the proper [`object`][js-object] | + +**Returns:** + +The **return value** is a message of a `string` type created from the provided `message` of [`ErrorMessage`](#errormessage) interface, or it's an empty `string` if the provided message object isn't proper. + +**Usage:** + +```typescript +// Example usage. +import { ValidationError } from '@angular-package/core'; + +const fix = 'There is no solution to the described problem.'; +const problem = 'The problem has no solution.'; +/** + * Returns + * -------- + * Problem: The problem has no solution. => Fix: There is no solution to the described problem. + */ +const errorMessage = ValidationError.defineMessage({ fix, problem }); +``` + +
+ +## `ValidationError` constructor + +### `ValidationError()` + +Creates a new instance with the message. If the provided `message` is an [`object`][js-object], then its properties are assigned to the instance. + +```typescript +new ValidationError(message: string | ErrorMessage) { + super(is.string(message) ? message : ValidationError.defineMessage(message)); + if (is.object(message)) { + Object.assign(this, getProperties(message, ['fix', 'problem'])); + } +} +``` + +**Parameters:** + +| Name: type | Description | +| :-------------------------------- | :---------- | +| `message: string \| ErrorMessage` | The message of a `string` type or of an [`ErrorMessage`](#errormessage) interface that is used to throw with an [`error`][js-error] | + +**Returns:** + +The **return value** is an instance of [`ValidationError`](#validationerror). + +**Usage:** + +```typescript +// Example usage. +import { ValidationError } from '@angular-package/core'; + +const fix = 'There is no solution to the described problem.'; +const problem = 'The problem has no solution.'; +const validationError = new ValidationError({ fix, problem }); +``` + +
+ +## Interface + +### ErrorMessage + +The shape of an [`object`][js-object] for an [`error`][js-error] message that contains a possible solution to the described problem. + +```typescript +interface ErrorMessage { + /** + * Possible solution to the described problem of a `string` type. + */ + fix: string; + /** + * Error problem of a `string` type. + */ + problem: string; +} +``` + +### ResultHandler + +Function to handle the result of the [`ResultCallback`][package-type-resultcallback] [`function`][js-function] before its result returns. + +```typescript +type ResultHandler = (result: boolean, value: any) => void; +``` + +
+ ## GIT ### Commit From f68b3cfa5563382e5723ac8088b2fc465bd9e38a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 3 Aug 2021 23:55:08 +0200 Subject: [PATCH 05/16] chore: remove unnecessary --- src/lib/error-custom.class.ts | 49 --------------------------------- src/lib/error-messages.class.ts | 0 2 files changed, 49 deletions(-) delete mode 100644 src/lib/error-custom.class.ts delete mode 100644 src/lib/error-messages.class.ts diff --git a/src/lib/error-custom.class.ts b/src/lib/error-custom.class.ts deleted file mode 100644 index 23a10d2..0000000 --- a/src/lib/error-custom.class.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { guard } from '@angular-package/type'; -import { MessageBuilderClass } from '../message-builder/lib/message-builder-class.class'; -import { MessageBuilderFunction } from '../message-builder/lib/message-builder-function.class'; -import { MessageBuilder } from '../message-builder/lib/message-builder.class'; - -export interface ConfigError { - problem: string; - fix?: string; -} - -new MessageBuilderClass(); -new MessageBuilderFunction(); - -export class ErrorCustom { - - public date: Date = new Date(); - public fix: string; - public problem: string; - - constructor(config: ConfigError) { - if (guard.is.string(config?.fix)) { - this.fix = config.fix; - } - if (guard.is.string(config?.problem)) { - this.problem = config.problem; - } - this.date = new Date(); - } - - private message(): string { - return ` - Problem: ${this.problem} - Fix: ${this.fix} - Date: ${this.date} - `; - } - - public error(): void { - throw new Error(this.message()); - } - - public syntax(): void { - throw new SyntaxError(this.message()); - } - - public type(): void { - throw new TypeError(this.message()); - } -} diff --git a/src/lib/error-messages.class.ts b/src/lib/error-messages.class.ts deleted file mode 100644 index e69de29..0000000 From d9ecdc7e51bfc15592dadd0c4efe52dc8747cba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 3 Aug 2021 23:55:52 +0200 Subject: [PATCH 06/16] chore: change the folder from lib to src --- .../lib/message-builder-class.class.ts | 83 ----------------- .../lib/message-builder-function.class.ts | 63 ------------- .../lib/message-builder-templates.class.ts | 19 ---- .../lib/message-builder.class.ts | 57 ------------ .../src/message-builder-template.class.ts | 29 ++++++ .../src/message-builder.class.ts | 91 +++++++++++++++++++ .../src/message-class-builder.class.ts | 83 +++++++++++++++++ .../src/message-function-builder.class.ts | 82 +++++++++++++++++ 8 files changed, 285 insertions(+), 222 deletions(-) delete mode 100644 src/message-builder/lib/message-builder-class.class.ts delete mode 100644 src/message-builder/lib/message-builder-function.class.ts delete mode 100644 src/message-builder/lib/message-builder-templates.class.ts delete mode 100644 src/message-builder/lib/message-builder.class.ts create mode 100644 src/message-builder/src/message-builder-template.class.ts create mode 100644 src/message-builder/src/message-builder.class.ts create mode 100644 src/message-builder/src/message-class-builder.class.ts create mode 100644 src/message-builder/src/message-function-builder.class.ts diff --git a/src/message-builder/lib/message-builder-class.class.ts b/src/message-builder/lib/message-builder-class.class.ts deleted file mode 100644 index f5bd1c7..0000000 --- a/src/message-builder/lib/message-builder-class.class.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { is, guard } from '@angular-package/type'; -import { MessageBuilderTemplates } from './message-builder-templates.class'; -import { MessageBuilder } from './message-builder.class'; - -export class MessageBuilderClass extends MessageBuilder { - private class$$: string; - private param$$: { - name?: string; - type?: string; - } = {}; - private method$$: string; - - constructor() { - super('class'); - } - - /** - * Build class message. - */ - public build(): this { - // class. - // this.replace('class', this.class$$); - // // method. - // this.replace('method', is.string(this.method$$) && is.string(this.class$$) ? `.${this.method$$}` : this.method$$); - // // param. - // const param = `${this.param$$.name}${this.param$$.type}`; - // this - // .replace('param.type', this.param$$.type) - // .replace('param.name', this.param$$.name) - // .replace(param, `(${param})`) - // .replace(this.param$$.type, `: ${this.param$$.type}`); - return this; - } - - /** - * Set class name to build message. - * @param name Class name. - * @returns this. - */ - public class(name: string): this { - if (guard.is.string(name)) { - this.class$$ = name; - } - return this; - } - - /** - * Set class method name to build message. - * @param name Class method name. - * @returns this. - */ - public method(name: string): this { - if (guard.is.string(name)) { - this.method$$ = name; - } - return this; - } - - /** - * Set method param name with type to build message. - * @param name Method param name. - * @param type Method param type. - * @returns this. - */ - public param(name: string, type?: string): this { - if (guard.is.string(name)) { - this.param$$.name = name; - } - if (guard.is.string(type)) { - this.param$$.type = type; - } - return this; - } -} - -const messageBuilderClass: MessageBuilderClass = new MessageBuilderClass() - .class('NameProperty') - .method('set') - .param('name', 'Array') - .build(); - -console.log(`messageBuilderClass`, messageBuilderClass.get); - diff --git a/src/message-builder/lib/message-builder-function.class.ts b/src/message-builder/lib/message-builder-function.class.ts deleted file mode 100644 index ea8a618..0000000 --- a/src/message-builder/lib/message-builder-function.class.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { guard } from '@angular-package/type'; -import { MessageBuilder } from './message-builder.class'; - -export class MessageBuilderFunction { - private builder$$: MessageBuilder; - private function$$: string; - private param$$: { - name?: string; - type?: string; - } = {}; - private method$$: string; - - get get(): string { - return this.builder$$.get; - } - - constructor() { - this.builder$$ = new MessageBuilder('function'); - } - - /** - * Build function message. - */ - public build(): this { - // function. - this.builder$$.function(this.function$$); - // param. - this.builder$$.param(this.param$$.name, this.param$$.type) - return this; - } - - /** - * Set class name to build message. - * @param name Class name. - * @returns this. - */ - public function(name: string): this { - if (guard.is.string(name)) { - this.function$$ = name; - } - return this; - } - - /** - * Set method param name with type to build message. - * @param name Method param name. - * @param type Method param type. - * @returns this. - */ - public param(name: string, type?: string): this { - if (guard.is.string(name)) { - this.param$$.name = name; - } - if (guard.is.string(type)) { - this.param$$.type = type; - } - return this; - } -} - -const messageBuilderFunction: MessageBuilderFunction = new MessageBuilderFunction(); -messageBuilderFunction.function('myFunction').param('one', 'string').build(); -console.log(`messageBuilderFunction`, messageBuilderFunction.get); diff --git a/src/message-builder/lib/message-builder-templates.class.ts b/src/message-builder/lib/message-builder-templates.class.ts deleted file mode 100644 index d4ac0bf..0000000 --- a/src/message-builder/lib/message-builder-templates.class.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { is } from '@angular-package/type'; - -export class MessageBuilderTemplates { - private templates$$ = { - class: `[class][method][param.name][param.type]`, // argument value is [value.type] type, must be [param.type] type - function: `[function][param.name][param.type]` - }; - private type$$: string; - - get get(): string { - return this.templates$$[this.type$$]; - } - - constructor(type: 'class' | 'function') { - if (is.string(type)) { - this.type$$ = type; - } - } -} diff --git a/src/message-builder/lib/message-builder.class.ts b/src/message-builder/lib/message-builder.class.ts deleted file mode 100644 index b95a229..0000000 --- a/src/message-builder/lib/message-builder.class.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { is } from '@angular-package/type'; -import { MessageBuilderTemplates } from './message-builder-templates.class'; - -// export type RegExpPreDefined = 'class' | 'function' | 'method' | 'param.name' | 'param.type'; - -export class MessageBuilder { - private regExp$$ = { - class: /\[class\]/i, - function: /\[function\]/i, - method: /\[method\]/i, - param: { - name: /\[param.name\]/i, - type: /\[param.type\]/i - } - }; - private template$$: string; - - get get(): string { - return this.template$$; - } - - constructor(template: 'class' | 'function') { - this.template$$ = new MessageBuilderTemplates(template).get; - } - - public class(name: string): this { - this.replace(this.regExp$$.class, name); - return this; - } - - public function(name: string): this { - this.replace(this.regExp$$.function, name); - return this; - } - - public method(name: string): this { - this.replace(this.regExp$$.method, name); - return this; - } - - public param(name: string, type?: string): this { - const param = `${name}${type}`; - this - .replace(this.regExp$$.param.type, type) - .replace(this.regExp$$.param.name, name) - .replace(param, `(${param})`) - .replace(type, `: ${type}`); - return this; - } - - public replace(searchValue: string | RegExp, replaceValue: string): this { - if (is.defined(searchValue)) { - this.template$$ = this.template$$.replace(searchValue, is.string(replaceValue) ? replaceValue : ''); - } - return this; - } -} diff --git a/src/message-builder/src/message-builder-template.class.ts b/src/message-builder/src/message-builder-template.class.ts new file mode 100644 index 0000000..64022cb --- /dev/null +++ b/src/message-builder/src/message-builder-template.class.ts @@ -0,0 +1,29 @@ +// @angular-package/type +import { is } from '@angular-package/type'; +// Interface. +import { MessageTemplate } from '../interface/message-template.interface'; +/** + * + */ +export class MessageBuilderTemplate { + #template: MessageTemplate = { + class: `[class][method]([param.name][param.type])[return]`, // argument value is [value.type] type, must be [param.type] type + function: `[function]([param.name][param.type])[return]`, + method: `[method]([param.name][param.type])[return]` + }; + + #type!: keyof MessageTemplate; + + /** + * Gets privately stored template of the provided in the constructor type. + */ + get get(): string { + return this.#template[this.#type]; + } + + constructor(type: 'class' | 'function' | 'method') { + if (is.string(type)) { + this.#type = type; + } + } +} diff --git a/src/message-builder/src/message-builder.class.ts b/src/message-builder/src/message-builder.class.ts new file mode 100644 index 0000000..42d9a5d --- /dev/null +++ b/src/message-builder/src/message-builder.class.ts @@ -0,0 +1,91 @@ +// @angular-package/type +import { is, guard, ResultCallback } from '@angular-package/type'; +// Class. +import { MessageBuilderTemplate } from './message-builder-template.class'; + +// export type RegExpPreDefined = 'class' | 'function' | 'method' | 'param.name' | 'param.type'; + +export class MessageBuilder { + #regExp = { + class: /\[class\]/i, + function: /\[function\]/i, + method: /\[method\]/i, + param: { + name: /\[param.name\]/i, + type: /\[param.type\]/i, + }, + return: /\[return\]/i + }; + + #template: string; + + get get(): string { + return this.#template; + } + + constructor(template: 'class' | 'function' | 'method') { + this.#template = new MessageBuilderTemplate(template).get; + } + + public setClassName(name: string, callback?: ResultCallback): this { + if (guard.string(name, callback)) { + this.replace(this.#regExp.class, name); + } + return this; + } + + public setFunctionName(name: string, callback?: ResultCallback): this { + if (guard.string(name, callback)) { + this.replace(this.#regExp.function, name); + } + return this; + } + + public setMethodName(name: string, callback?: ResultCallback): this { + if (guard.string(name, callback)) { + this.replace(this.#regExp.method, name); + } + return this; + } + + public setParam(name: string, type: string = ''): this { + if (guard.string(name)) { + const param = `${name}${type}`; + this + .replace(this.#regExp.param.name, name) + .replace(this.#regExp.param.type, type); + + if (type.length > 0) { + this.replace(type, `: ${type}`); + } + } + return this; + } + + public setReturn(returns: string, callback?: ResultCallback): this { + if (guard.string(returns, callback)) { + this.replace(this.#regExp.return, returns); + if (returns.length > 0) { + this.replace(returns, `: ${returns}`); + } + } + return this; + } + + private replace(searchValue: string | RegExp, replaceValue: string): this { + if (is.defined(searchValue)) { + this.#template = this.#template.replace( + searchValue, + is.string(replaceValue) ? replaceValue : '' + ); + } + return this; + } +} + +// console.log( +// new MessageBuilder('function') +// .param('firstName?', 'string') +// .function('isComponentLoader') +// .get +// ); diff --git a/src/message-builder/src/message-class-builder.class.ts b/src/message-builder/src/message-class-builder.class.ts new file mode 100644 index 0000000..dcde20f --- /dev/null +++ b/src/message-builder/src/message-class-builder.class.ts @@ -0,0 +1,83 @@ +import { is, guard } from '@angular-package/type'; +import { MessageBuilderTemplate } from './message-builder-template.class'; +import { MessageBuilder } from './message-builder.class'; + +// export class MessageClassBuilder extends MessageBuilder { +// private class$$: string; +// private param$$: { +// name?: string; +// type?: string; +// } = {}; +// private method$$: string; + +// constructor() { +// super('class'); +// } + +// /** +// * Build class message. +// */ +// public build(): this { +// // class. +// // this.replace('class', this.class$$); +// // // method. +// // this.replace('method', is.string(this.method$$) && is.string(this.class$$) ? `.${this.method$$}` : this.method$$); +// // // param. +// // const param = `${this.param$$.name}${this.param$$.type}`; +// // this +// // .replace('param.type', this.param$$.type) +// // .replace('param.name', this.param$$.name) +// // .replace(param, `(${param})`) +// // .replace(this.param$$.type, `: ${this.param$$.type}`); +// return this; +// } + +// /** +// * Set class name to build message. +// * @param name Class name. +// * @returns this. +// */ +// public class(name: string): this { +// if (guard.is.string(name)) { +// this.class$$ = name; +// } +// return this; +// } + +// /** +// * Set class method name to build message. +// * @param name Class method name. +// * @returns this. +// */ +// public method(name: string): this { +// if (guard.is.string(name)) { +// this.method$$ = name; +// } +// return this; +// } + +// /** +// * Set method param name with type to build message. +// * @param name Method param name. +// * @param type Method param type. +// * @returns this. +// */ +// public param(name: string, type?: string): this { +// if (guard.is.string(name)) { +// this.param$$.name = name; +// } +// if (guard.is.string(type)) { +// this.param$$.type = type; +// } +// return this; +// } +// } + +// const messageBuilderClass: MessageClassBuilder = new MessageClassBuilder() +// .class('NameProperty') +// .method('set') +// .param('name', 'Array') +// .build(); + +// console.log(`messageBuilderClass`, messageBuilderClass.get); + diff --git a/src/message-builder/src/message-function-builder.class.ts b/src/message-builder/src/message-function-builder.class.ts new file mode 100644 index 0000000..e0d2451 --- /dev/null +++ b/src/message-builder/src/message-function-builder.class.ts @@ -0,0 +1,82 @@ +import { guard, is, ResultCallback } from '@angular-package/type'; +// Class. +import { MessageBuilder } from './message-builder.class'; +// Interface. +import { Parameter } from '../interface/parameter.interface'; +/** + * + */ +export class MessageFunctionBuilder { + #messageBuilder: MessageBuilder; + #name = ''; + #param: Parameter = { + name: '', + type: '' + }; + #return = ''; + + get get(): string { + return this.#messageBuilder.get; + } + + constructor() { + this.#messageBuilder = new MessageBuilder('function'); + } + + /** + * Build function message. + */ + public build(): this { + this + .#messageBuilder + .setFunctionName(this.#name) + .setParam(this.#param.name, this.#param.type) + .setReturn(this.#return); + return this; + } + + /** + * Sets the function name to build message. + * @param name Function name of a `string` type. + * @param callback + * @returns The return value is an instance of `MessageBuilderFunction`. + */ + public setName(name: string, callback?: ResultCallback): this { + if (guard.string(name, callback)) { + this.#name = name; + } + // this.setFunction(name); + return this; + } + + /** + * Set method param name with type to build message. + * @param name Method param name. + * @param type Method param type. + * @returns this. + */ + public setParam(name: string, type?: string, callback?: ResultCallback): this { + if (guard.string(name, callback)) { + this.#param.name = name; + if (is.string(type)) { + this.#param.type = type; + } + } + return this; + } + + public setReturn(returns: string, callback?: ResultCallback): this { + if (guard.string(returns, callback)) { + this.#return = returns; + } + return this; + } +} + +const messageBuilderFunction = new MessageFunctionBuilder(); +messageBuilderFunction + .setName('isString') + .setParam('one', 'string') + .setReturn('this') + .build(); +console.log(messageBuilderFunction.get); From cf204a3f6d0a5ceb3ffe880f65e30b7e71c72900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 3 Aug 2021 23:56:36 +0200 Subject: [PATCH 07/16] test: activate tests --- src/test/validation-error.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/validation-error.spec.ts b/src/test/validation-error.spec.ts index b03e9b5..6edc5f9 100644 --- a/src/test/validation-error.spec.ts +++ b/src/test/validation-error.spec.ts @@ -5,7 +5,7 @@ import { ValidationError } from '../lib/validation-error.class'; /** * Initialize `Testing`. */ -const testing = new Testing(false, true); +const testing = new Testing(true, true); const toBe = new TestingToBeMatchers(); /** * Tests. From 5e2142126aefd77eec4843d8b45a81bd03f1a7cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Tue, 3 Aug 2021 23:57:00 +0200 Subject: [PATCH 08/16] feat(interface): add interface for the message builder --- src/message-builder/interface/message-template.interface.ts | 3 +++ src/message-builder/interface/parameter.interface.ts | 4 ++++ 2 files changed, 7 insertions(+) create mode 100644 src/message-builder/interface/message-template.interface.ts create mode 100644 src/message-builder/interface/parameter.interface.ts diff --git a/src/message-builder/interface/message-template.interface.ts b/src/message-builder/interface/message-template.interface.ts new file mode 100644 index 0000000..a2388da --- /dev/null +++ b/src/message-builder/interface/message-template.interface.ts @@ -0,0 +1,3 @@ +export interface MessageTemplate { + [index: string]: string; +} diff --git a/src/message-builder/interface/parameter.interface.ts b/src/message-builder/interface/parameter.interface.ts new file mode 100644 index 0000000..8d17d26 --- /dev/null +++ b/src/message-builder/interface/parameter.interface.ts @@ -0,0 +1,4 @@ +export interface Parameter { + name: string; + type: string; +} From f97ddbbee58b0e5431f6a3b97fac8a7bb2afd7be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 4 Aug 2021 00:49:38 +0200 Subject: [PATCH 09/16] docs(README.md): update --- README.md | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 029e1e3..93eadcd 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ Manages an [`Error`][js-error] of the validation. ### `ValidationError.template` -Template of the error message with the replaceable `[problem]` and `[fix]`. +Template of the error message with the replaceable `[problem]` and `[fix]`. By default, it's set to `Problem: [problem] => Fix: [fix]`. ```typescript static template = `Problem: [problem] => Fix: [fix]`; @@ -156,7 +156,7 @@ public fix = ''; ### `ValidationError.prototype.name` -Error name of a string type that is being thrown. By default, it's `ValidationError`. +Error name of a [`string`][js-string] type that is being thrown. By default, it's [`ValidationError`](#validationerror). ```typescript public name = ValidationError.name; @@ -166,7 +166,7 @@ public name = ValidationError.name; ### `ValidationError.prototype.problem` -The validation problem of a [`string`][js-string] type. By default, it's an empty string. +The validation problem of a [`string`][js-string] type. By default, it's an empty [`string`][js-string]. ```typescript public problem = ''; @@ -181,11 +181,17 @@ public problem = ''; Defines the validation error message of a [`string`][js-string] type from the provided `message` of the [`ErrorMessage`](#errormessage) interface. ```typescript -static defineMessage(message: ErrorMessage): string { - if (is.objectKey(message, ['fix', 'problem'])) { - return `Problem: ${message.problem}. ${ - is.string(message.fix) ? `Fix: ${message.fix}` : '' - }`; +static defineMessage( + message: ErrorMessage, + template: string = ValidationError.template, + callback?: ResultCallback +): string { + if (is.objectKey(message, ['fix', 'problem'], callback)) { + if (is.string(template)) { + return template + .replace(`[fix]`, message.fix) + .replace(`[problem]`, message.problem); + } } return ''; } @@ -193,13 +199,15 @@ static defineMessage(message: ErrorMessage): string { **Parameters:** -| Name: type | Description | -| :---------------------- | :---------- | -| `message: ErrorMessage` | An [`object`][js-object] of the [`ErrorMessage`](#errormessage) interface to build a message of a [`string`][js-string] type. The value is checked against the proper [`object`][js-object] | +| Name: type | Description | +| :-------------------------- | :---------- | +| `message: ErrorMessage` | An [`object`][js-object] of the [`ErrorMessage`](#errormessage) interface to build a message of a [`string`][js-string] type. The value is checked against the proper [`object`][js-object] | +| `template: string` | A message template of a [`string`][js-string] type with replaceable `[problem]` and `[fix]` from the given `message`. The value is checked against a [`string`][js-string]. By default, it's set to `Problem: [problem] => Fix: [fix]` | +| `callback?: ResultCallback` | An optional callback function of [`ResultCallback`][package-type-resultcallback] type to handle the check whether the provided message contains required `problem` and `fix` properties | **Returns:** -The **return value** is a message of a `string` type created from the provided `message` of [`ErrorMessage`](#errormessage) interface, or it's an empty `string` if the provided message object isn't proper. +The **return value** is a message of a `string` type created from the provided `message` of [`ErrorMessage`](#errormessage) interface, or it's an empty [`string`][js-string] if the provided message [`object`][js-object] isn't proper. **Usage:** @@ -209,6 +217,7 @@ import { ValidationError } from '@angular-package/core'; const fix = 'There is no solution to the described problem.'; const problem = 'The problem has no solution.'; + /** * Returns * -------- @@ -227,9 +236,14 @@ Creates a new instance with the message. If the provided `message` is an [`objec ```typescript new ValidationError(message: string | ErrorMessage) { - super(is.string(message) ? message : ValidationError.defineMessage(message)); + super( + is.string(message) ? message : ValidationError.defineMessage(message) + ); if (is.object(message)) { - Object.assign(this, getProperties(message, ['fix', 'problem'])); + Object.assign(this, { + problem: message.problem, + fix: message.fix, + }); } } ``` @@ -238,7 +252,7 @@ new ValidationError(message: string | ErrorMessage) { | Name: type | Description | | :-------------------------------- | :---------- | -| `message: string \| ErrorMessage` | The message of a `string` type or of an [`ErrorMessage`](#errormessage) interface that is used to throw with an [`error`][js-error] | +| `message: string \| ErrorMessage` | The message of a [`string`][js-string] type or of an [`ErrorMessage`](#errormessage) interface that is used to throw with an [`error`][js-error] | **Returns:** @@ -276,14 +290,6 @@ interface ErrorMessage { } ``` -### ResultHandler - -Function to handle the result of the [`ResultCallback`][package-type-resultcallback] [`function`][js-function] before its result returns. - -```typescript -type ResultHandler = (result: boolean, value: any) => void; -``` -
## GIT From 14412a97707f9a5102500e70022a0c05e576ab92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 4 Aug 2021 00:52:00 +0200 Subject: [PATCH 10/16] docs(README.md): update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 93eadcd..3a4417d 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,7 @@ Manages an [`Error`][js-error] of the validation. | Methods | Description | | :----------------------------------------------------------------- | :---------- | -| [`ValidationError.defineMessage()`](#validationerrordefinemessage) | Defines the error message of a [`string`][js-string] type from the provided `message` of an [`object`][js-object] | +| [`ValidationError.defineMessage()`](#validationerrordefinemessage) | Defines the validation error message of a [`string`][js-string] type from the provided `message` of the [`ErrorMessage`](#errormessage) interface | **Constructor:** From 8f3e79d3801a00438b17115d08920f0292bbc42c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 4 Aug 2021 01:01:10 +0200 Subject: [PATCH 11/16] refactor(ValidationError): update - add `template: string`, `callback: ResultCallback` parameters to the static `defineMessage()` method. - checks the `template: string` of the static `defineMessage()` method. - use prettier on the file. - update jsdoc. --- src/lib/validation-error.class.ts | 42 +++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/lib/validation-error.class.ts b/src/lib/validation-error.class.ts index e111767..e702681 100644 --- a/src/lib/validation-error.class.ts +++ b/src/lib/validation-error.class.ts @@ -1,5 +1,5 @@ // Object. -import { is } from '@angular-package/type'; +import { is, ResultCallback } from '@angular-package/type'; // Interface. import { ErrorMessage } from '../interface/error-message.interface'; /** @@ -8,35 +8,48 @@ import { ErrorMessage } from '../interface/error-message.interface'; export class ValidationError extends Error { /** * Template of the error message with the replaceable [problem] and [fix]. + * By default, it's set to `Problem: [problem] => Fix: [fix]`. */ static template = `Problem: [problem] => Fix: [fix]`; /** - * Possible solution to the described problem of a `string` type. + * A possible solution to the described problem of a `string` type. By default, it's an empty `string`. */ public fix = ''; /** - * Error name of a string type that is being thrown. By default, it's `ValidationError`. + * Error name of a `string` type that is being thrown. By default, it's `ValidationError`. */ public name = ValidationError.name; /** - * The validation problem of a `string` type. By default, it's an empty string. + * The validation problem of a `string` type. By default, it's an empty `string`. */ public problem = ''; /** - * Defines the validation error message of a `string` type from the provided `message` of `ErrorMessage` interface. + * Defines the validation error message of a `string` type from the provided `message` of the `ErrorMessage` interface. * @param message An object of an `ErrorMessage` interface to build the message of a `string` type. The value is checked against - * the proper object. - * @returns The return value is a message of a `string` type created from the provided `message` of `ErrorMessage` interface. + * the proper `object`. + * @param template A message template of a `string` type with replaceable `[problem]` and `[fix]` from the given `message`. The value is + * checked against a `string`. By default, it's set to `Problem: [problem] => Fix: [fix]`. + * @param callback An optional callback function of `ResultCallback` type to handle the check whether the provided message contains + * required `problem` and `fix` properties. + * @returns The return value is a message of a `string` type created from the provided `message` of `ErrorMessage` interface or it's an + * empty `string` if the provided message object isn't proper. + * @angularpackage */ - static defineMessage(message: ErrorMessage): string { - if (is.objectKey(message, ['fix', 'problem'])) { - return ValidationError.template - .replace(`[fix]`, message.fix) - .replace(`[problem]`, message.problem); + static defineMessage( + message: ErrorMessage, + template: string = ValidationError.template, + callback?: ResultCallback + ): string { + if (is.objectKey(message, ['fix', 'problem'], callback)) { + if (is.string(template)) { + return template + .replace(`[fix]`, message.fix) + .replace(`[problem]`, message.problem); + } } return ''; } @@ -45,9 +58,12 @@ export class ValidationError extends Error { * Creates a new instance with the message. If the provided `message` is an `object`, then its properties are assigned * to the instance. * @param message The message of a `string` type or of an `ErrorMessage` interface that is used to throw with an `error`. + * @angularpackage */ constructor(message: string | ErrorMessage) { - super(is.string(message) ? message : ValidationError.defineMessage(message)); + super( + is.string(message) ? message : ValidationError.defineMessage(message) + ); if (is.object(message)) { Object.assign(this, { problem: message.problem, From 03466872fbb3e1a2baf6a2b671b7928faabadb9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 4 Aug 2021 01:05:19 +0200 Subject: [PATCH 12/16] chore(package): update --- package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 6e283c4..3d3ebe7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,7 +5,7 @@ "requires": true, "packages": { "": { - "version": "0.0.1", + "license": "MIT", "dependencies": { "tslib": "^2.2.0" }, From 17c20a83d98f0ea7a103d38d83ba44a3bb34afa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 4 Aug 2021 01:05:25 +0200 Subject: [PATCH 13/16] 1.0.0 --- package-lock.json | 5 +++-- package.json | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3d3ebe7..6b06213 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "error", - "version": "0.0.1", + "version": "1.0.0", "lockfileVersion": 2, "requires": true, "packages": { @@ -16,7 +16,8 @@ "@angular-package/type": "^4.2.0", "@angular/common": "^12.1.1", "@angular/core": "^12.1.1" - } + }, + "version": "1.0.0" }, "node_modules/@angular-package/testing": { "version": "1.1.0", diff --git a/package.json b/package.json index 6188824..e0829f5 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,6 @@ "bugs": { "url": "https://github.com/angular-package/error/issues" }, - "license": "MIT" - + "license": "MIT", + "version": "1.0.0" } From 86489ae60835c72620f434768517fd99361b8920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 4 Aug 2021 01:07:32 +0200 Subject: [PATCH 14/16] docs(README.md): update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3a4417d..509bd5e 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Useful and simple to use packages based on the [angular.io][angulario]. | [type][type-github-readme] | Common types, type guards, and type checkers. | [![npm version][type-npm-badge-svg]][type-npm-badge] | | [ui][ui-github-readme] | User interface. | *In Progress* | -> Click on the package name to visit the package. +> Click on the package name to visit its [GitHub](https://github.com/) page. ## angular-package/error From 3d1b89a35eb20ef5ec28d6898dc20efddb887615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 4 Aug 2021 01:12:09 +0200 Subject: [PATCH 15/16] chore(ng-package): add `@angular-package/type` `umdModuleIds` --- ng-package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ng-package.json b/ng-package.json index 87acb8b..5dbe8d1 100644 --- a/ng-package.json +++ b/ng-package.json @@ -2,6 +2,9 @@ "$schema": "../../node_modules/ng-packagr/ng-package.schema.json", "dest": "../../dist/error", "lib": { - "entryFile": "src/public-api.ts" + "entryFile": "src/public-api.ts", + "umdModuleIds": { + "@angular-package/type": "angular-package.type" + } } } \ No newline at end of file From 0150f6caf5a0f14c5023ba1b23bfde6579924e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Aeebor=20Rudnicki?= Date: Wed, 4 Aug 2021 01:12:37 +0200 Subject: [PATCH 16/16] fix(package): add `name` and `version` --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e0829f5..1ffbc4e 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,6 @@ { + "name": "@angular-package/error", + "version": "1.0.0", "description": "Manages the callback function.", "author": "Angular Package (https://wvvw.dev)", "homepage": "https://github.com/angular-package/testing#readme", @@ -31,6 +33,5 @@ "bugs": { "url": "https://github.com/angular-package/error/issues" }, - "license": "MIT", - "version": "1.0.0" + "license": "MIT" }