@dravishek/number-validate 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # NumberValidate
2
+
3
+ This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 19.2.0.
4
+
5
+ ## Code scaffolding
6
+
7
+ Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
8
+
9
+ ```bash
10
+ ng generate component component-name
11
+ ```
12
+
13
+ For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
14
+
15
+ ```bash
16
+ ng generate --help
17
+ ```
18
+
19
+ ## Building
20
+
21
+ To build the library, run:
22
+
23
+ ```bash
24
+ ng build number-validate
25
+ ```
26
+
27
+ This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
28
+
29
+ ### Publishing the Library
30
+
31
+ Once the project is built, you can publish your library by following these steps:
32
+
33
+ 1. Navigate to the `dist` directory:
34
+ ```bash
35
+ cd dist/number-validate
36
+ ```
37
+
38
+ 2. Run the `npm publish` command to publish your library to the npm registry:
39
+ ```bash
40
+ npm publish
41
+ ```
42
+
43
+ ## Running unit tests
44
+
45
+ To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
46
+
47
+ ```bash
48
+ ng test
49
+ ```
50
+
51
+ ## Running end-to-end tests
52
+
53
+ For end-to-end (e2e) testing, run:
54
+
55
+ ```bash
56
+ ng e2e
57
+ ```
58
+
59
+ Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
60
+
61
+ ## Additional Resources
62
+
63
+ For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
@@ -0,0 +1,65 @@
1
+ import * as i0 from '@angular/core';
2
+ import { input, HostListener, Optional, Directive } from '@angular/core';
3
+ import * as i1 from '@angular/forms';
4
+
5
+ class AdrNumberValidateDirective {
6
+ el;
7
+ control;
8
+ constructor(el, control) {
9
+ this.el = el;
10
+ this.control = control;
11
+ }
12
+ /**
13
+ * @description Value before the decimal point specifies the number of digits before decimal and value after the decimal specifies the number of digits after decimal.
14
+ * Example: 7.3 (Before decimal 7 digits & 3 digits after decimal)
15
+ * Possible type of patterns allowed: X, X.X
16
+ */
17
+ adrNumberValidate = input('');
18
+ onKeyDown = (event) => this.execute(this.el.nativeElement.value);
19
+ onPaste = (event) => this.execute(this.el.nativeElement.value);
20
+ checkValue(value) {
21
+ let [length, scale] = this.adrNumberValidate().split('.'), regExpString = `^(\\+|\\-)?([\\d]{0,${+length}})`, checkPattern = null;
22
+ if (+scale > 0) {
23
+ regExpString += `((\\.{1})([\\d]{1,${+scale}})?)`;
24
+ }
25
+ checkPattern = String(value).match(new RegExp(`${regExpString}?$`));
26
+ return checkPattern;
27
+ }
28
+ execute(oldValue) {
29
+ setTimeout(() => {
30
+ let currentValue = this.el.nativeElement.value;
31
+ if (currentValue && !this.checkValue(currentValue)) {
32
+ this.control?.control && this.control.control.patchValue(+oldValue);
33
+ this.el.nativeElement.value = oldValue;
34
+ }
35
+ });
36
+ }
37
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: AdrNumberValidateDirective, deps: [{ token: i0.ElementRef }, { token: i1.NgControl, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
38
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.14", type: AdrNumberValidateDirective, isStandalone: true, selector: "[adrNumberValidate]", inputs: { adrNumberValidate: { classPropertyName: "adrNumberValidate", publicName: "adrNumberValidate", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "keydown": "onKeyDown($event)", "paste": "onPaste($event)" } }, ngImport: i0 });
39
+ }
40
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: AdrNumberValidateDirective, decorators: [{
41
+ type: Directive,
42
+ args: [{
43
+ selector: '[adrNumberValidate]',
44
+ standalone: true
45
+ }]
46
+ }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i1.NgControl, decorators: [{
47
+ type: Optional
48
+ }] }], propDecorators: { onKeyDown: [{
49
+ type: HostListener,
50
+ args: ["keydown", ["$event"]]
51
+ }], onPaste: [{
52
+ type: HostListener,
53
+ args: ["paste", ["$event"]]
54
+ }] } });
55
+
56
+ /*
57
+ * Public API Surface of number-validate
58
+ */
59
+
60
+ /**
61
+ * Generated bundle index. Do not edit.
62
+ */
63
+
64
+ export { AdrNumberValidateDirective };
65
+ //# sourceMappingURL=dravishek-number-validate.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dravishek-number-validate.mjs","sources":["../../../../projects/dravishek/number-validate/src/lib/adr-number-validate.directive.ts","../../../../projects/dravishek/number-validate/src/public-api.ts","../../../../projects/dravishek/number-validate/src/dravishek-number-validate.ts"],"sourcesContent":["import { Directive, ElementRef, HostListener, input, Optional } from '@angular/core';\r\nimport { NgControl } from '@angular/forms';\r\n\r\n@Directive({\r\n selector: '[adrNumberValidate]',\r\n standalone: true\r\n})\r\nexport class AdrNumberValidateDirective {\r\n\r\n constructor(private el: ElementRef, @Optional() private control: NgControl) { }\r\n\r\n /**\r\n * @description Value before the decimal point specifies the number of digits before decimal and value after the decimal specifies the number of digits after decimal.\r\n * Example: 7.3 (Before decimal 7 digits & 3 digits after decimal)\r\n * Possible type of patterns allowed: X, X.X\r\n */\r\n adrNumberValidate = input<string>('');\r\n\r\n @HostListener(\"keydown\", [\"$event\"])\r\n onKeyDown = (event: KeyboardEvent) => this.execute(this.el.nativeElement.value);\r\n\r\n @HostListener(\"paste\", [\"$event\"])\r\n onPaste = (event: ClipboardEvent) => this.execute(this.el.nativeElement.value);\r\n\r\n private checkValue(value: string): RegExpMatchArray | null {\r\n let [length, scale] = this.adrNumberValidate().split('.'), regExpString = `^(\\\\+|\\\\-)?([\\\\d]{0,${+length}})`,\r\n checkPattern: RegExpMatchArray | null = null;\r\n if (+scale > 0) { regExpString += `((\\\\.{1})([\\\\d]{1,${+scale}})?)` }\r\n checkPattern = String(value).match(new RegExp(`${regExpString}?$`));\r\n return checkPattern;\r\n }\r\n\r\n private execute(oldValue: string) {\r\n setTimeout(() => {\r\n let currentValue: string = this.el.nativeElement.value;\r\n if (currentValue && !this.checkValue(currentValue)) {\r\n this.control?.control && this.control.control.patchValue(+oldValue);\r\n this.el.nativeElement.value = oldValue;\r\n }\r\n });\r\n }\r\n}\r\n","/*\r\n * Public API Surface of number-validate\r\n */\r\n\r\nexport * from './lib/adr-number-validate.directive';\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;MAOa,0BAA0B,CAAA;AAEjB,IAAA,EAAA;AAAoC,IAAA,OAAA;IAAxD,WAAoB,CAAA,EAAc,EAAsB,OAAkB,EAAA;QAAtD,IAAE,CAAA,EAAA,GAAF,EAAE;QAAkC,IAAO,CAAA,OAAA,GAAP,OAAO;;AAE/D;;;;AAIE;AACF,IAAA,iBAAiB,GAAG,KAAK,CAAS,EAAE,CAAC;AAGrC,IAAA,SAAS,GAAG,CAAC,KAAoB,KAAK,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC;AAG/E,IAAA,OAAO,GAAG,CAAC,KAAqB,KAAK,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC;AAEtE,IAAA,UAAU,CAAC,KAAa,EAAA;QAC9B,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,YAAY,GAAG,CAAuB,oBAAA,EAAA,CAAC,MAAM,CAAA,EAAA,CAAI,EAC1G,YAAY,GAA4B,IAAI;AAC9C,QAAA,IAAI,CAAC,KAAK,GAAG,CAAC,EAAE;AAAE,YAAA,YAAY,IAAI,CAAA,kBAAA,EAAqB,CAA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,YAAA,IAAA,EAAA,CAAA;AACT,oBAAA,QAAQ,EAAE,qBAAqB;AAC/B,oBAAA,UAAU,EAAE;AACb,iBAAA;;0BAGsC;yCAUrC,SAAS,EAAA,CAAA;sBADR,YAAY;uBAAC,SAAS,EAAE,CAAC,QAAQ,CAAC;gBAInC,OAAO,EAAA,CAAA;sBADN,YAAY;uBAAC,OAAO,EAAE,CAAC,QAAQ,CAAC;;;ACrBnC;;AAEG;;ACFH;;AAEG;;;;"}
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Generated bundle index. Do not edit.
3
+ */
4
+ /// <amd-module name="@dravishek/number-validate" />
5
+ export * from './public-api';
@@ -0,0 +1,20 @@
1
+ import { ElementRef } from '@angular/core';
2
+ import { NgControl } from '@angular/forms';
3
+ import * as i0 from "@angular/core";
4
+ export declare class AdrNumberValidateDirective {
5
+ private el;
6
+ private control;
7
+ constructor(el: ElementRef, control: NgControl);
8
+ /**
9
+ * @description Value before the decimal point specifies the number of digits before decimal and value after the decimal specifies the number of digits after decimal.
10
+ * Example: 7.3 (Before decimal 7 digits & 3 digits after decimal)
11
+ * Possible type of patterns allowed: X, X.X
12
+ */
13
+ adrNumberValidate: import("@angular/core").InputSignal<string>;
14
+ onKeyDown: (event: KeyboardEvent) => void;
15
+ onPaste: (event: ClipboardEvent) => void;
16
+ private checkValue;
17
+ private execute;
18
+ static ɵfac: i0.ɵɵFactoryDeclaration<AdrNumberValidateDirective, [null, { optional: true; }]>;
19
+ static ɵdir: i0.ɵɵDirectiveDeclaration<AdrNumberValidateDirective, "[adrNumberValidate]", never, { "adrNumberValidate": { "alias": "adrNumberValidate"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
20
+ }
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@dravishek/number-validate",
3
+ "version": "1.0.0",
4
+ "peerDependencies": {
5
+ "@angular/common": "^19.2.0",
6
+ "@angular/core": "^19.2.0"
7
+ },
8
+ "dependencies": {
9
+ "tslib": "^2.3.0"
10
+ },
11
+ "sideEffects": false,
12
+ "module": "fesm2022/dravishek-number-validate.mjs",
13
+ "typings": "index.d.ts",
14
+ "exports": {
15
+ "./package.json": {
16
+ "default": "./package.json"
17
+ },
18
+ ".": {
19
+ "types": "./index.d.ts",
20
+ "default": "./fesm2022/dravishek-number-validate.mjs"
21
+ }
22
+ }
23
+ }
@@ -0,0 +1 @@
1
+ export * from './lib/adr-number-validate.directive';