@sneat/components 0.1.2 → 0.1.4

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.
Files changed (170) hide show
  1. package/esm2022/index.js +15 -0
  2. package/esm2022/index.js.map +1 -0
  3. package/esm2022/lib/app-version/app-version.component.js +16 -0
  4. package/esm2022/lib/app-version/app-version.component.js.map +1 -0
  5. package/esm2022/lib/app-version/build-info.js +5 -0
  6. package/esm2022/lib/app-version/build-info.js.map +1 -0
  7. package/esm2022/lib/app-version/index.js +3 -0
  8. package/esm2022/lib/app-version/index.js.map +1 -0
  9. package/esm2022/lib/card-list/index.js +2 -0
  10. package/esm2022/lib/card-list/index.js.map +1 -0
  11. package/esm2022/lib/card-list/sneat-card-list.component.js +106 -0
  12. package/esm2022/lib/card-list/sneat-card-list.component.js.map +1 -0
  13. package/esm2022/lib/copyright/copyright.component.js +11 -0
  14. package/esm2022/lib/copyright/copyright.component.js.map +1 -0
  15. package/esm2022/lib/copyright/index.js +2 -0
  16. package/esm2022/lib/copyright/index.js.map +1 -0
  17. package/esm2022/lib/country-input/country-input.component.js +59 -0
  18. package/esm2022/lib/country-input/country-input.component.js.map +1 -0
  19. package/esm2022/lib/country-input/index.js +2 -0
  20. package/esm2022/lib/country-input/index.js.map +1 -0
  21. package/esm2022/lib/country-selector/countries-loader.service.js +91 -0
  22. package/esm2022/lib/country-selector/countries-loader.service.js.map +1 -0
  23. package/esm2022/lib/country-selector/countries.js +22 -0
  24. package/esm2022/lib/country-selector/countries.js.map +1 -0
  25. package/esm2022/lib/country-selector/country-selector.component.js +103 -0
  26. package/esm2022/lib/country-selector/country-selector.component.js.map +1 -0
  27. package/esm2022/lib/country-selector/country-selector.service.js +15 -0
  28. package/esm2022/lib/country-selector/country-selector.service.js.map +1 -0
  29. package/esm2022/lib/country-selector/index.js +5 -0
  30. package/esm2022/lib/country-selector/index.js.map +1 -0
  31. package/esm2022/lib/date-input/date-input.component.js +70 -0
  32. package/esm2022/lib/date-input/date-input.component.js.map +1 -0
  33. package/esm2022/lib/date-input/date-modal.component.js +53 -0
  34. package/esm2022/lib/date-input/date-modal.component.js.map +1 -0
  35. package/esm2022/lib/dialog-header/dialog-header.component.js +23 -0
  36. package/esm2022/lib/dialog-header/dialog-header.component.js.map +1 -0
  37. package/esm2022/lib/dialog-header/index.js +2 -0
  38. package/esm2022/lib/dialog-header/index.js.map +1 -0
  39. package/esm2022/lib/error-card/index.js +2 -0
  40. package/esm2022/lib/error-card/index.js.map +1 -0
  41. package/esm2022/lib/error-card/sneat-error-card.component.js +23 -0
  42. package/esm2022/lib/error-card/sneat-error-card.component.js.map +1 -0
  43. package/esm2022/lib/filter-item/filter-item.component.js +37 -0
  44. package/esm2022/lib/filter-item/filter-item.component.js.map +1 -0
  45. package/esm2022/lib/filter-item/index.js +2 -0
  46. package/esm2022/lib/filter-item/index.js.map +1 -0
  47. package/esm2022/lib/pipes/country-emoji.pipe.js +69 -0
  48. package/esm2022/lib/pipes/country-emoji.pipe.js.map +1 -0
  49. package/esm2022/lib/pipes/decimal64p2.pipe.js +47 -0
  50. package/esm2022/lib/pipes/decimal64p2.pipe.js.map +1 -0
  51. package/esm2022/lib/pipes/gender.pipes.js +69 -0
  52. package/esm2022/lib/pipes/gender.pipes.js.map +1 -0
  53. package/esm2022/lib/pipes/index.js +7 -0
  54. package/esm2022/lib/pipes/index.js.map +1 -0
  55. package/esm2022/lib/pipes/long-month-name.pipe.js +41 -0
  56. package/esm2022/lib/pipes/long-month-name.pipe.js.map +1 -0
  57. package/esm2022/lib/pipes/short-month-name.pipe.js +31 -0
  58. package/esm2022/lib/pipes/short-month-name.pipe.js.map +1 -0
  59. package/esm2022/lib/pipes/team-emoji.pipe.js +31 -0
  60. package/esm2022/lib/pipes/team-emoji.pipe.js.map +1 -0
  61. package/esm2022/lib/save-event.js +2 -0
  62. package/esm2022/lib/save-event.js.map +1 -0
  63. package/esm2022/lib/user-country/user-country.component.js +136 -0
  64. package/esm2022/lib/user-country/user-country.component.js.map +1 -0
  65. package/esm2022/lib/virtual-slider/virtual-slider.js +83 -0
  66. package/esm2022/lib/virtual-slider/virtual-slider.js.map +1 -0
  67. package/esm2022/sneat-components.js +5 -0
  68. package/esm2022/sneat-components.js.map +1 -0
  69. package/lib/app-version/app-version.component.d.ts +9 -0
  70. package/lib/app-version/build-info.d.ts +4 -0
  71. package/lib/card-list/sneat-card-list.component.d.ts +43 -0
  72. package/lib/copyright/copyright.component.d.ts +5 -0
  73. package/lib/country-input/country-input.component.d.ts +16 -0
  74. package/lib/country-selector/countries-loader.service.d.ts +43 -0
  75. package/lib/country-selector/countries.d.ts +25 -0
  76. package/lib/country-selector/country-selector.component.d.ts +31 -0
  77. package/lib/country-selector/country-selector.service.d.ts +8 -0
  78. package/lib/date-input/date-input.component.d.ts +21 -0
  79. package/lib/date-input/date-modal.component.d.ts +13 -0
  80. package/lib/dialog-header/dialog-header.component.d.ts +8 -0
  81. package/lib/error-card/sneat-error-card.component.d.ts +8 -0
  82. package/lib/filter-item/filter-item.component.d.ts +13 -0
  83. package/lib/pipes/country-emoji.pipe.d.ts +29 -0
  84. package/lib/pipes/decimal64p2.pipe.d.ts +12 -0
  85. package/lib/pipes/gender.pipes.d.ts +20 -0
  86. package/lib/pipes/long-month-name.pipe.d.ts +7 -0
  87. package/lib/pipes/short-month-name.pipe.d.ts +8 -0
  88. package/lib/pipes/team-emoji.pipe.d.ts +8 -0
  89. package/lib/save-event.d.ts +5 -0
  90. package/lib/user-country/user-country.component.d.ts +24 -0
  91. package/lib/virtual-slider/virtual-slider.d.ts +13 -0
  92. package/package.json +14 -2
  93. package/sneat-components.d.ts +5 -0
  94. package/eslint.config.js +0 -7
  95. package/ng-package.json +0 -7
  96. package/project.json +0 -38
  97. package/src/assets/data/countries.json +0 -1730
  98. package/src/lib/app-version/app-version.component.html +0 -15
  99. package/src/lib/app-version/app-version.component.spec.ts +0 -25
  100. package/src/lib/app-version/app-version.component.ts +0 -17
  101. package/src/lib/app-version/build-info.ts +0 -8
  102. package/src/lib/card-list/sneat-card-list.component.html +0 -108
  103. package/src/lib/card-list/sneat-card-list.component.spec.ts +0 -131
  104. package/src/lib/card-list/sneat-card-list.component.ts +0 -125
  105. package/src/lib/copyright/copyright.component.html +0 -1
  106. package/src/lib/copyright/copyright.component.spec.ts +0 -24
  107. package/src/lib/copyright/copyright.component.ts +0 -7
  108. package/src/lib/country-input/country-input.component.html +0 -33
  109. package/src/lib/country-input/country-input.component.spec.ts +0 -84
  110. package/src/lib/country-input/country-input.component.ts +0 -76
  111. package/src/lib/country-selector/countries-loader.service.spec.ts +0 -149
  112. package/src/lib/country-selector/countries-loader.service.ts +0 -100
  113. package/src/lib/country-selector/countries.ts +0 -42
  114. package/src/lib/country-selector/country-selector.component.html +0 -24
  115. package/src/lib/country-selector/country-selector.component.spec.ts +0 -5
  116. package/src/lib/country-selector/country-selector.component.ts +0 -125
  117. package/src/lib/country-selector/country-selector.service.spec.ts +0 -23
  118. package/src/lib/country-selector/country-selector.service.ts +0 -11
  119. package/src/lib/date-input/date-input.component.html +0 -39
  120. package/src/lib/date-input/date-input.component.spec.ts +0 -179
  121. package/src/lib/date-input/date-input.component.ts +0 -97
  122. package/src/lib/date-input/date-modal.component.html +0 -23
  123. package/src/lib/date-input/date-modal.component.spec.ts +0 -105
  124. package/src/lib/date-input/date-modal.component.ts +0 -67
  125. package/src/lib/dialog-header/dialog-header.component.html +0 -8
  126. package/src/lib/dialog-header/dialog-header.component.spec.ts +0 -67
  127. package/src/lib/dialog-header/dialog-header.component.ts +0 -26
  128. package/src/lib/dismissable.ts +0 -6
  129. package/src/lib/error-card/sneat-error-card.component.html +0 -20
  130. package/src/lib/error-card/sneat-error-card.component.spec.ts +0 -49
  131. package/src/lib/error-card/sneat-error-card.component.ts +0 -28
  132. package/src/lib/filter-item/filter-item.component.html +0 -19
  133. package/src/lib/filter-item/filter-item.component.spec.ts +0 -83
  134. package/src/lib/filter-item/filter-item.component.ts +0 -47
  135. package/src/lib/pipes/country-emoji.pipe.spec.ts +0 -116
  136. package/src/lib/pipes/country-emoji.pipe.ts +0 -67
  137. package/src/lib/pipes/decimal64p2.pipe.spec.ts +0 -61
  138. package/src/lib/pipes/decimal64p2.pipe.ts +0 -35
  139. package/src/lib/pipes/gender.pipes.spec.ts +0 -84
  140. package/src/lib/pipes/gender.pipes.ts +0 -65
  141. package/src/lib/pipes/long-month-name.pipe.spec.ts +0 -36
  142. package/src/lib/pipes/long-month-name.pipe.ts +0 -35
  143. package/src/lib/pipes/short-month-name.pipe.spec.ts +0 -28
  144. package/src/lib/pipes/short-month-name.pipe.ts +0 -26
  145. package/src/lib/pipes/team-emoji.pipe.spec.ts +0 -27
  146. package/src/lib/pipes/team-emoji.pipe.ts +0 -26
  147. package/src/lib/save-event.ts +0 -5
  148. package/src/lib/test-ide-bug.ts +0 -24
  149. package/src/lib/user-country/user-country.component.html +0 -44
  150. package/src/lib/user-country/user-country.component.spec.ts +0 -136
  151. package/src/lib/user-country/user-country.component.ts +0 -172
  152. package/src/lib/virtual-slider/odd-even-virtual-slider.ts +0 -1
  153. package/src/lib/virtual-slider/virtual-slider.ts +0 -130
  154. package/src/lib/webstorm-type-err-demo.component.ts +0 -35
  155. package/src/test-setup.ts +0 -3
  156. package/tsconfig.json +0 -13
  157. package/tsconfig.lib.json +0 -19
  158. package/tsconfig.lib.prod.json +0 -7
  159. package/tsconfig.spec.json +0 -31
  160. package/vite.config.mts +0 -10
  161. /package/{src/index.ts → index.d.ts} +0 -0
  162. /package/{src/lib/app-version/index.ts → lib/app-version/index.d.ts} +0 -0
  163. /package/{src/lib/card-list/index.ts → lib/card-list/index.d.ts} +0 -0
  164. /package/{src/lib/copyright/index.ts → lib/copyright/index.d.ts} +0 -0
  165. /package/{src/lib/country-input/index.ts → lib/country-input/index.d.ts} +0 -0
  166. /package/{src/lib/country-selector/index.ts → lib/country-selector/index.d.ts} +0 -0
  167. /package/{src/lib/dialog-header/index.ts → lib/dialog-header/index.d.ts} +0 -0
  168. /package/{src/lib/error-card/index.ts → lib/error-card/index.d.ts} +0 -0
  169. /package/{src/lib/filter-item/index.ts → lib/filter-item/index.d.ts} +0 -0
  170. /package/{src/lib/pipes/index.ts → lib/pipes/index.d.ts} +0 -0
@@ -1,19 +0,0 @@
1
- <ion-item class="with-buttons" lines="none">
2
- @if (!$filter()) {
3
- <ion-icon name="search-outline" slot="start" />
4
- }
5
- <ion-input
6
- [label]="$filter() ? 'Filter:' : ''"
7
- placeholder="Filter"
8
- [value]="$filter()"
9
- (ionInput)="onFilterChanged($event)"
10
- (ionBlur)="onBlured($event)"
11
- />
12
- @if (!!$filter()) {
13
- <ion-buttons slot="end">
14
- <ion-button color="medium" (click)="clearFilter($event)">
15
- <ion-icon name="close-outline" />
16
- </ion-button>
17
- </ion-buttons>
18
- }
19
- </ion-item>
@@ -1,83 +0,0 @@
1
- import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
2
- import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
3
- import { FilterItemComponent } from './filter-item.component';
4
-
5
- describe('FilterItemComponent', () => {
6
- let component: FilterItemComponent;
7
- let fixture: ComponentFixture<FilterItemComponent>;
8
-
9
- beforeEach(waitForAsync(async () => {
10
- await TestBed.configureTestingModule({
11
- imports: [FilterItemComponent],
12
- schemas: [CUSTOM_ELEMENTS_SCHEMA],
13
- })
14
- .overrideComponent(FilterItemComponent, {
15
- set: {
16
- imports: [],
17
- schemas: [CUSTOM_ELEMENTS_SCHEMA],
18
- template: '',
19
- },
20
- })
21
- .compileComponents();
22
- fixture = TestBed.createComponent(FilterItemComponent);
23
- component = fixture.componentInstance;
24
- fixture.componentRef.setInput('$filter', 'test');
25
- }));
26
-
27
- it('should create', () => {
28
- expect(component).toBeTruthy();
29
- });
30
-
31
- it('should emit changed event with empty string when clearFilter is called', () => {
32
- const changedSpy = vi.fn();
33
- component.changed.subscribe(changedSpy);
34
-
35
- const mockEvent = {
36
- stopPropagation: vi.fn(),
37
- preventDefault: vi.fn(),
38
- } as unknown as Event;
39
-
40
- component['clearFilter'](mockEvent);
41
-
42
- expect(mockEvent.stopPropagation).toHaveBeenCalled();
43
- expect(mockEvent.preventDefault).toHaveBeenCalled();
44
- expect(changedSpy).toHaveBeenCalledWith('');
45
- });
46
-
47
- it('should emit changed event when onFilterChanged is called', () => {
48
- const changedSpy = vi.fn();
49
- component.changed.subscribe(changedSpy);
50
-
51
- const mockEvent = {
52
- detail: { value: 'new filter' },
53
- } as CustomEvent;
54
-
55
- component['onFilterChanged'](mockEvent);
56
-
57
- expect(changedSpy).toHaveBeenCalledWith('new filter');
58
- });
59
-
60
- it('should emit empty string when onFilterChanged receives empty detail value', () => {
61
- const changedSpy = vi.fn();
62
- component.changed.subscribe(changedSpy);
63
-
64
- const mockEvent = {
65
- detail: { value: null },
66
- } as CustomEvent;
67
-
68
- component['onFilterChanged'](mockEvent);
69
-
70
- expect(changedSpy).toHaveBeenCalledWith('');
71
- });
72
-
73
- it('should emit blured event when onBlured is called', () => {
74
- const bluredSpy = vi.fn();
75
- component.blured.subscribe(bluredSpy);
76
-
77
- const mockEvent = {} as Event;
78
-
79
- component['onBlured'](mockEvent);
80
-
81
- expect(bluredSpy).toHaveBeenCalledWith(mockEvent);
82
- });
83
- });
@@ -1,47 +0,0 @@
1
- import {
2
- ChangeDetectionStrategy,
3
- Component,
4
- EventEmitter,
5
- input,
6
- Output,
7
- } from '@angular/core';
8
- import {
9
- IonButton,
10
- IonButtons,
11
- IonIcon,
12
- IonInput,
13
- IonItem,
14
- } from '@ionic/angular/standalone';
15
-
16
- @Component({
17
- selector: 'sneat-filter-item',
18
- templateUrl: './filter-item.component.html',
19
- imports: [IonItem, IonIcon, IonInput, IonButtons, IonButton],
20
- changeDetection: ChangeDetectionStrategy.OnPush,
21
- })
22
- export class FilterItemComponent {
23
- public readonly $filter = input.required<string>();
24
-
25
- @Output() readonly changed = new EventEmitter<string>();
26
- @Output() readonly blured = new EventEmitter<Event>();
27
-
28
- protected clearFilter(event: Event): void {
29
- event.stopPropagation();
30
- event.preventDefault();
31
- this.emitChanged('');
32
- }
33
-
34
- protected onFilterChanged(event: CustomEvent): void {
35
- // console.log(`FilterItemComponent.onFilterChanged()`, event);
36
- this.emitChanged(event.detail.value || '');
37
- }
38
-
39
- protected onBlured(event: Event): void {
40
- this.blured.emit(event);
41
- }
42
-
43
- private emitChanged(value: string): void {
44
- // console.log(`FilterItemComponent.emitChange(value=${value})`);
45
- this.changed.emit(value);
46
- }
47
- }
@@ -1,116 +0,0 @@
1
- import { TestBed, fakeAsync, tick } from '@angular/core/testing';
2
- import { CountryFlagPipe, CountryTitle } from './country-emoji.pipe';
3
- import { CountriesLoaderService } from '../country-selector';
4
-
5
- describe('Country pipes', () => {
6
- let countriesLoader: { getCountriesByID: () => Promise<unknown> };
7
- const mockCountries = {
8
- US: { emoji: '🇺🇸', title: 'United States' },
9
- UA: { emoji: '🇺🇦', title: 'Ukraine' },
10
- };
11
-
12
- beforeEach(() => {
13
- countriesLoader = {
14
- getCountriesByID: vi.fn().mockReturnValue(Promise.resolve(mockCountries)),
15
- };
16
-
17
- TestBed.configureTestingModule({
18
- providers: [
19
- CountryFlagPipe,
20
- CountryTitle,
21
- {
22
- provide: CountriesLoaderService,
23
- useValue: countriesLoader,
24
- },
25
- ],
26
- });
27
- });
28
-
29
- describe('CountryFlagPipe', () => {
30
- it('should create', () => {
31
- expect(TestBed.inject(CountryFlagPipe)).toBeTruthy();
32
- });
33
-
34
- it('should return empty string for empty input', () => {
35
- const pipe = TestBed.inject(CountryFlagPipe);
36
- expect(pipe.transform('')).toBe('');
37
- expect(pipe.transform('--')).toBe('');
38
- });
39
-
40
- it('should return countryID when cache is not yet loaded', () => {
41
- const pipe = TestBed.inject(CountryFlagPipe);
42
- expect(pipe.transform('US')).toBe('US');
43
- });
44
-
45
- it('should return emoji when cache is loaded', fakeAsync(() => {
46
- const pipe = TestBed.inject(CountryFlagPipe);
47
- tick(); // resolve promise
48
- expect(pipe.transform('US')).toBe('🇺🇸');
49
- expect(pipe.transform('UA')).toBe('🇺🇦');
50
- }));
51
-
52
- it('should return countryID for unknown country', fakeAsync(() => {
53
- const pipe = TestBed.inject(CountryFlagPipe);
54
- tick();
55
- expect(pipe.transform('XX')).toBe('XX');
56
- }));
57
- });
58
-
59
- describe('CountryTitle', () => {
60
- it('should create', () => {
61
- expect(TestBed.inject(CountryTitle)).toBeTruthy();
62
- });
63
-
64
- it('should return empty string for empty input', () => {
65
- const pipe = TestBed.inject(CountryTitle);
66
- expect(pipe.transform('')).toBe('');
67
- });
68
-
69
- it('should return countryID when cache is not yet loaded', () => {
70
- const pipe = TestBed.inject(CountryTitle);
71
- expect(pipe.transform('US')).toBe('US');
72
- });
73
-
74
- it('should return title when cache is loaded', fakeAsync(() => {
75
- const pipe = TestBed.inject(CountryTitle);
76
- tick();
77
- expect(pipe.transform('US')).toBe('United States');
78
- expect(pipe.transform('UA')).toBe('Ukraine');
79
- }));
80
-
81
- it('should return countryID for unknown country', fakeAsync(() => {
82
- const pipe = TestBed.inject(CountryTitle);
83
- tick();
84
- expect(pipe.transform('XX')).toBe('XX');
85
- }));
86
-
87
- it('should return empty string for undefined input', () => {
88
- const pipe = TestBed.inject(CountryTitle);
89
- expect(pipe.transform(undefined)).toBe('');
90
- });
91
- });
92
-
93
- describe('Error handling', () => {
94
- it('should handle load error gracefully', fakeAsync(() => {
95
- const errorLoader = {
96
- getCountriesByID: vi.fn().mockReturnValue(Promise.reject(new Error('Load failed'))),
97
- };
98
-
99
- TestBed.resetTestingModule();
100
- TestBed.configureTestingModule({
101
- providers: [
102
- CountryFlagPipe,
103
- {
104
- provide: CountriesLoaderService,
105
- useValue: errorLoader,
106
- },
107
- ],
108
- });
109
-
110
- const pipe = TestBed.inject(CountryFlagPipe);
111
- tick();
112
- // After error, should return the countryID itself
113
- expect(pipe.transform('US')).toBe('US');
114
- }));
115
- });
116
- });
@@ -1,67 +0,0 @@
1
- import { inject, Pipe, PipeTransform } from '@angular/core';
2
- import { CountriesLoaderService } from '../country-selector';
3
-
4
- /**
5
- * Base class for country-related pipes that need to cache country data.
6
- */
7
- abstract class CountryDataPipe {
8
- protected readonly countriesLoader = inject(CountriesLoaderService);
9
- protected countriesCache?: Record<string, { emoji: string; title: string }>;
10
- protected isLoading = false;
11
- protected loadError = false;
12
-
13
- constructor() {
14
- // Eagerly load countries data when pipe is created
15
- this.loadCountriesData();
16
- }
17
-
18
- private loadCountriesData(): void {
19
- if (this.isLoading) return;
20
- this.isLoading = true;
21
-
22
- this.countriesLoader
23
- .getCountriesByID()
24
- .then((countries) => {
25
- this.countriesCache = Object.fromEntries(
26
- Object.entries(countries).map(([id, country]) => [
27
- id,
28
- { emoji: country.emoji, title: country.title },
29
- ]),
30
- );
31
- })
32
- .catch((error) => {
33
- console.error('Failed to load countries data for pipe:', error);
34
- this.loadError = true;
35
- // Set empty cache to avoid repeated load attempts
36
- this.countriesCache = {};
37
- })
38
- .finally(() => {
39
- this.isLoading = false;
40
- });
41
- }
42
- }
43
-
44
- export const countryFlagEmoji = (countryID?: string): string =>
45
- countryID && countryID !== '--' ? countryID : '';
46
-
47
- @Pipe({ name: 'countryFlag' })
48
- export class CountryFlagPipe extends CountryDataPipe implements PipeTransform {
49
- transform(countryID?: string): string {
50
- if (!countryID || countryID === '--') {
51
- return '';
52
- }
53
- // Return country emoji from cache if available, otherwise return countryID
54
- return this.countriesCache?.[countryID]?.emoji || countryID;
55
- }
56
- }
57
-
58
- @Pipe({ name: 'countryTitle' })
59
- export class CountryTitle extends CountryDataPipe implements PipeTransform {
60
- transform(countryID?: string): string {
61
- if (!countryID) {
62
- return '';
63
- }
64
- // Return country title from cache if available, otherwise return countryID
65
- return this.countriesCache?.[countryID]?.title || countryID;
66
- }
67
- }
@@ -1,61 +0,0 @@
1
- import { Decimal64p2Pipe, Numeral2Pipe } from './decimal64p2.pipe';
2
-
3
- describe('Decimal64p2Pipe', () => {
4
- let pipe: Decimal64p2Pipe;
5
-
6
- beforeEach(() => {
7
- pipe = new Decimal64p2Pipe();
8
- });
9
-
10
- it('should create', () => {
11
- expect(pipe).toBeTruthy();
12
- });
13
-
14
- it('should divide value by 100', () => {
15
- expect(pipe.transform(100)).toBe(1);
16
- expect(pipe.transform(150)).toBe(1.5);
17
- expect(pipe.transform(50)).toBe(0.5);
18
- });
19
-
20
- it('should return 0 for undefined or null', () => {
21
- expect(pipe.transform(undefined)).toBe(0);
22
- });
23
- });
24
-
25
- describe('Numeral2Pipe', () => {
26
- let pipe: Numeral2Pipe;
27
-
28
- beforeEach(() => {
29
- pipe = new Numeral2Pipe();
30
- });
31
-
32
- it('should create', () => {
33
- expect(pipe).toBeTruthy();
34
- });
35
-
36
- it('should add "st" for numbers ending in 1 (except 11 - currently bugged in code)', () => {
37
- expect(pipe.transform(1)).toBe('1st');
38
- expect(pipe.transform(21)).toBe('21st');
39
- expect(pipe.transform(11)).toBe('11st'); // Verified current buggy behavior
40
- });
41
-
42
- it('should add "nd" for numbers ending in 2', () => {
43
- expect(pipe.transform(2)).toBe('2nd');
44
- expect(pipe.transform(22)).toBe('22nd');
45
- });
46
-
47
- it('should add "d" for numbers ending in 3 (should probably be "rd")', () => {
48
- expect(pipe.transform(3)).toBe('3d');
49
- expect(pipe.transform(23)).toBe('23d');
50
- });
51
-
52
- it('should add "th" for 13', () => {
53
- expect(pipe.transform(13)).toBe('13th');
54
- });
55
-
56
- it('should add "th" for other numbers', () => {
57
- expect(pipe.transform(4)).toBe('4th');
58
- expect(pipe.transform(10)).toBe('10th');
59
- expect(pipe.transform(0)).toBe('0th');
60
- });
61
- });
@@ -1,35 +0,0 @@
1
- import { Pipe, PipeTransform } from '@angular/core';
2
-
3
- @Pipe({ name: 'decimal64p2' })
4
- export class Decimal64p2Pipe implements PipeTransform {
5
- readonly transform = (value?: number) => (value ? value / 100 : 0);
6
- }
7
-
8
- @Pipe({ name: 'numeral' })
9
- export class Numeral2Pipe implements PipeTransform {
10
- readonly transform = (value?: number | string) => {
11
- const s = value?.toString();
12
- if (s?.endsWith('1')) {
13
- return value + 'st';
14
- }
15
- if (
16
- s === '13' ||
17
- s?.endsWith('4') ||
18
- s?.endsWith('5') ||
19
- s?.endsWith('6') ||
20
- s?.endsWith('7') ||
21
- s?.endsWith('8') ||
22
- s?.endsWith('9') ||
23
- s?.endsWith('0')
24
- ) {
25
- return value + 'th';
26
- }
27
- if (s?.endsWith('2')) {
28
- return value + 'nd';
29
- }
30
- if (s?.endsWith('3')) {
31
- return value + 'd';
32
- }
33
- return value;
34
- };
35
- }
@@ -1,84 +0,0 @@
1
- import { Gender } from '@sneat/core';
2
- import {
3
- GenderIconNamePipe,
4
- GenderEmojiPipe,
5
- GenderColorPipe,
6
- } from './gender.pipes';
7
-
8
- describe('GenderIconNamePipe', () => {
9
- let pipe: GenderIconNamePipe;
10
-
11
- beforeEach(() => {
12
- pipe = new GenderIconNamePipe();
13
- });
14
-
15
- it('should create', () => {
16
- expect(pipe).toBeTruthy();
17
- });
18
-
19
- const cases: { gender: Gender | undefined; expected: string }[] = [
20
- { gender: 'male', expected: 'man-outline' },
21
- { gender: 'female', expected: 'woman-outline' },
22
- { gender: 'other', expected: 'person-circle-outline' },
23
- { gender: 'unknown', expected: 'person-outline' },
24
- { gender: 'undisclosed', expected: 'person' },
25
- { gender: undefined, expected: 'person-outline' },
26
- ];
27
-
28
- cases.forEach(({ gender, expected }) => {
29
- it(`should return ${expected} for gender ${gender}`, () => {
30
- expect(pipe.transform(gender)).toBe(expected);
31
- });
32
- });
33
- });
34
-
35
- describe('GenderEmojiPipe', () => {
36
- let pipe: GenderEmojiPipe;
37
-
38
- beforeEach(() => {
39
- pipe = new GenderEmojiPipe();
40
- });
41
-
42
- it('should create', () => {
43
- expect(pipe).toBeTruthy();
44
- });
45
-
46
- const cases: { gender: Gender | undefined; expected: string }[] = [
47
- { gender: 'male', expected: 'man-outline' },
48
- { gender: 'female', expected: 'woman-outline' },
49
- { gender: undefined, expected: 'person-outline' },
50
- ];
51
-
52
- cases.forEach(({ gender, expected }) => {
53
- it(`should return ${expected} for gender ${gender}`, () => {
54
- expect(pipe.transform(gender)).toBe(expected);
55
- });
56
- });
57
- });
58
-
59
- describe('GenderColorPipe', () => {
60
- let pipe: GenderColorPipe;
61
-
62
- beforeEach(() => {
63
- pipe = new GenderColorPipe();
64
- });
65
-
66
- it('should create', () => {
67
- expect(pipe).toBeTruthy();
68
- });
69
-
70
- const cases: { gender: Gender | undefined; expected: string }[] = [
71
- { gender: 'male', expected: 'primary' },
72
- { gender: 'female', expected: 'danger' },
73
- { gender: 'other', expected: 'warning' },
74
- { gender: 'unknown', expected: 'medium' },
75
- { gender: 'undisclosed', expected: 'medium' },
76
- { gender: undefined, expected: 'dark' },
77
- ];
78
-
79
- cases.forEach(({ gender, expected }) => {
80
- it(`should return ${expected} for gender ${gender}`, () => {
81
- expect(pipe.transform(gender)).toBe(expected);
82
- });
83
- });
84
- });
@@ -1,65 +0,0 @@
1
- import { Pipe, PipeTransform } from '@angular/core';
2
- import { Gender } from '@sneat/core';
3
-
4
- @Pipe({ name: 'genderIconName' })
5
- export class GenderIconNamePipe implements PipeTransform {
6
- transform(gender?: Gender): string {
7
- switch (gender) {
8
- case 'male':
9
- return 'man-outline';
10
- case 'female':
11
- return 'woman-outline';
12
- case 'other':
13
- return 'person-circle-outline';
14
- case 'unknown':
15
- return 'person-outline';
16
- case 'undisclosed':
17
- return 'person';
18
- }
19
- return 'person-outline';
20
- }
21
- }
22
-
23
- @Pipe({ name: 'genderEmoji' })
24
- export class GenderEmojiPipe implements PipeTransform {
25
- transform(gender?: Gender): string {
26
- switch (gender) {
27
- case 'male':
28
- return 'man-outline';
29
- case 'female':
30
- return 'woman-outline';
31
- }
32
- return 'person-outline';
33
- }
34
- }
35
-
36
- export type GenderColor =
37
- | 'primary'
38
- | 'secondary'
39
- | 'tertiary'
40
- | 'success'
41
- | 'warning'
42
- | 'danger'
43
- | 'dark'
44
- | 'medium';
45
-
46
- export function genderColor(gender?: Gender): GenderColor {
47
- switch (gender) {
48
- case 'male':
49
- return 'primary';
50
- case 'female':
51
- return 'danger';
52
- case 'other':
53
- return 'warning';
54
- case 'unknown':
55
- return 'medium';
56
- case 'undisclosed':
57
- return 'medium';
58
- }
59
- return 'dark';
60
- }
61
-
62
- @Pipe({ name: 'genderColor' })
63
- export class GenderColorPipe implements PipeTransform {
64
- readonly transform = genderColor;
65
- }
@@ -1,36 +0,0 @@
1
- import { LongMonthNamePipe } from './long-month-name.pipe';
2
-
3
- describe('LongMonthNamePipe', () => {
4
- let pipe: LongMonthNamePipe;
5
-
6
- beforeEach(() => {
7
- pipe = new LongMonthNamePipe();
8
- });
9
-
10
- it('should create', () => {
11
- expect(pipe).toBeTruthy();
12
- });
13
-
14
- const cases = [
15
- { month: 0, expected: 'January' },
16
- { month: 1, expected: 'February' },
17
- { month: 2, expected: 'March' },
18
- { month: 3, expected: 'April' },
19
- { month: 4, expected: 'May' },
20
- { month: 5, expected: 'June' },
21
- { month: 6, expected: 'July' },
22
- { month: 7, expected: 'August' },
23
- { month: 8, expected: 'September' },
24
- { month: 9, expected: 'October' },
25
- { month: 10, expected: 'November' },
26
- { month: 11, expected: 'December' },
27
- { month: 12, expected: '12' },
28
- { month: undefined, expected: 'undefined' },
29
- ];
30
-
31
- cases.forEach(({ month, expected }) => {
32
- it(`should return ${expected} for month ${month}`, () => {
33
- expect(pipe.transform(month)).toBe(expected);
34
- });
35
- });
36
- });
@@ -1,35 +0,0 @@
1
- import { Pipe, PipeTransform } from '@angular/core';
2
-
3
- @Pipe({ name: 'longMonthName' })
4
- export class LongMonthNamePipe implements PipeTransform {
5
- transform(month?: number): string {
6
- switch (month) {
7
- case 0:
8
- return 'January';
9
- case 1:
10
- return 'February';
11
- case 2:
12
- return 'March';
13
- case 3:
14
- return 'April';
15
- case 4:
16
- return 'May';
17
- case 5:
18
- return 'June';
19
- case 6:
20
- return 'July';
21
- case 7:
22
- return 'August';
23
- case 8:
24
- return 'September';
25
- case 9:
26
- return 'October';
27
- case 10:
28
- return 'November';
29
- case 11:
30
- return 'December';
31
- default:
32
- return '' + month;
33
- }
34
- }
35
- }
@@ -1,28 +0,0 @@
1
- import { ShortMonthNamePipe } from './short-month-name.pipe';
2
-
3
- describe('ShortMonthNamePipe', () => {
4
- let pipe: ShortMonthNamePipe;
5
-
6
- beforeEach(() => {
7
- pipe = new ShortMonthNamePipe();
8
- });
9
-
10
- it('should create', () => {
11
- expect(pipe).toBeTruthy();
12
- });
13
-
14
- const cases = [
15
- { month: 0, expected: 'Jan' },
16
- { month: 5, expected: 'Jun' },
17
- { month: 11, expected: 'Dec' },
18
- { month: 12, expected: '12' },
19
- { month: -1, expected: '-1' },
20
- { month: undefined, expected: 'undefined' },
21
- ];
22
-
23
- cases.forEach(({ month, expected }) => {
24
- it(`should return ${expected} for month ${month}`, () => {
25
- expect(pipe.transform(month)).toBe(expected);
26
- });
27
- });
28
- });