@@ -100,10 +100,23 @@ export interface ICollator {
100
100
101
101
}
102
102
103
+ /**
104
+ * Intl.Collator APIs.
105
+ */
103
106
@Injectable ( ) export class Collator implements ICollator {
104
107
105
108
constructor ( private locale : LocaleService , private translation : TranslationService ) { }
106
109
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
+ */
107
120
public compare (
108
121
key1 : string ,
109
122
key2 : string ,
@@ -124,6 +137,16 @@ export interface ICollator {
124
137
return new Intl . Collator ( locale , options ) . compare ( value1 , value2 ) ;
125
138
}
126
139
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
+ */
127
150
public sort (
128
151
list : any [ ] ,
129
152
keyName : any ,
@@ -145,6 +168,16 @@ export interface ICollator {
145
168
return list ;
146
169
}
147
170
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
+ */
148
181
public sortAsync (
149
182
list : any [ ] ,
150
183
keyName : any ,
@@ -158,6 +191,16 @@ export interface ICollator {
158
191
} ) ;
159
192
}
160
193
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
+ */
161
204
public search (
162
205
s : string ,
163
206
list : any [ ] ,
@@ -184,6 +227,16 @@ export interface ICollator {
184
227
return matches ;
185
228
}
186
229
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
+ */
187
240
public searchAsync (
188
241
s : string ,
189
242
list : any [ ] ,
0 commit comments