@@ -273,6 +273,13 @@ class ParseQuery {
273
273
return this ;
274
274
}
275
275
276
+ /**
277
+ * Converts string for regular expression at the beginning
278
+ */
279
+ _regexStartWith ( string : string ) : String {
280
+ return '^ ' + quote(string);
281
+ }
282
+
276
283
/**
277
284
* Returns a JSON representation of this query.
278
285
* @return {Object } The JSON representation of the query.
@@ -864,6 +871,27 @@ class ParseQuery {
864
871
return this . _addCondition ( key , '$all' , values ) ;
865
872
}
866
873
874
+ /**
875
+ * Adds a constraint to the query that requires a particular key's value to
876
+ * contain each one of the provided list of values starting with given strings.
877
+ * @method containsAllStartingWith
878
+ * @param {String } key The key to check. This key's value must be an array.
879
+ * @param {Array<String> } values The string values that will match as starting string.
880
+ * @return {Parse.Query } Returns the query, so you can chain this call.
881
+ */
882
+ containsAllStartingWith ( key : string , values : Array < string > ) : ParseQuery {
883
+ var _this = this ;
884
+ if ( ! Array . isArray ( values ) ) {
885
+ values = [ values ] ;
886
+ }
887
+
888
+ values = values . map ( function ( value ) {
889
+ return { "$regex" : _this . _regexStartWith ( value ) } ;
890
+ } ) ;
891
+
892
+ return this . containsAll ( key , values ) ;
893
+ }
894
+
867
895
/**
868
896
* Adds a constraint for finding objects that contain the given key.
869
897
* @param {String } key The key that should exist.
@@ -1033,7 +1061,7 @@ class ParseQuery {
1033
1061
if ( typeof value !== 'string' ) {
1034
1062
throw new Error ( 'The value being searched for must be a string.' ) ;
1035
1063
}
1036
- return this . _addCondition ( key , '$regex' , '^' + quote ( value ) ) ;
1064
+ return this . _addCondition ( key , '$regex' , this . _regexStartWith ( value ) ) ;
1037
1065
}
1038
1066
1039
1067
/**
0 commit comments