-
Notifications
You must be signed in to change notification settings - Fork 59
/
jlinq.js
1333 lines (1075 loc) · 54.9 KB
/
jlinq.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* jLinq - 3.0.1
* Hugo Bonacci - hugoware.com
* http://creativecommons.org/licenses/by/3.0/
*/
var jLinq;
var jlinq;
var jl;
(function() {
//jLinq functionality
var framework = {
//command types for extensions
command:{
//queues a comparison to filter records
query:0,
//executes all queued commands and filters the records
select:1,
//performs an immediate action to the query
action:2
},
//common expressions
exp:{
//gets each part of a dot notation path
get_path:/\./g,
//escapes string so it can be used in a regular expression
escape_regex:/[\-\[\]\{\}\(\)\*\+\?\.\,\\\^\$\|\#\s]/g
},
//common javascript types
type:{
nothing:-1,
undefined:0,
string:1,
number:2,
array:3,
regex:4,
bool:5,
method:6,
datetime:7,
object:99
},
//contains jLinq commands and functions
library:{
//the current commands in jLinq
commands:{},
//the type comparisons for jLinq
types:{},
//includes a comparison to identify types
addType:function(type, compare) {
framework.library.types[type] = compare;
},
//adds a command to the jLinq library
extend:function(commands) {
//convert to an array if not already
if (!framework.util.isType(framework.type.array, commands)) {
commands = [commands];
}
//append each method
framework.util.each(commands, function(command) {
framework.library.commands[command.name] = command;
});
},
//starts a new jLinq query
query:function(collection, params) {
//make sure something is there
if (!framework.util.isType(framework.type.array, collection)) {
throw "jLinq can only query arrays of objects.";
}
//clone the array to prevent changing objects - by default
//this is off
collection = params.clone || (params.clone == null && jLinq.alwaysClone)
? framework.util.clone(collection)
: collection;
//holds the state of the current query
var self = {
//the public instance of the query
instance:{
//should this query ignore case
ignoreCase:jLinq.ignoreCase,
//should the next command be evaluated as not
not:false,
//the action that was last invoked
lastCommand:null,
//the name of the last field queried
lastField:null,
//the current records available
records:collection,
//records that have been filtered out
removed:[],
//tells a query to start a new function
or:function() { self.startNewCommandSet(); },
//the query creator object
query:{}
},
//determines if the arguments provided meet the
//requirements to be a repeated command
canRepeatCommand:function(args) {
return self.instance.lastCommand != null &&
args.length == (self.instance.lastCommand.method.length + 1) &&
framework.util.isType(framework.type.string, args[0])
},
//commands waiting to execute
commands:[[]],
//executes the current query and updated the records
execute:function() {
var results = [];
//get the current state of the query
var state = self.instance;
//start checking each record
framework.util.each(self.instance.records, function(record) {
//update the state
state.record = record;
//perform the evaluation
if (self.evaluate(state)) {
results.push(record);
}
else {
self.instance.removed.push(record);
}
});
//update the matching records
self.instance.records = results;
},
//tries to find a value from the path name
findValue:framework.util.findValue,
//evaluates each queued command for matched
evaluate:function(state) {
//check each of the command sets
for (var command = 0, l = self.commands.length; command < l; command++) {
//each set represents an 'or' set - if any
//match then return this worked
var set = self.commands[command];
if (self.evaluateSet(set, state)) { return true; }
};
//since nothing evaluated, return it failed
return false;
},
//evaluates a single set of commands
evaluateSet:function(set, state) {
//check each command in this set
for (var item in set) {
if (!set.hasOwnProperty(item)) continue;
//get the details to use
var command = set[item];
state.value = self.findValue(state.record, command.path);
state.compare = function(types) { return framework.util.compare(state.value, types, state); };
state.when = function(types) { return framework.util.when(state.value, types, state); };
//evaluate the command
try {
var result = command.method.apply(state, command.args);
if (command.not) { result = !result; }
if (!result) { return false; }
}
//errors and exceptions just result in a failed
//to evaluate as true
catch (e) {
return false;
}
}
//if nothing failed then return it worked
return true;
},
//repeats the previous command with new
//arguments
repeat:function(arguments) {
//check if there is anything to repeat
if (!self.instance.lastCommand || arguments == null) { return; }
//get the array of arguments to work with
arguments = framework.util.toArray(arguments);
//check if there is a field name has changed, and
//if so, update the arguments to match
if (self.canRepeatCommand(arguments)) {
self.instance.lastField = arguments[0];
arguments = framework.util.select(arguments, null, 1, null);
}
//invoke the command now
self.queue(self.instance.lastCommand, arguments);
},
//saves a command to evaluate later
queue:function(command, args) {
self.instance.lastCommand = command;
//the base detail for the command
var detail = {
name:command.name,
method:command.method,
field:self.instance.lastField,
count:command.method.length,
args:args,
not:self.not
};
//check to see if there is an extra argument which should
//be the field name argument
if (detail.args.length > command.method.length) {
//if so, grab the name and update the arguments
detail.field = detail.args[0];
detail.args = framework.util.remaining(detail.args, 1);
self.instance.lastField = detail.field;
}
//get the full path for the field name
detail.path = detail.field;
//queue the command to the current set
self.commands[self.commands.length-1].push(detail);
//then reset the not state
self.not = false;
},
//creates a new set of methods that should be evaluated
startNewCommandSet:function() {
self.commands.push([]);
},
//marks a command to evaluate as NOT
setNot:function() {
self.not = !self.not;
}
};
//append each of the functions
framework.util.each(framework.library.commands, function(command) {
//Query methods queue up and are not evaluated until
//a selection or action command is called
if (command.type == framework.command.query) {
//the default action to perform
var action = function() {
self.queue(command, arguments);
return self.instance.query;
};
//create the default action
self.instance.query[command.name] = action;
//orCommand
var name = framework.util.operatorName(command.name);
self.instance.query["or"+name] = function() {
self.startNewCommandSet();
return action.apply(null, arguments);
};
//orNotCommand
self.instance.query["orNot"+name] = function() {
self.startNewCommandSet();
self.setNot();
return action.apply(null, arguments);
};
//andCommand
self.instance.query["and"+name] = function() {
return action.apply(null, arguments);
};
//andNotCommand
self.instance.query["andNot"+name] = function() {
self.setNot();
return action.apply(null, arguments);
};
//notCommand
self.instance.query["not"+name] = function() {
self.setNot();
return action.apply(null, arguments);
};
}
//Selections commands flush the queue of commands
//before they are executed. A selection command
//must return something (even if it is the current query)
else if (command.type == framework.command.select) {
self.instance.query[command.name] = function() {
//apply the current changes
self.execute();
//get the current state of the query
var state = self.instance;
state.compare = function(value, types) { return framework.util.compare(value, types, state); };
state.when = function(value, types) { return framework.util.when(value, types, state); };
//perform the work
return command.method.apply(state, arguments);
};
}
//actions evaluate immediately then return control to
//the query
else if (command.type == framework.command.action) {
self.instance.query[command.name] = function() {
//get the current state of the query
var state = self.instance;
state.compare = function(value, types) { return framework.util.compare(value, types, state); };
state.when = function(value, types) { return framework.util.when(value, types, state); };
//perform the work
command.method.apply(state, arguments);
return self.instance.query;
};
}
});
//causes the next command to be an 'or'
self.instance.query.or = function() {
self.startNewCommandSet();
self.repeat(arguments);
return self.instance.query;
};
//causes the next command to be an 'and' (which is default)
self.instance.query.and = function() {
self.repeat(arguments);
return self.instance.query;
};
//causes the next command to be a 'not'
self.instance.query.not = function() {
self.setNot();
self.repeat(arguments);
return self.instance.query;
};
//causes the next command to be a 'not'
self.instance.query.andNot = function() {
self.setNot();
self.repeat(arguments);
return self.instance.query;
};
//causes the next command to be a 'not' and 'or'
self.instance.query.orNot = function() {
self.startNewCommandSet();
self.setNot();
self.repeat(arguments);
return self.instance.query;
};
//return the query information
return self.instance.query;
}
},
//variety of helper methods
util:{
//removes trailing and leading spaces from a value
trim:function(value) {
//get the string value
value = value == null ? "" : value;
value = value.toString();
//trim the spaces
return value.replace(/^\s*|\s*$/g, "");
},
//clones each item in an array
cloneArray:function(array) {
var result = [];
framework.util.each(array, function(item) {
result.push(framework.util.clone(item));
});
return result;
},
//creates a copy of an object
clone:function(obj) {
//for arrays, copy each item
if (framework.util.isType(framework.type.array, obj)) {
return framework.util.cloneArray(obj);
}
//for object check each value
else if (framework.util.isType(framework.type.object, obj)) {
var clone = {};
for(var item in obj) {
if (obj.hasOwnProperty(item)) clone[item] = framework.util.clone(obj[item]);
}
return clone;
}
//all other types just return the value
else {
return obj;
}
},
//creates an invocation handler for a field
//name instead of grabbing values
invoke:function(obj, args) {
//copy the array to avoid breaking any other calls
args = args.concat();
//start by getting the path
var path = args[0];
//find the method and extract the arguments
var method = framework.util.findValue(obj, path);
args = framework.util.select(args, null, 1, null);
//if we are invoking a method that hangs off
//another object then we need to find the value
path = path.replace(/\..*$/, "");
var parent = framework.util.findValue(obj, path);
obj = parent === method ? obj : parent;
//return the result of the call
try {
var result = method.apply(obj, args);
return result;
}
catch (e) {
return null;
}
},
//gets a path from a field name
getPath:function(path) {
return framework.util.toString(path).split(framework.exp.get_path);
},
//searches an object to find a value
findValue:function(obj, path) {
//start by checking if this is actualy an attempt to
//invoke a value on this property
if (framework.util.isType(framework.type.array, path)) {
return framework.util.invoke(obj, path);
}
//if this referring to a field
else if (framework.util.isType(framework.type.string, path)) {
//get each part of the path
path = framework.util.getPath(path);
//search for the record
var index = 0;
while(obj != null && index < path.length) {
obj = obj[path[index++]];
}
//return the final found object
return obj;
}
//nothing that can be read, just return the value
else {
return obj;
}
},
//returns the value at the provided index
elementAt:function(collection, index) {
return collection && collection.length > 0 && index < collection.length && index >= 0
? collection[index]
: null;
},
//makes a string save for regular expression searching
regexEscape:function(val) {
return (val ? val : "").toString().replace(framework.exp.escape_regex, "\\$&");
},
//matches expressions to a value
regexMatch:function(expression, source, ignoreCase) {
//get the string value if needed
if (framework.util.isType(framework.type.regex, expression)) {
expression = expression.source;
}
//create the actual expression and match
expression = new RegExp(framework.util.toString(expression), ignoreCase ? "gi" : "g");
return framework.util.toString(source).match(expression) != null;
},
//converts a command to an operator name
operatorName:function(name) {
return name.replace(/^\w/, function(match) { return match.toUpperCase(); });
},
//changes a value based on the type
compare:function(value, types, state) {
var result = framework.util.when(value, types, state);
return result == true ? result : false;
},
//performs the correct action depending on the type
when:function(value, types, state) {
//get the kind of object this is
var kind = framework.util.getType(value);
//check each of the types
for (var item in types) {
if (!types.hasOwnProperty(item)) continue;
var type = framework.type[item];
if (type == kind) {
return types[item].apply(state, [value]);
}
}
//if there is a fallback comparison
if (types.other) { return types.other.apply(state, [value]); }
//no matches were found
return null;
},
//performs an action on each item in a collection
each:function(collection, action) {
var index = 0;
for(var item in collection){
if (collection.hasOwnProperty(item)) action(collection[item], index++);
}
},
//performs an action to each item in a collection and then returns the items
grab:function(collection, action) {
var list = [];
framework.util.each(collection, function(item) {
list.push(action(item));
});
return list;
},
//performs an action on each item in a collection
until:function(collection, action) {
for(var item = 0, l = collection.length; item < l; item++) {
var result = action(collection[item], item + 1);
if (result === true) { return true; }
}
return false;
},
//checks if the types match
isType:function(type, value) {
return framework.util.getType(value) == type;
},
//finds the type for an object
getType:function(obj) {
//check if this even has a value
if (obj == null) { return framework.type.nothing; }
//check each type except object
for (var item in framework.library.types) {
if (framework.library.types[item](obj)) { return item; }
}
//no matching type was found
return framework.type.object;
},
//grabs remaining elements from and array
remaining:function(array, at) {
var results = [];
for(; at < array.length; at++) results.push(array[at]);
return results;
},
//append items onto a target object
apply:function(target, source) {
for(var item in source) {
if (source.hasOwnProperty(item)) target[item] = source[item];
}
return target;
},
//performs sorting on a collection of records
reorder:function(collection, fields, ignoreCase) {
//reverses the fields so that they are organized
//in the correct order
return framework.util._performSort(collection, fields, ignoreCase);
},
//handles actual work of reordering (call reorder)
_performSort:function(collection, fields, ignoreCase) {
//get the next field to use
var field = fields.splice(0, 1);
if (field.length == 0) { return collection; }
field = field[0];
//get the name of the field and descending or not
var invoked = framework.util.isType(framework.type.array, field);
var name = (invoked ? field[0] : field);
var desc = name.match(/^\-/);
name = desc ? name.substr(1) : name;
//updat the name if needed
if (desc) {
if (invoked) { field[0] = name; } else { field = name; }
}
//IE sorting bug resolved (Thanks @rizil)
//http://webcache.googleusercontent.com/search?q=cache:www.zachleat.com/web/2010/02/24/array-sort/+zach+array+sort
//create the sorting method for this field
var sort = function(val1, val2) {
//find the values to compare
var a = framework.util.findValue(val1, field);
var b = framework.util.findValue(val2, field);
//default to something when null
if (a == null && b == null) { a = 0; b = 0; }
else if (a == null && b != null) { a = 0; b = 1; }
else if (a != null && b == null) { a = 1; b = 0; }
//check for string values
else if (ignoreCase &&
framework.util.isType(framework.type.string, a) &&
framework.util.isType(framework.type.string, b)) {
a = a.toLowerCase();
b = b.toLowerCase();
}
//if there is a length attribute use it instead
else if (a.length && b.length) {
a = a.length;
b = b.length;
}
//perform the sorting
var result = (a < b) ? -1 : (a > b) ? 1 : 0;
return desc ? -result : result;
};
//then perform the sorting
collection.sort(sort);
//check for sub groups if required
if (fields.length > 0) {
//create the container for the results
var sorted = [];
var groups = framework.util.group(collection, field, ignoreCase);
framework.util.each(groups, function(group) {
var listing = fields.slice();
var records = framework.util._performSort(group, listing, ignoreCase);
sorted = sorted.concat(records);
});
//update the main collection
collection = sorted;
}
//the final results
return collection;
},
//returns groups of unique field values
group:function(records, field, ignoreCase) {
//create a container to track group names
var groups = {};
for(var item = 0, l = records.length; item < l; item++) {
//get the values
var record = records[item];
var alias = framework.util.toString(framework.util.findValue(record, field));
alias = ignoreCase ? alias.toUpperCase() : alias;
//check for existing values
if (!groups[alias]) {
groups[alias] = [record];
}
else {
groups[alias].push(record);
}
}
//return the matches
return groups;
},
//compares two values for equality
equals:function(val1, val2, ignoreCase) {
return framework.util.when(val1, {
string:function() {
return framework.util.regexMatch(
"^"+framework.util.regexEscape(val2)+"$",
val1,
ignoreCase);
},
other:function() { return (val1 == null && val2 == null) || (val1 === val2); }
});
},
//converts an object to an array of elements
toArray:function(obj) {
var items = [];
if (obj.length) {
for (var i = 0; i < obj.length; i++) { items.push(obj[i]); }
}
else {
for (var item in obj) {
if (obj.hasOwnProperty(item)) items.push(obj[item]);
}
}
return items;
},
//converts a value into a string
toString:function(val) {
return val == null ? "" : val.toString();
},
//grabs a range of records from a collection
skipTake:function(collection, action, skip, take) {
//set the defaults
skip = skip == null ? 0 : skip;
take = take == null ? collection.length : take;
//check if this will return any records
if (skip >= collection.length ||
take == 0) {
return [];
}
//return the results
return framework.util.select(collection, action, skip, skip + take);
},
//grabs a range and format for records
select:function(collection, action, start, end) {
//grab the records if there is a range
start = start == null ? 0 : start;
end = end == null ? collection.length : end;
//slice the records
var results = collection.slice(start, end);
//check if this is a mapping method
if (jLinq.util.isType(jLinq.type.object, action)) {
var map = action;
action = function(rec) {
//map existing values or defaults
// TODO: tests do not cover this method!
var create = {};
for (var item in map) {
if (!map.hasOwnProperty(item)) continue;
create[item] = rec[item]
? rec[item]
: map[item];
}
//return the created record
return create;
};
};
//if there is a selection method, use it
if (jLinq.util.isType(jLinq.type.method, action)) {
for (var i = 0; i < results.length; i++) {
var record = results[i];
results[i] = action.apply(record, [record]);
}
}
//return the final set of records
return results;
}
}
};
//default types
framework.library.addType(framework.type.nothing, function(value) { return value == null; });
framework.library.addType(framework.type.array, function(value) { return value instanceof Array; });
framework.library.addType(framework.type.string, function(value) { return value.substr && value.toLowerCase; });
framework.library.addType(framework.type.number, function(value) { return value.toFixed && value.toExponential; });
framework.library.addType(framework.type.regex, function(value) { return value instanceof RegExp; });
framework.library.addType(framework.type.bool, function(value) { return value == true || value == false; });
framework.library.addType(framework.type.method, function(value) { return value instanceof Function; });
framework.library.addType(framework.type.datetime, function(value) { return value instanceof Date; });
//add the default methods
framework.library.extend([
//sets a query to ignore case
{ name:"ignoreCase", type:framework.command.action,
method:function() {
this.ignoreCase = true;
}},
//reverses the current set of records
{ name:"reverse", type:framework.command.action,
method:function() {
this.records.reverse();
}},
//sets a query to evaluate case
{ name:"useCase", type:framework.command.action,
method:function() {
this.ignoreCase = false;
}},
//performs an action for each record
{ name:"each", type:framework.command.action,
method:function(action) {
jLinq.util.each(this.records, function(record) { action(record); });
}},
//attaches a value or result of a method to each record
{ name:"attach", type:framework.command.action,
method:function(field, action) {
this.when(action, {
method:function() { jLinq.util.each(this.records, function(record) { record[field] = action(record); }); },
other:function() { jLinq.util.each(this.records, function(record) { record[field] = action; }); }
});
}},
//joins two sets of records by the key information provided
{ name:"join", type:framework.command.action,
method:function(source, alias, pk, fk) {
jLinq.util.each(this.records, function(record) {
record[alias] = jLinq.from(source).equals(fk, record[pk]).select();
});
}},
//joins a second array but uses only the first matched record. Allows for a default for a fallback value
{ name:"assign", type:framework.command.action,
method:function(source, alias, pk, fk, fallback) {
jLinq.util.each(this.records, function(record) {
record[alias] = jLinq.from(source).equals(fk, record[pk]).first(fallback);
});
}},
//joins two sets of records by the key information provided
{ name:"sort", type:framework.command.action,
method:function() {
var args = jLinq.util.toArray(arguments);
this.records = jLinq.util.reorder(this.records, args, this.ignoreCase);
}},
//are the two values the same
{ name:"equals", type:framework.command.query,
method:function(value) {
return jLinq.util.equals(this.value, value, this.ignoreCase);
}},
//does this start with a value
{ name:"starts", type:framework.command.query,
method:function(value) {
return this.compare({
array:function() { return jLinq.util.equals(this.value[0], value, this.ignoreCase); },
other:function() { return jLinq.util.regexMatch(("^"+jLinq.util.regexEscape(value)), this.value, this.ignoreCase); }
});
}},
//does this start with a value
{ name:"ends", type:framework.command.query,
method:function(value) {
return this.compare({
array:function() { return jLinq.util.equals(this.value[this.value.length - 1], value, this.ignoreCase); },
other:function() { return jLinq.util.regexMatch((jLinq.util.regexEscape(value)+"$"), this.value, this.ignoreCase); }
});
}},
//does this start with a value
{ name:"contains", type:framework.command.query,
method:function(value) {
return this.compare({
array:function() {
var ignoreCase = this.ignoreCase;
return jLinq.util.until(this.value, function(item) { return jLinq.util.equals(item, value, ignoreCase); });
},
other:function() { return jLinq.util.regexMatch(jLinq.util.regexEscape(value), this.value, this.ignoreCase); }
});
}},
//does this start with a value
{ name:"match", type:framework.command.query,
method:function(value) {
return this.compare({
array:function() {
var ignoreCase = this.ignoreCase;
return jLinq.util.until(this.value, function(item) { return jLinq.util.regexMatch(value, item, ignoreCase); });
},
other:function() { return jLinq.util.regexMatch(value, this.value, this.ignoreCase); }
});
}},
//checks if the value matches the type provided
{ name:"type", type:framework.command.query,
method:function(type) {
return jLinq.util.isType(type, this.value);
}},
//is the value greater than the argument
{ name:"greater", type:framework.command.query,
method:function(value) {
return this.compare({
array:function() { return this.value.length > value; },
string:function() { return this.value.length > value; },
other:function() { return this.value > value; }
});
}},
//is the value greater than or equal to the argument
{ name:"greaterEquals", type:framework.command.query,
method:function(value) {
return this.compare({
array:function() { return this.value.length >= value; },
string:function() { return this.value.length >= value; },
other:function() { return this.value >= value; }
});
}},
//is the value less than the argument
{ name:"less", type:framework.command.query,
method:function(value) {
return this.compare({
array:function() { return this.value.length < value; },
string:function() { return this.value.length < value; },
other:function() { return this.value < value; }
});
}},