@tilde-nlp/ngx-common 8.0.5 → 8.0.7

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.
@@ -19,7 +19,7 @@ import { MatTooltipModule } from '@angular/material/tooltip';
19
19
  import * as i2$2 from '@ngbracket/ngx-layout/flex';
20
20
  import * as i3 from '@ngbracket/ngx-layout/extended';
21
21
  import * as i1$4 from '@angular/common/http';
22
- import { HttpErrorResponse, provideHttpClient, withInterceptorsFromDi, HttpClient } from '@angular/common/http';
22
+ import { HttpErrorResponse, HttpHeaders, provideHttpClient, withInterceptorsFromDi, HttpClient } from '@angular/common/http';
23
23
  import * as i15 from '@angular/material/paginator';
24
24
  import { MatPaginatorIntl, MatPaginator, MatPaginatorModule } from '@angular/material/paginator';
25
25
  import * as i2$4 from '@angular/material/progress-spinner';
@@ -632,6 +632,11 @@ class AuthHeadersHelper {
632
632
  }
633
633
  return authHeaders;
634
634
  }
635
+ static getLangHeaders(lang) {
636
+ return new HttpHeaders({
637
+ 'Accept-Language': lang,
638
+ });
639
+ }
635
640
  }
636
641
 
637
642
  class FileExtensionHelper {
@@ -670,10 +675,10 @@ class SortHelper {
670
675
  });
671
676
  }
672
677
  /**
673
- * Transforms the input array of objects by sorting them based on the specified sortingValueKey.
674
- * @param values - An array of objects to be sorted.
675
- * @param sortingValueKey - The key by which the provided values should be sorted, leave it empty if you want to sort string[].
676
- */
678
+ * Transforms the input array of objects by sorting them based on the specified sortingValueKey.
679
+ * @param values - An array of objects to be sorted.
680
+ * @param sortingValueKey - The key by which the provided values should be sorted, leave it empty if you want to sort string[].
681
+ */
677
682
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
678
683
  static sortAlphabetically(values, sortingValueKey) {
679
684
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -688,27 +693,60 @@ class SortHelper {
688
693
  return values;
689
694
  }
690
695
  /**
691
- * Sorts an array of values by a specified numeric property or by their numeric value if no property is specified.
692
- * @param values - The array of values to be sorted. Can be an array of objects or primitive numeric values.
693
- * @param sortingValueKey - The key of the numeric property in the objects to sort by.
694
- * @param desc - Flag indicating whether to sort in descending (true) or ascending (false) order.
695
- */
696
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
696
+ * Sorts an array of values by a specified numeric property or by their numeric value if no property is specified.
697
+ * @param values - The array of values to be sorted. Can be an array of objects or primitive numeric values.
698
+ * @param sortingValueKey - The key of the numeric property in the objects to sort by.
699
+ * @param desc - Flag indicating whether to sort in descending (true) or ascending (false) order.
700
+ */
697
701
  static sortByNumber(values, sortingValueKey, desc = true) {
698
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
702
+ const getValueByKey = (obj, keyPath) => {
703
+ if (!keyPath)
704
+ return Number(obj ?? 0);
705
+ const keys = keyPath.split('.');
706
+ let value = obj;
707
+ for (const key of keys) {
708
+ if (value && typeof value === 'object' && key in value) {
709
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
710
+ value = value[key];
711
+ }
712
+ }
713
+ return Number(value ?? 0);
714
+ };
699
715
  values.sort((a, b) => {
700
- const numberA = sortingValueKey ? Number(a[sortingValueKey] ?? 0) : Number(a);
701
- const numberB = sortingValueKey ? Number(b[sortingValueKey] ?? 0) : Number(b);
702
- return desc ? numberA - numberB : numberB - numberA;
716
+ const numberA = getValueByKey(a, sortingValueKey);
717
+ const numberB = getValueByKey(b, sortingValueKey);
718
+ return desc ? numberB - numberA : numberA - numberB;
703
719
  });
704
720
  return values;
705
721
  }
706
722
  /**
707
- * This method is intended to be used with sorting methods like Array.sort(). It compares two strings, a and b, against a reference substring input.
708
- * @param a - The first string to be compared.
709
- * @param b - The second string to be compared.
710
- * @param input - The reference substring used to influence the sorting order.
711
- */
723
+ * Sorts an array of values by a specified boolean property or by their boolean value if no property is specified.
724
+ * @param values - The array of values to be sorted. Can be an array of objects or primitive boolean values.
725
+ * @param sortingValueKey - The key of the boolean property in the objects to sort by.
726
+ * @param desc - Flag indicating whether to sort in descending (true) or ascending (false) order.
727
+ */
728
+ static sortByBoolean(values, sortingValueKey, desc = true) {
729
+ const getValue = (item) => {
730
+ if (sortingValueKey) {
731
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
732
+ const value = item[sortingValueKey];
733
+ return Boolean(value);
734
+ }
735
+ return Boolean(item);
736
+ };
737
+ values.sort((a, b) => {
738
+ const valA = getValue(a) ? 1 : 0;
739
+ const valB = getValue(b) ? 1 : 0;
740
+ return desc ? valB - valA : valA - valB;
741
+ });
742
+ return values;
743
+ }
744
+ /**
745
+ * This method is intended to be used with sorting methods like Array.sort(). It compares two strings, a and b, against a reference substring input.
746
+ * @param a - The first string to be compared.
747
+ * @param b - The second string to be compared.
748
+ * @param input - The reference substring used to influence the sorting order.
749
+ */
712
750
  static sortByStartingLetter(a, b, input) {
713
751
  const startsWithInputA = a.toLowerCase().startsWith(input.toLowerCase());
714
752
  const startsWithInputB = b.toLowerCase().startsWith(input.toLowerCase());