Skip to content

Commit 09abf71

Browse files
committed
Docs: improve internal documentation
1 parent e44c202 commit 09abf71

File tree

6 files changed

+82
-3
lines changed

6 files changed

+82
-3
lines changed

src/services/collator.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,23 @@ export interface ICollator {
100100

101101
}
102102

103+
/**
104+
* Intl.Collator APIs.
105+
*/
103106
@Injectable() export class Collator implements ICollator {
104107

105108
constructor(private locale: LocaleService, private translation: TranslationService) { }
106109

110+
/**
111+
* Compares two keys by the value of translation according to the current language.
112+
* @param key1, key2 The keys of the values to compare
113+
* @param extension Unicode extension key, e.g. 'co-phonebk'
114+
* @param options Default is { usage: 'sort', sensitivity: 'variant' }
115+
* @return A negative value if the value of translation of key1 comes before the value of translation of key2;
116+
* a positive value if key1 comes after key2;
117+
* 0 if they are considered equal or Intl.Collator is not supported
118+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator
119+
*/
107120
public compare(
108121
key1: string,
109122
key2: string,
@@ -124,6 +137,16 @@ export interface ICollator {
124137
return new Intl.Collator(locale, options).compare(value1, value2);
125138
}
126139

140+
/**
141+
* Sorts an array of objects or an array of arrays according to the current language.
142+
* @param list The array to be sorted
143+
* @param keyName The column that contains the keys of the values to be ordered
144+
* @param order 'asc' or 'desc'. The default value is 'asc'
145+
* @param extension Unicode extension key, e.g. 'co-phonebk'
146+
* @param options Default is { usage: 'sort', sensitivity: 'variant' }
147+
* @return The same sorted list or the same list if Intl.Collator is not supported
148+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator
149+
*/
127150
public sort(
128151
list: any[],
129152
keyName: any,
@@ -145,6 +168,16 @@ export interface ICollator {
145168
return list;
146169
}
147170

171+
/**
172+
* Sorts asynchronously an array of objects or an array of arrays according to the current language.
173+
* @param list The array to be sorted
174+
* @param keyName The column that contains the keys of the values to be ordered
175+
* @param order 'asc' or 'desc'. The default value is 'asc'
176+
* @param extension Unicode extension key, e.g. 'co-phonebk'
177+
* @param options Default is { usage: 'sort', sensitivity: 'variant' }
178+
* @return An observable of the sorted list or of the same list if Intl.Collator is not supported
179+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator
180+
*/
148181
public sortAsync(
149182
list: any[],
150183
keyName: any,
@@ -158,6 +191,16 @@ export interface ICollator {
158191
});
159192
}
160193

194+
/**
195+
* Matches a string into an array of objects or an array of arrays
196+
* according to the current language.
197+
* @param s The string to search
198+
* @param list The array in which to search
199+
* @param keyNames An array that contains the columns to look for
200+
* @param options Default is { usage: 'search' }
201+
* @return A filtered list or the same list if Intl.Collator is not supported
202+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator
203+
*/
161204
public search(
162205
s: string,
163206
list: any[],
@@ -184,6 +227,16 @@ export interface ICollator {
184227
return matches;
185228
}
186229

230+
/**
231+
* Matches asynchronously a string into an array of objects or an array of arrays
232+
* according to the current language.
233+
* @param s The string to search
234+
* @param list The array in which to search
235+
* @param keyNames An array that contains the columns to look for
236+
* @param options Default is { usage: 'search' }
237+
* @return An observable of the filtered list or the same list if Intl.Collator is not supported
238+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator
239+
*/
187240
public searchAsync(
188241
s: string,
189242
list: any[],

src/services/l10n-loader.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import { TranslationService } from '../services/translation.service';
1616
private translation: TranslationService
1717
) { }
1818

19+
/**
20+
* Loads l10n services.
21+
*/
1922
public async load(): Promise<void> {
2023
// LocaleService initialization.
2124
if (Object.keys(this.localeConfig).length > 0) {

src/services/locale-storage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ import { LOCALE_CONFIG, LocaleConfig } from '../models/l10n-config';
44
import { StorageStrategy } from '../models/types';
55

66
/**
7-
* Implement this class-interface to create a custom storage for default locale & currency.
7+
* Implement this class-interface to create a custom storage for default locale, currency & timezone.
88
*/
99
@Injectable() export abstract class LocaleStorage {
1010

1111
/**
1212
* This method must contain the logic to read the storage.
13-
* @param name 'defaultLocale' or 'currency'
13+
* @param name 'defaultLocale', 'currency' or 'timezone'
1414
* @return A promise with the value of the given name
1515
*/
1616
public abstract async read(name: string): Promise<string | null>;
1717

1818
/**
1919
* This method must contain the logic to write the storage.
20-
* @param name 'defaultLocale' or 'currency'
20+
* @param name 'defaultLocale', 'currency' or 'timezone'
2121
* @param value The value for the given name
2222
*/
2323
public abstract async write(name: string, value: string): Promise<void>;

src/services/locale-validation.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@ export interface ILocaleValidation {
1515

1616
}
1717

18+
/**
19+
* Provides the methods to convert strings according to default locale.
20+
*/
1821
@Injectable() export class LocaleValidation implements ILocaleValidation {
1922

2023
constructor(private decimalCode: DecimalCode) { }
2124

25+
/**
26+
* Converts a string to a number according to default locale.
27+
* If the string cannot be converted to a number, returns NaN.
28+
*/
2229
public parseNumber(s: string): number | null {
2330
if (s == "") {
2431
return null;

src/services/locale.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ export interface ILocaleService {
6969

7070
}
7171

72+
/**
73+
* Manages language, default locale, currency & timezone.
74+
*/
7275
@Injectable() export class LocaleService implements ILocaleService {
7376

7477
@Output() public languageCodeChanged: EventEmitter<string> = new EventEmitter<string>(true);

src/services/translation.service.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ export interface ITranslationService {
4343

4444
}
4545

46+
/**
47+
* Manages the translation data.
48+
*/
4649
@Injectable() export class TranslationService implements ITranslationService {
4750

4851
public translationError: Subject<any> = new Subject();
@@ -92,10 +95,20 @@ export interface ITranslationService {
9295
await this.loadTranslation();
9396
}
9497

98+
/**
99+
* Fired when the translation data has been loaded. Returns the translation language.
100+
*/
95101
public translationChanged(): Observable<string> {
96102
return this.translation.asObservable();
97103
}
98104

105+
/**
106+
* Translates a key or an array of keys.
107+
* @param keys The key or an array of keys to be translated
108+
* @param args Optional parameters contained in the key
109+
* @param lang The current language of the service is used by default
110+
* @return The translated value or an object: {key: value}
111+
*/
99112
public translate(
100113
keys: string | string[],
101114
args: any = null,

0 commit comments

Comments
 (0)