@hmcts/opal-frontend-common 0.0.28 → 0.0.30
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/fesm2022/hmcts-opal-frontend-common-components-alphagov-alphagov-accessible-autocomplete.mjs +1 -1
- package/fesm2022/hmcts-opal-frontend-common-components-alphagov-alphagov-accessible-autocomplete.mjs.map +1 -1
- package/fesm2022/hmcts-opal-frontend-common-services-utils-service.mjs +30 -0
- package/fesm2022/hmcts-opal-frontend-common-services-utils-service.mjs.map +1 -1
- package/package.json +1 -1
- package/services/utils-service/index.d.ts +19 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmcts-opal-frontend-common-components-alphagov-alphagov-accessible-autocomplete.mjs","sources":["../../../projects/opal-frontend-common/components/alphagov/alphagov-accessible-autocomplete/alphagov-accessible-autocomplete.component.ts","../../../projects/opal-frontend-common/components/alphagov/alphagov-accessible-autocomplete/alphagov-accessible-autocomplete.component.html","../../../projects/opal-frontend-common/components/alphagov/alphagov-accessible-autocomplete/hmcts-opal-frontend-common-components-alphagov-alphagov-accessible-autocomplete.ts"],"sourcesContent":["import {\n ChangeDetectionStrategy,\n ChangeDetectorRef,\n Component,\n ElementRef,\n Input,\n OnDestroy,\n OnInit,\n ViewChild,\n afterNextRender,\n inject,\n} from '@angular/core';\nimport { FormControl, AbstractControl, ReactiveFormsModule } from '@angular/forms';\nimport { IAlphagovAccessibleAutocompleteItem } from './interfaces/alphagov-accessible-autocomplete-item.interface';\nimport { AccessibleAutocompleteProps } from 'accessible-autocomplete';\nimport { Subject, pairwise, startWith, takeUntil } from 'rxjs';\n\n@Component({\n selector: 'opal-lib-alphagov-accessible-autocomplete',\n imports: [ReactiveFormsModule],\n templateUrl: './alphagov-accessible-autocomplete.component.html',\n styleUrl: './alphagov-accessible-autocomplete.component.scss',\n changeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class AlphagovAccessibleAutocompleteComponent implements OnInit, OnDestroy {\n private readonly changeDetector: ChangeDetectorRef = inject(ChangeDetectorRef);\n private _control!: FormControl;\n private readonly ngUnsubscribe = new Subject<void>();\n\n @Input({ required: true }) labelText!: string;\n @Input({ required: false }) labelClasses!: string;\n @Input({ required: true }) inputId!: string;\n @Input({ required: true }) inputName!: string;\n @Input({ required: false }) inputClasses!: string;\n @Input({ required: false }) hintText!: string;\n @Input({ required: true }) autoCompleteItems: IAlphagovAccessibleAutocompleteItem[] = [];\n @Input() showAllValues = false;\n @Input({ required: false }) errors: string | null = null;\n\n @ViewChild('autocomplete') autocompleteContainer!: ElementRef<HTMLElement>;\n\n public autoCompleteId!: string;\n\n @Input({ required: true }) set control(abstractControl: AbstractControl | null) {\n // Form controls are passed in as abstract controls, we need to re-cast it.\n this._control = abstractControl as FormControl;\n }\n\n constructor() {\n afterNextRender(() => {\n // Only trigger the render of the component in the browser\n this.configureAutoComplete();\n });\n }\n\n /**\n * Gets the control for the alphagov-accessible-autocomplete component.\n * @returns The control for the component.\n */\n get getControl() {\n return this._control;\n }\n\n /**\n * Handles the confirmation of a selected name.\n *\n * @param selectedName - The selected name.\n * @returns void\n */\n\n private handleOnConfirm(selectedName: string | undefined): void {\n // selectedName is populated on selecting an option but is undefined onBlur, so we need to grab the input value directly from the input\n const control = this._control;\n const name = selectedName ?? (document.querySelector(`#${this.autoCompleteId}`) as HTMLInputElement).value;\n const selectedItem = this.autoCompleteItems.find((item) => item.name === name) ?? null;\n const previousValue = control.value;\n const selectedValue = selectedItem?.value ?? null;\n\n control.setValue(selectedValue);\n control.markAsTouched();\n\n // Handles initial empty state when the user clicks away from the input\n if (selectedItem === null && previousValue === null) {\n control.markAsPristine();\n } else if (selectedItem?.value !== previousValue) {\n control.markAsDirty();\n }\n\n control.updateValueAndValidity();\n this.changeDetector.detectChanges();\n }\n\n /**\n * Retrieves the default value for the autocomplete component.\n *\n * @returns The default value as a string.\n */\n\n private getDefaultValue() {\n return this.autoCompleteItems.find((item) => item.value === this._control.value)?.name ?? '';\n }\n\n /**\n * Builds the props object for the AccessibleAutocomplete component.\n * @returns The props object for the AccessibleAutocomplete component.\n */\n private buildAutoCompleteProps(): AccessibleAutocompleteProps {\n return {\n id: this.autoCompleteId,\n element: this.autocompleteContainer.nativeElement,\n source: this.autoCompleteItems.map((item) => item.name),\n name: this.autoCompleteId,\n showAllValues: this.showAllValues,\n defaultValue: this.getDefaultValue(),\n onConfirm: (selectedName: string) => this.handleOnConfirm(selectedName),\n };\n }\n\n /**\n * Configures the auto-complete functionality using the accessible-autocomplete library.\n */\n private configureAutoComplete(): void {\n import('accessible-autocomplete').then((accessibleAutocomplete) => {\n accessibleAutocomplete.default(this.buildAutoCompleteProps());\n });\n }\n\n /**\n * Sets up the control subscription for value changes.\n * Whenever the control value changes, this method is called to handle the changes.\n * If the new value is null, it clears the autocomplete container and configures the autocomplete.\n */\n private setupControlSub(): void {\n this._control.valueChanges\n .pipe(startWith(null), pairwise(), takeUntil(this.ngUnsubscribe))\n .subscribe(([prev, next]) => {\n // If both values are null, we don't need to do anything\n if (prev === null && next === null) {\n return;\n }\n\n // Otherwise, next is null, we need to clear the autocomplete\n if (next === null) {\n this.autocompleteContainer.nativeElement.innerHTML = '';\n this.configureAutoComplete();\n }\n });\n }\n\n ngOnInit(): void {\n this.autoCompleteId = this.inputId + '-autocomplete';\n this.setupControlSub();\n }\n\n ngOnDestroy(): void {\n this.ngUnsubscribe.next();\n this.ngUnsubscribe.complete();\n }\n}\n","<div class=\"govuk-form-group\" [class.govuk-form-group--error]=\"!!errors\">\n <label class=\"govuk-label {{ labelClasses }}\" [for]=\"autoCompleteId\"> {{ labelText }} </label>\n @if (hintText) {\n <div id=\"{{ inputId }}-hint\" class=\"govuk-hint\">\n {{ hintText }}\n </div>\n }\n\n @if (errors) {\n <p id=\"{{ this.autoCompleteId }}-error-message\" class=\"govuk-error-message\">\n <span class=\"govuk-visually-hidden\">Error: </span> {{ errors }}\n </p>\n }\n\n <div #autocomplete id=\"{{ autoCompleteId }}-container\" class=\"{{ inputClasses }}\"></div>\n <input [id]=\"inputId\" [name]=\"inputName\" type=\"hidden\" [formControl]=\"getControl\" />\n</div>\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;MAwBa,uCAAuC,CAAA;AACjC,IAAA,cAAc,GAAsB,MAAM,CAAC,iBAAiB,CAAC;AACtE,IAAA,QAAQ;AACC,IAAA,aAAa,GAAG,IAAI,OAAO,EAAQ;AAEzB,IAAA,SAAS;AACR,IAAA,YAAY;AACb,IAAA,OAAO;AACP,IAAA,SAAS;AACR,IAAA,YAAY;AACZ,IAAA,QAAQ;IACT,iBAAiB,GAA0C,EAAE;IAC/E,aAAa,GAAG,KAAK;IACF,MAAM,GAAkB,IAAI;AAE7B,IAAA,qBAAqB;AAEzC,IAAA,cAAc;IAErB,IAA+B,OAAO,CAAC,eAAuC,EAAA;;AAE5E,QAAA,IAAI,CAAC,QAAQ,GAAG,eAA8B;IAChD;AAEA,IAAA,WAAA,GAAA;QACE,eAAe,CAAC,MAAK;;YAEnB,IAAI,CAAC,qBAAqB,EAAE;AAC9B,QAAA,CAAC,CAAC;IACJ;AAEA;;;AAGG;AACH,IAAA,IAAI,UAAU,GAAA;QACZ,OAAO,IAAI,CAAC,QAAQ;IACtB;AAEA;;;;;AAKG;AAEK,IAAA,eAAe,CAAC,YAAgC,EAAA;;AAEtD,QAAA,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ;AAC7B,QAAA,MAAM,IAAI,GAAG,YAAY,IAAK,QAAQ,CAAC,aAAa,CAAC,CAAA,CAAA,EAAI,IAAI,CAAC,cAAc,CAAA,CAAE,CAAsB,CAAC,KAAK;QAC1G,MAAM,YAAY,GAAG,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,IAAI;AACtF,QAAA,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK;AACnC,Q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ACE,SAAS,EAAA,CAAA;sBAAnC,KAAK;uBAAC,EAAE,QAAQ,EAAE,IAAI,EAAE;gBACG,YAAY,EAAA,CAAA;sBAAvC,KAAK;uBAAC,EAAE,QAAQ,EAAE,KAAK,EAAE;gBACE,QAAQ,EAAA,CAAA;sBAAnC,KAAK;uBAAC,EAAE,QAAQ,EAAE,KAAK,EAAE;gBACC,iBAAiB,EAAA,CAAA;sBAA3C,KAAK;uBAAC,EAAE,QAAQ,EAAE,IAAI,EAAE;gBAChB,aAAa,EAAA,CAAA;sBAArB;gBAC2B,MAAM,EAAA,CAAA;sBAAjC,KAAK;uBAAC,EAAE,QAAQ,EAAE,KAAK,EAAE;gBAEC,qBAAqB,EAAA,CAAA;sBAA/C,SAAS;uBAAC,cAAc;gBAIM,OAAO,EAAA,CAAA;sBAArC,KAAK;uBAAC,EAAE,QAAQ,EAAE,IAAI,EAAE;;;AE3C3B;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"hmcts-opal-frontend-common-components-alphagov-alphagov-accessible-autocomplete.mjs","sources":["../../../projects/opal-frontend-common/components/alphagov/alphagov-accessible-autocomplete/alphagov-accessible-autocomplete.component.ts","../../../projects/opal-frontend-common/components/alphagov/alphagov-accessible-autocomplete/alphagov-accessible-autocomplete.component.html","../../../projects/opal-frontend-common/components/alphagov/alphagov-accessible-autocomplete/hmcts-opal-frontend-common-components-alphagov-alphagov-accessible-autocomplete.ts"],"sourcesContent":["import {\n ChangeDetectionStrategy,\n ChangeDetectorRef,\n Component,\n ElementRef,\n Input,\n OnDestroy,\n OnInit,\n ViewChild,\n afterNextRender,\n inject,\n} from '@angular/core';\nimport { FormControl, AbstractControl, ReactiveFormsModule } from '@angular/forms';\nimport { IAlphagovAccessibleAutocompleteItem } from './interfaces/alphagov-accessible-autocomplete-item.interface';\nimport { AccessibleAutocompleteProps } from 'accessible-autocomplete';\nimport { Subject, pairwise, startWith, takeUntil } from 'rxjs';\n\n@Component({\n selector: 'opal-lib-alphagov-accessible-autocomplete',\n imports: [ReactiveFormsModule],\n templateUrl: './alphagov-accessible-autocomplete.component.html',\n styleUrl: './alphagov-accessible-autocomplete.component.scss',\n changeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class AlphagovAccessibleAutocompleteComponent implements OnInit, OnDestroy {\n private readonly changeDetector: ChangeDetectorRef = inject(ChangeDetectorRef);\n private _control!: FormControl;\n private readonly ngUnsubscribe = new Subject<void>();\n\n @Input({ required: true }) labelText!: string;\n @Input({ required: false }) labelClasses!: string;\n @Input({ required: true }) inputId!: string;\n @Input({ required: true }) inputName!: string;\n @Input({ required: false }) inputClasses!: string;\n @Input({ required: false }) hintText!: string;\n @Input({ required: true }) autoCompleteItems: IAlphagovAccessibleAutocompleteItem[] = [];\n @Input() showAllValues = true;\n @Input({ required: false }) errors: string | null = null;\n\n @ViewChild('autocomplete') autocompleteContainer!: ElementRef<HTMLElement>;\n\n public autoCompleteId!: string;\n\n @Input({ required: true }) set control(abstractControl: AbstractControl | null) {\n // Form controls are passed in as abstract controls, we need to re-cast it.\n this._control = abstractControl as FormControl;\n }\n\n constructor() {\n afterNextRender(() => {\n // Only trigger the render of the component in the browser\n this.configureAutoComplete();\n });\n }\n\n /**\n * Gets the control for the alphagov-accessible-autocomplete component.\n * @returns The control for the component.\n */\n get getControl() {\n return this._control;\n }\n\n /**\n * Handles the confirmation of a selected name.\n *\n * @param selectedName - The selected name.\n * @returns void\n */\n\n private handleOnConfirm(selectedName: string | undefined): void {\n // selectedName is populated on selecting an option but is undefined onBlur, so we need to grab the input value directly from the input\n const control = this._control;\n const name = selectedName ?? (document.querySelector(`#${this.autoCompleteId}`) as HTMLInputElement).value;\n const selectedItem = this.autoCompleteItems.find((item) => item.name === name) ?? null;\n const previousValue = control.value;\n const selectedValue = selectedItem?.value ?? null;\n\n control.setValue(selectedValue);\n control.markAsTouched();\n\n // Handles initial empty state when the user clicks away from the input\n if (selectedItem === null && previousValue === null) {\n control.markAsPristine();\n } else if (selectedItem?.value !== previousValue) {\n control.markAsDirty();\n }\n\n control.updateValueAndValidity();\n this.changeDetector.detectChanges();\n }\n\n /**\n * Retrieves the default value for the autocomplete component.\n *\n * @returns The default value as a string.\n */\n\n private getDefaultValue() {\n return this.autoCompleteItems.find((item) => item.value === this._control.value)?.name ?? '';\n }\n\n /**\n * Builds the props object for the AccessibleAutocomplete component.\n * @returns The props object for the AccessibleAutocomplete component.\n */\n private buildAutoCompleteProps(): AccessibleAutocompleteProps {\n return {\n id: this.autoCompleteId,\n element: this.autocompleteContainer.nativeElement,\n source: this.autoCompleteItems.map((item) => item.name),\n name: this.autoCompleteId,\n showAllValues: this.showAllValues,\n defaultValue: this.getDefaultValue(),\n onConfirm: (selectedName: string) => this.handleOnConfirm(selectedName),\n };\n }\n\n /**\n * Configures the auto-complete functionality using the accessible-autocomplete library.\n */\n private configureAutoComplete(): void {\n import('accessible-autocomplete').then((accessibleAutocomplete) => {\n accessibleAutocomplete.default(this.buildAutoCompleteProps());\n });\n }\n\n /**\n * Sets up the control subscription for value changes.\n * Whenever the control value changes, this method is called to handle the changes.\n * If the new value is null, it clears the autocomplete container and configures the autocomplete.\n */\n private setupControlSub(): void {\n this._control.valueChanges\n .pipe(startWith(null), pairwise(), takeUntil(this.ngUnsubscribe))\n .subscribe(([prev, next]) => {\n // If both values are null, we don't need to do anything\n if (prev === null && next === null) {\n return;\n }\n\n // Otherwise, next is null, we need to clear the autocomplete\n if (next === null) {\n this.autocompleteContainer.nativeElement.innerHTML = '';\n this.configureAutoComplete();\n }\n });\n }\n\n ngOnInit(): void {\n this.autoCompleteId = this.inputId + '-autocomplete';\n this.setupControlSub();\n }\n\n ngOnDestroy(): void {\n this.ngUnsubscribe.next();\n this.ngUnsubscribe.complete();\n }\n}\n","<div class=\"govuk-form-group\" [class.govuk-form-group--error]=\"!!errors\">\n <label class=\"govuk-label {{ labelClasses }}\" [for]=\"autoCompleteId\"> {{ labelText }} </label>\n @if (hintText) {\n <div id=\"{{ inputId }}-hint\" class=\"govuk-hint\">\n {{ hintText }}\n </div>\n }\n\n @if (errors) {\n <p id=\"{{ this.autoCompleteId }}-error-message\" class=\"govuk-error-message\">\n <span class=\"govuk-visually-hidden\">Error: </span> {{ errors }}\n </p>\n }\n\n <div #autocomplete id=\"{{ autoCompleteId }}-container\" class=\"{{ inputClasses }}\"></div>\n <input [id]=\"inputId\" [name]=\"inputName\" type=\"hidden\" [formControl]=\"getControl\" />\n</div>\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;MAwBa,uCAAuC,CAAA;AACjC,IAAA,cAAc,GAAsB,MAAM,CAAC,iBAAiB,CAAC;AACtE,IAAA,QAAQ;AACC,IAAA,aAAa,GAAG,IAAI,OAAO,EAAQ;AAEzB,IAAA,SAAS;AACR,IAAA,YAAY;AACb,IAAA,OAAO;AACP,IAAA,SAAS;AACR,IAAA,YAAY;AACZ,IAAA,QAAQ;IACT,iBAAiB,GAA0C,EAAE;IAC/E,aAAa,GAAG,IAAI;IACD,MAAM,GAAkB,IAAI;AAE7B,IAAA,qBAAqB;AAEzC,IAAA,cAAc;IAErB,IAA+B,OAAO,CAAC,eAAuC,EAAA;;AAE5E,QAAA,IAAI,CAAC,QAAQ,GAAG,eAA8B;IAChD;AAEA,IAAA,WAAA,GAAA;QACE,eAAe,CAAC,MAAK;;YAEnB,IAAI,CAAC,qBAAqB,EAAE;AAC9B,QAAA,CAAC,CAAC;IACJ;AAEA;;;AAGG;AACH,IAAA,IAAI,UAAU,GAAA;QACZ,OAAO,IAAI,CAAC,QAAQ;IACtB;AAEA;;;;;AAKG;AAEK,IAAA,eAAe,CAAC,YAAgC,EAAA;;AAEtD,QAAA,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ;AAC7B,QAAA,MAAM,IAAI,GAAG,YAAY,IAAK,QAAQ,CAAC,aAAa,CAAC,CAAA,CAAA,EAAI,IAAI,CAAC,cAAc,CAAA,CAAE,CAAsB,CAAC,KAAK;QAC1G,MAAM,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AE,IAAI,EAAE;gBACG,YAAY,EAAA,CAAA;sBAAvC,KAAK;uBAAC,EAAE,QAAQ,EAAE,KAAK,EAAE;gBACC,OAAO,EAAA,CAAA;sBAAjC,KAAK;uBAAC,EAAE,QAAQ,EAAE,IAAI,EAAE;gBACE,SAAS,EAAA,CAAA;sBAAnC,KAAK;uBAAC,EAAE,QAAQ,EAAE,IAAI,EAAE;gBACG,YAAY,EAAA,CAAA;sBAAvC,KAAK;uBAAC,EAAE,QAAQ,EAAE,KAAK,EAAE;gBACE,QAAQ,EAAA,CAAA;sBAAnC,KAAK;uBAAC,EAAE,QAAQ,EAAE,KAAK,EAAE;gBACC,iBAAiB,EAAA,CAAA;sBAA3C,KAAK;uBAAC,EAAE,QAAQ,EAAE,IAAI,EAAE;gBAChB,aAAa,EAAA,CAAA;sBAArB;gBAC2B,MAAM,EAAA,CAAA;sBAAjC,KAAK;uBAAC,EAAE,QAAQ,EAAE,KAAK,EAAE;gBAEC,qBAAqB,EAAA,CAAA;sBAA/C,SAAS;uBAAC,cAAc;gBAIM,OAAO,EAAA,CAAA;sBAArC,KAAK;uBAAC,EAAE,QAAQ,EAAE,IAAI,EAAE;;;AE3C3B;;AAEG;;;;"}
|
|
@@ -118,6 +118,36 @@ class UtilsService {
|
|
|
118
118
|
return [key, value];
|
|
119
119
|
}));
|
|
120
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Strips out the first parentheses block from the given text.
|
|
123
|
+
* This method looks for the first occurrence of parentheses in the text,
|
|
124
|
+
* removes the content within them, and returns the modified text.
|
|
125
|
+
* @param {string} text - The text from which to strip the first parentheses block.
|
|
126
|
+
* @returns {string} - The modified text with the first parentheses block removed.
|
|
127
|
+
*/
|
|
128
|
+
stripFirstParenthesesBlock(text) {
|
|
129
|
+
const open = text.indexOf('(');
|
|
130
|
+
const close = text.indexOf(')', open);
|
|
131
|
+
if (open !== -1 && close !== -1 && close > open) {
|
|
132
|
+
const before = text.slice(0, open);
|
|
133
|
+
const after = text.slice(close + 1);
|
|
134
|
+
return (before + after).trim();
|
|
135
|
+
}
|
|
136
|
+
return text.trim();
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Determines whether the provided object has at least one property set to a meaningful value.
|
|
140
|
+
*
|
|
141
|
+
* A property is considered "set" if:
|
|
142
|
+
* - It is a boolean and its value is `true`.
|
|
143
|
+
* - It is not a boolean and its value is neither `null` nor an empty string.
|
|
144
|
+
*
|
|
145
|
+
* @param value - The object to check for set properties. Can be `null` or `undefined`.
|
|
146
|
+
* @returns `true` if at least one property is set; otherwise, `false`.
|
|
147
|
+
*/
|
|
148
|
+
hasSetProperty(value) {
|
|
149
|
+
return Object.values(value ?? {}).some((v) => (typeof v === 'boolean' ? v === true : v !== null && v !== ''));
|
|
150
|
+
}
|
|
121
151
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: UtilsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
122
152
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.4", ngImport: i0, type: UtilsService, providedIn: 'root' });
|
|
123
153
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmcts-opal-frontend-common-services-utils-service.mjs","sources":["../../../projects/opal-frontend-common/services/utils-service/utils.service.ts","../../../projects/opal-frontend-common/services/utils-service/hmcts-opal-frontend-common-services-utils-service.ts"],"sourcesContent":["import { ViewportScroller } from '@angular/common';\nimport { inject, Injectable } from '@angular/core';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class UtilsService {\n private readonly viewportScroller = inject(ViewportScroller);\n\n /**\n * Converts the first letter of a string to uppercase.\n * @param str - The input string.\n * @returns The input string with the first letter capitalized.\n */\n public upperCaseFirstLetter(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1);\n }\n\n /**\n * Converts the entire string to uppercase.\n * @param str - The input string.\n * @returns The input string in uppercase.\n */\n public upperCaseAllLetters(str: string): string {\n return str.toUpperCase();\n }\n\n /**\n * Converts a number to a monetary string representation.\n * @param amount - The number to convert.\n * @returns The monetary string representation of the number.\n */\n public convertToMonetaryString(amount: number | string): string {\n if (typeof amount === 'string') {\n amount = parseFloat(amount);\n }\n return `£${amount.toFixed(2)}`;\n }\n\n /**\n * Formats a 6-digit number or string as a sort code.\n * @param value - The 6-digit value to format.\n * @returns The formatted sort code string (xx-xx-xx).\n */\n public formatSortCode(value: string | number): string {\n const sortCode = value.toString();\n return `${sortCode.slice(0, 2)}-${sortCode.slice(2, 4)}-${sortCode.slice(4, 6)}`;\n }\n\n /**\n * Filters out null or empty strings from an array of address lines.\n *\n * @param address - An array of address lines which may contain strings or null values.\n * @returns A new array containing only non-empty strings from the input array.\n */\n public formatAddress(address: (string | null)[]): string[] {\n return address.filter((line): line is string => !!line?.trim());\n }\n\n /**\n * Scrolls the viewport to the top of the page.\n * Utilizes the `viewportScroller` service to scroll to the position [0, 0].\n */\n public scrollToTop(): void {\n this.viewportScroller.scrollToPosition([0, 0]);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public checkFormValues(form: { [key: string]: any }): boolean {\n return Object.values(form).some((value) => {\n return Array.isArray(value) ? value.length > 0 : Boolean(value);\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public checkFormArrayValues(forms: { [key: string]: any }[]): boolean {\n return forms.every((form) => this.checkFormValues(form));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public getFormStatus(form: { [key: string]: any }, providedMessage: string, notProvidedMessage: string): string {\n return this.checkFormValues(form) ? providedMessage : notProvidedMessage;\n }\n\n public getArrayFormStatus(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n forms: { [key: string]: any }[],\n providedMessage: string,\n notProvidedMessage: string,\n ): string {\n return forms.every((form) => this.checkFormValues(form)) ? providedMessage : notProvidedMessage;\n }\n\n /**\n * Copies the provided string value to the clipboard.\n *\n * @param value - The string value to be copied to the clipboard.\n *\n * @remarks\n * This method uses the `navigator.clipboard.writeText` API to copy text to the clipboard.\n * Ensure that the browser supports the Clipboard API before using this method.\n */\n public copyToClipboard(value: string): Promise<void> {\n return navigator.clipboard.writeText(value);\n }\n\n /**\n * Recursively filters out properties from an object where the value is `null` or `undefined`.\n *\n * @param obj - The object to filter. Can include nested objects.\n * @returns A new object with only non-null and non-undefined values.\n *\n * @example\n * ```ts\n * const input = {\n * a: 1,\n * b: null,\n * c: undefined,\n * d: 'hello',\n * e: { x: null, y: 2 },\n * f: { z: undefined },\n * };\n * const result = filterNullOrUndefined(input);\n * console.log(result); // Output: { a: 1, d: 'hello', e: { y: 2 } }\n * ```\n */\n public filterNullOrUndefined(obj: Record<string, unknown>): Record<string, unknown> {\n return Object.fromEntries(\n Object.entries(obj)\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n .filter(([_, value]) => value !== null && value !== undefined)\n .map(([key, value]) => {\n if (typeof value === 'object' && !Array.isArray(value) && value !== null) {\n return [key, this.filterNullOrUndefined(value as Record<string, unknown>)];\n }\n return [key, value];\n }),\n );\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;MAMa,YAAY,CAAA;AACN,IAAA,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC;AAE5D;;;;AAIG;AACI,IAAA,oBAAoB,CAAC,GAAW,EAAA;AACrC,QAAA,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;IACnD;AAEA;;;;AAIG;AACI,IAAA,mBAAmB,CAAC,GAAW,EAAA;AACpC,QAAA,OAAO,GAAG,CAAC,WAAW,EAAE;IAC1B;AAEA;;;;AAIG;AACI,IAAA,uBAAuB,CAAC,MAAuB,EAAA;AACpD,QAAA,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;AAC9B,YAAA,MAAM,GAAG,UAAU,CAAC,M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AAM,EAAA,CAAA;;2FAEP,YAAY,EAAA,UAAA,EAAA,CAAA;kBAHxB,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA;;;ACLD;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"hmcts-opal-frontend-common-services-utils-service.mjs","sources":["../../../projects/opal-frontend-common/services/utils-service/utils.service.ts","../../../projects/opal-frontend-common/services/utils-service/hmcts-opal-frontend-common-services-utils-service.ts"],"sourcesContent":["import { ViewportScroller } from '@angular/common';\nimport { inject, Injectable } from '@angular/core';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class UtilsService {\n private readonly viewportScroller = inject(ViewportScroller);\n\n /**\n * Converts the first letter of a string to uppercase.\n * @param str - The input string.\n * @returns The input string with the first letter capitalized.\n */\n public upperCaseFirstLetter(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1);\n }\n\n /**\n * Converts the entire string to uppercase.\n * @param str - The input string.\n * @returns The input string in uppercase.\n */\n public upperCaseAllLetters(str: string): string {\n return str.toUpperCase();\n }\n\n /**\n * Converts a number to a monetary string representation.\n * @param amount - The number to convert.\n * @returns The monetary string representation of the number.\n */\n public convertToMonetaryString(amount: number | string): string {\n if (typeof amount === 'string') {\n amount = parseFloat(amount);\n }\n return `£${amount.toFixed(2)}`;\n }\n\n /**\n * Formats a 6-digit number or string as a sort code.\n * @param value - The 6-digit value to format.\n * @returns The formatted sort code string (xx-xx-xx).\n */\n public formatSortCode(value: string | number): string {\n const sortCode = value.toString();\n return `${sortCode.slice(0, 2)}-${sortCode.slice(2, 4)}-${sortCode.slice(4, 6)}`;\n }\n\n /**\n * Filters out null or empty strings from an array of address lines.\n *\n * @param address - An array of address lines which may contain strings or null values.\n * @returns A new array containing only non-empty strings from the input array.\n */\n public formatAddress(address: (string | null)[]): string[] {\n return address.filter((line): line is string => !!line?.trim());\n }\n\n /**\n * Scrolls the viewport to the top of the page.\n * Utilizes the `viewportScroller` service to scroll to the position [0, 0].\n */\n public scrollToTop(): void {\n this.viewportScroller.scrollToPosition([0, 0]);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public checkFormValues(form: { [key: string]: any }): boolean {\n return Object.values(form).some((value) => {\n return Array.isArray(value) ? value.length > 0 : Boolean(value);\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public checkFormArrayValues(forms: { [key: string]: any }[]): boolean {\n return forms.every((form) => this.checkFormValues(form));\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public getFormStatus(form: { [key: string]: any }, providedMessage: string, notProvidedMessage: string): string {\n return this.checkFormValues(form) ? providedMessage : notProvidedMessage;\n }\n\n public getArrayFormStatus(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n forms: { [key: string]: any }[],\n providedMessage: string,\n notProvidedMessage: string,\n ): string {\n return forms.every((form) => this.checkFormValues(form)) ? providedMessage : notProvidedMessage;\n }\n\n /**\n * Copies the provided string value to the clipboard.\n *\n * @param value - The string value to be copied to the clipboard.\n *\n * @remarks\n * This method uses the `navigator.clipboard.writeText` API to copy text to the clipboard.\n * Ensure that the browser supports the Clipboard API before using this method.\n */\n public copyToClipboard(value: string): Promise<void> {\n return navigator.clipboard.writeText(value);\n }\n\n /**\n * Recursively filters out properties from an object where the value is `null` or `undefined`.\n *\n * @param obj - The object to filter. Can include nested objects.\n * @returns A new object with only non-null and non-undefined values.\n *\n * @example\n * ```ts\n * const input = {\n * a: 1,\n * b: null,\n * c: undefined,\n * d: 'hello',\n * e: { x: null, y: 2 },\n * f: { z: undefined },\n * };\n * const result = filterNullOrUndefined(input);\n * console.log(result); // Output: { a: 1, d: 'hello', e: { y: 2 } }\n * ```\n */\n public filterNullOrUndefined(obj: Record<string, unknown>): Record<string, unknown> {\n return Object.fromEntries(\n Object.entries(obj)\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n .filter(([_, value]) => value !== null && value !== undefined)\n .map(([key, value]) => {\n if (typeof value === 'object' && !Array.isArray(value) && value !== null) {\n return [key, this.filterNullOrUndefined(value as Record<string, unknown>)];\n }\n return [key, value];\n }),\n );\n }\n\n /**\n * Strips out the first parentheses block from the given text.\n * This method looks for the first occurrence of parentheses in the text,\n * removes the content within them, and returns the modified text.\n * @param {string} text - The text from which to strip the first parentheses block.\n * @returns {string} - The modified text with the first parentheses block removed.\n */\n public stripFirstParenthesesBlock(text: string): string {\n const open = text.indexOf('(');\n const close = text.indexOf(')', open);\n if (open !== -1 && close !== -1 && close > open) {\n const before = text.slice(0, open);\n const after = text.slice(close + 1);\n return (before + after).trim();\n }\n return text.trim();\n }\n\n /**\n * Determines whether the provided object has at least one property set to a meaningful value.\n *\n * A property is considered \"set\" if:\n * - It is a boolean and its value is `true`.\n * - It is not a boolean and its value is neither `null` nor an empty string.\n *\n * @param value - The object to check for set properties. Can be `null` or `undefined`.\n * @returns `true` if at least one property is set; otherwise, `false`.\n */\n public hasSetProperty(value: object | null | undefined): boolean {\n return Object.values(value ?? {}).some((v) => (typeof v === 'boolean' ? v === true : v !== null && v !== ''));\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;MAMa,YAAY,CAAA;AACN,IAAA,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC;AAE5D;;;;AAIG;AACI,IAAA,oBAAoB,CAAC,GAAW,EAAA;AACrC,QAAA,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;IACnD;AAEA;;;;AAIG;AACI,IAAA,mBAAmB,CAAC,GAAW,EAAA;AACpC,QAAA,OAAO,GAAG,CAAC,WAAW,EAAE;IAC1B;AAEA;;;;AAIG;AACI,IAAA,uBAAuB,CAAC,MAAuB,EAAA;AACpD,QAAA,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;AAC9B,YAAA,MAAM,GAAG,UAAU,CAAC,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CAAC,IAAI,KAAK,GAAG,IAAI,EAAE;YAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC;YAClC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC;YACnC,OAAO,CAAC,MAAM,GAAG,KAAK,EAAE,IAAI,EAAE;QAChC;AACA,QAAA,OAAO,IAAI,CAAC,IAAI,EAAE;IACpB;AAEA;;;;;;;;;AASG;AACI,IAAA,cAAc,CAAC,KAAgC,EAAA;AACpD,QAAA,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,KAAK,SAAS,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IAC/G;uGApKW,YAAY,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAZ,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,YAAY,cAFX,MAAM,EAAA,CAAA;;2FAEP,YAAY,EAAA,UAAA,EAAA,CAAA;kBAHxB,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA;;;ACLD;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -81,6 +81,25 @@ declare class UtilsService {
|
|
|
81
81
|
* ```
|
|
82
82
|
*/
|
|
83
83
|
filterNullOrUndefined(obj: Record<string, unknown>): Record<string, unknown>;
|
|
84
|
+
/**
|
|
85
|
+
* Strips out the first parentheses block from the given text.
|
|
86
|
+
* This method looks for the first occurrence of parentheses in the text,
|
|
87
|
+
* removes the content within them, and returns the modified text.
|
|
88
|
+
* @param {string} text - The text from which to strip the first parentheses block.
|
|
89
|
+
* @returns {string} - The modified text with the first parentheses block removed.
|
|
90
|
+
*/
|
|
91
|
+
stripFirstParenthesesBlock(text: string): string;
|
|
92
|
+
/**
|
|
93
|
+
* Determines whether the provided object has at least one property set to a meaningful value.
|
|
94
|
+
*
|
|
95
|
+
* A property is considered "set" if:
|
|
96
|
+
* - It is a boolean and its value is `true`.
|
|
97
|
+
* - It is not a boolean and its value is neither `null` nor an empty string.
|
|
98
|
+
*
|
|
99
|
+
* @param value - The object to check for set properties. Can be `null` or `undefined`.
|
|
100
|
+
* @returns `true` if at least one property is set; otherwise, `false`.
|
|
101
|
+
*/
|
|
102
|
+
hasSetProperty(value: object | null | undefined): boolean;
|
|
84
103
|
static ɵfac: i0.ɵɵFactoryDeclaration<UtilsService, never>;
|
|
85
104
|
static ɵprov: i0.ɵɵInjectableDeclaration<UtilsService>;
|
|
86
105
|
}
|