PageSourceSearch

https://icc-angkor.org/wp-content/themes/catch-box/Scripts/js/JSLINQ.js?ver=2.2.1

js icc-angkor.org collected 2026-09-25 08:45:01 UTC 6,775 bytes, 187 lines download raw bytes

1//-----------------------------------------------------------------------
2// Part of the LINQ to JavaScript (JSLINQ) v2.10 Project - http://jslinq.codeplex.com
3// Copyright (C) 2009 Chris Pietschmann (http://pietschsoft.com). All rights reserved.
4// This project is licensed under the Microsoft Reciprocal License (Ms-RL)
5// This license can be found here: http://jslinq.codeplex.com/license
6//-----------------------------------------------------------------------
7(function() {
8    JSLINQ = window.JSLINQ = function(dataItems) {
9        return new JSLINQ.fn.init(dataItems);
10    };
11    JSLINQ.fn = JSLINQ.prototype = {
12        init: function(dataItems) {
13            this.items = dataItems;
14        },
15
16        // The current version of JSLINQ being used
17        jslinq: "2.10",
18
19        ToArray: function() { return this.items; },
20        Where: function(clause) {
21            var item;
22            var newArray = new Array();
23
24            // The clause was passed in as a Method that return a Boolean
25            for (var index = 0; index < this.items.length; index++) {
26                if (clause(this.items[index], index)) {
27                    newArray[newArray.length] = this.items[index];
28                }
29            }
30            return new JSLINQ(newArray);
31        },
32        Select: function(clause) {
33            var item;
34            var newArray = new Array();
35
36            // The clause was passed in as a Method that returns a Value
37            for (var i = 0; i < this.items.length; i++) {
38                if (clause(this.items[i])) {
39                    newArray[newArray.length] = clause(this.items[i]);
40                }
41            }
42            return new JSLINQ(newArray);
43        },
44        OrderBy: function(clause) {
45            var tempArray = new Array();
46            for (var i = 0; i < this.items.length; i++) {
47                tempArray[tempArray.length] = this.items[i];
48            }
49            return new JSLINQ(
50            tempArray.sort(function(a, b) {
51                var x = clause(a);
52                var y = clause(b);
53                return ((x < y) ? -1 : ((x > y) ? 1 : 0));
54            })
55        );
56        },
57        OrderByDescending: function(clause) {
58            var tempArray = new Array();
59            for (var i = 0; i < this.items.length; i++) {
60                tempArray[tempArray.length] = this.items[i];
61            }
62            return new JSLINQ(
63            tempArray.sort(function(a, b) {
64                var x = clause(b);
65                var y = clause(a);
66                return ((x < y) ? -1 : ((x > y) ? 1 : 0));
67            })
68        );
69        },
70        SelectMany: function(clause) {
71            var r = new Array();
72            for (var i = 0; i < this.items.length; i++) {
73                r = r.concat(clause(this.items[i]));
74            }
75            return new JSLINQ(r);
76        },
77        Count: function(clause) {
78            if (clause == null)
79                return this.items.length;
80            else
81                return this.Where(clause).items.length;
82        },
83        Distinct: function(clause) {
84            var item;
85            var dict = new Object();
86            var retVal = new Array();
87            for (var i = 0; i < this.items.length; i++) {
88                item = clause(this.items[i]);
89                // TODO - This doens't correctly compare Objects. Need to fix this
90                if (dict[item] == null) {
91                    dict[item] = true;
92                    retVal[retVal.length] = item;
93                }
94            }
95            dict = null;
96            return new JSLINQ(retVal);
97        },
98        Any: function(clause) {
99            for (var index = 0; index < this.items.length; index++) {
100                if (clause(this.items[index], index)) { return true; }
101            }
102            return false;
103        },
104        All: function(clause) {
105            for (var index = 0; index < this.items.length; index++) {
106                if (!clause(this.items[index], index)) { return false; }
107            }
108            return true;
109        },
110        Reverse: function() {
111            var retVal = new Array();
112            for (var index = this.items.length - 1; index > -1; index--)
113                retVal[retVal.length] = this.items[index];
114            return new JSLINQ(retVal);
115        },
116        First: function(clause) {
117            if (clause != null) {
118                return this.Where(clause).First();
119            }
120            else {
121                // If no clause was specified, then return the First element in the Array
122                if (this.items.length > 0)
123                    return this.items[0];
124                else
125                    return null;
126            }
127        },
128        Last: function(clause) {
129            if (clause != null) {
130                return this.Where(clause).Last();
131            }
132            else {
133                // If no clause was specified, then return the First element in the Array
134                if (this.items.length > 0)
135                    return this.items[this.items.length - 1];
136                else
137                    return null;
138            }
139        },
140        ElementAt: function(index) {
141            return this.items[index];
142        },
143        Concat: function(array) {
144            var arr = array.items || array;
145            return new JSLINQ(this.items.concat(arr));
146        },
147        Intersect: function(secondArray, clause) {
148            var clauseMethod;
149            if (clause != undefined) {
150                clauseMethod = clause;
151            } else {
152                clauseMethod = function(item, index, item2, index2) { return item == item2; };
153            }
154
155            var sa = secondArray.items || secondArray;
156
157            var result = new Array();
158            for (var a = 0; a < this.items.length; a++) {
159                for (var b = 0; b < sa.length; b++) {
160                    if (clauseMethod(this.items[a], a, sa[b], b)) {
161                        result[result.length] = this.items[a];
162                    }
163                }
164            }
165            return new JSLINQ(result);
166        },
167        DefaultIfEmpty: function(defaultValue) {
168            if (this.items.length == 0) {
169                return defaultValue;
170            }
171            return this;
172        },
173        ElementAtOrDefault: function(index, defaultValue) {
174            if (index >= 0 && index < this.items.length) {
175                return this.items[index];
176            }
177            return defaultValue;
178        },
179        FirstOrDefault: function(defaultValue) {
180            return this.First() || defaultValue;
181        },
182        LastOrDefault: function(defaultValue) {
183            return this.Last() || defaultValue;
184        }
185    };
186    JSLINQ.fn.init.prototype = JSLINQ.fn;
187})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.