Permalink
Browse files

wow, why does microsoft try so hard to make the docs impossible to wo…

…rk with, cleaning up docs
  • Loading branch information...
1 parent 6f4748d commit d2e7b554b68326b370fc44167b46ca10441497e1 @Marak committed May 4, 2010
Showing with 1,434 additions and 0 deletions.
  1. +187 −0 CommonJS/LINQ.js
  2. +70 −0 index.html
  3. +111 −0 javascript/JSLINQ-vsdoc.js
  4. +187 −0 javascript/LINQ.js
  5. +858 −0 javascript/data.js
  6. +21 −0 tests.html
View
@@ -0,0 +1,187 @@
+//-----------------------------------------------------------------------
+// Part of the LINQ to JavaScript (JSLINQ) v2.10 Project - http://jslinq.codeplex.com
+// Copyright (C) 2009 Chris Pietschmann (http://pietschsoft.com). All rights reserved.
+// This project is licensed under the Microsoft Reciprocal License (Ms-RL)
+// This license can be found here: http://jslinq.codeplex.com/license
+//-----------------------------------------------------------------------
+(function() {
+ JSLINQ = window.JSLINQ = function(dataItems) {
+ return new JSLINQ.fn.init(dataItems);
+ };
+ JSLINQ.fn = JSLINQ.prototype = {
+ init: function(dataItems) {
+ this.items = dataItems;
+ },
+
+ // The current version of JSLINQ being used
+ jslinq: "2.10",
+
+ ToArray: function() { return this.items; },
+ Where: function(clause) {
+ var item;
+ var newArray = new Array();
+
+ // The clause was passed in as a Method that return a Boolean
+ for (var index = 0; index < this.items.length; index++) {
+ if (clause(this.items[index], index)) {
+ newArray[newArray.length] = this.items[index];
+ }
+ }
+ return new JSLINQ(newArray);
+ },
+ Select: function(clause) {
+ var item;
+ var newArray = new Array();
+
+ // The clause was passed in as a Method that returns a Value
+ for (var i = 0; i < this.items.length; i++) {
+ if (clause(this.items[i])) {
+ newArray[newArray.length] = clause(this.items[i]);
+ }
+ }
+ return new JSLINQ(newArray);
+ },
+ OrderBy: function(clause) {
+ var tempArray = new Array();
+ for (var i = 0; i < this.items.length; i++) {
+ tempArray[tempArray.length] = this.items[i];
+ }
+ return new JSLINQ(
+ tempArray.sort(function(a, b) {
+ var x = clause(a);
+ var y = clause(b);
+ return ((x < y) ? -1 : ((x > y) ? 1 : 0));
+ })
+ );
+ },
+ OrderByDescending: function(clause) {
+ var tempArray = new Array();
+ for (var i = 0; i < this.items.length; i++) {
+ tempArray[tempArray.length] = this.items[i];
+ }
+ return new JSLINQ(
+ tempArray.sort(function(a, b) {
+ var x = clause(b);
+ var y = clause(a);
+ return ((x < y) ? -1 : ((x > y) ? 1 : 0));
+ })
+ );
+ },
+ SelectMany: function(clause) {
+ var r = new Array();
+ for (var i = 0; i < this.items.length; i++) {
+ r = r.concat(clause(this.items[i]));
+ }
+ return new JSLINQ(r);
+ },
+ Count: function(clause) {
+ if (clause == null)
+ return this.items.length;
+ else
+ return this.Where(clause).items.length;
+ },
+ Distinct: function(clause) {
+ var item;
+ var dict = new Object();
+ var retVal = new Array();
+ for (var i = 0; i < this.items.length; i++) {
+ item = clause(this.items[i]);
+ // TODO - This doens't correctly compare Objects. Need to fix this
+ if (dict[item] == null) {
+ dict[item] = true;
+ retVal[retVal.length] = item;
+ }
+ }
+ dict = null;
+ return new JSLINQ(retVal);
+ },
+ Any: function(clause) {
+ for (var index = 0; index < this.items.length; index++) {
+ if (clause(this.items[index], index)) { return true; }
+ }
+ return false;
+ },
+ All: function(clause) {
+ for (var index = 0; index < this.items.length; index++) {
+ if (!clause(this.items[index], index)) { return false; }
+ }
+ return true;
+ },
+ Reverse: function() {
+ var retVal = new Array();
+ for (var index = this.items.length - 1; index > -1; index--)
+ retVal[retVal.length] = this.items[index];
+ return new JSLINQ(retVal);
+ },
+ First: function(clause) {
+ if (clause != null) {
+ return this.Where(clause).First();
+ }
+ else {
+ // If no clause was specified, then return the First element in the Array
+ if (this.items.length > 0)
+ return this.items[0];
+ else
+ return null;
+ }
+ },
+ Last: function(clause) {
+ if (clause != null) {
+ return this.Where(clause).Last();
+ }
+ else {
+ // If no clause was specified, then return the First element in the Array
+ if (this.items.length > 0)
+ return this.items[this.items.length - 1];
+ else
+ return null;
+ }
+ },
+ ElementAt: function(index) {
+ return this.items[index];
+ },
+ Concat: function(array) {
+ var arr = array.items || array;
+ return new JSLINQ(this.items.concat(arr));
+ },
+ Intersect: function(secondArray, clause) {
+ var clauseMethod;
+ if (clause != undefined) {
+ clauseMethod = clause;
+ } else {
+ clauseMethod = function(item, index, item2, index2) { return item == item2; };
+ }
+
+ var sa = secondArray.items || secondArray;
+
+ var result = new Array();
+ for (var a = 0; a < this.items.length; a++) {
+ for (var b = 0; b < sa.length; b++) {
+ if (clauseMethod(this.items[a], a, sa[b], b)) {
+ result[result.length] = this.items[a];
+ }
+ }
+ }
+ return new JSLINQ(result);
+ },
+ DefaultIfEmpty: function(defaultValue) {
+ if (this.items.length == 0) {
+ return defaultValue;
+ }
+ return this;
+ },
+ ElementAtOrDefault: function(index, defaultValue) {
+ if (index >= 0 && index < this.items.length) {
+ return this.items[index];
+ }
+ return defaultValue;
+ },
+ FirstOrDefault: function(defaultValue) {
+ return this.First() || defaultValue;
+ },
+ LastOrDefault: function(defaultValue) {
+ return this.Last() || defaultValue;
+ }
+ };
+ JSLINQ.fn.init.prototype = JSLINQ.fn;
+})();
View
@@ -0,0 +1,70 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title>LINQ to JavaScript SDK - Samples</title>
+
+ <style type="text/css">
+ ul {margin-left: 2px;}
+ ul li {font-weight: bold; font-size: smaller;}
+ ul ul { margin-left: 5px; list-style-type: none;}
+ ul ul li {font-weight: normal; font-size: smaller;}
+ h4 { width: 100%; background-color: #ccc; padding: 3px; margin-bottom: -10px;}
+ table.noborder{border: none;}
+ table {border: 1px #ccc solid;}
+ table tr th {background-color: #efefef; padding: 3px;}
+ table tr td {vertical-align: top;}
+ </style>
+
+ <script type="text/javascript" src="javascript/LINQ.js"></script>
+ <script type="text/javascript" src="javascript/data.js"></script>
+
+ <script type="text/javascript">
+ function Page_Load(){
+ Samples.ShowSampleList();
+ // Show the First From Operator Sample by Default
+ Samples.Show(Samples.SampleList[0].Samples[0]);
+ Samples.ShowSourceData();
+ }
+ </script>
+</head>
+<body onload="Page_Load();">
+
+ <h1>LINQ to JavaScript - Samples</h1>
+ <p>These are some basic samples of using JSLINQ to select/manipulate your JavaScript Arrays.</p>
+ <table class="noborder">
+ <tr>
+ <td valign="top" style="margin-right: 10px; width: 250px; border: solid 1px black; background-color: #efefef;padding-left:3px">
+ JSLINQ v<script type="text/javascript">document.write(JSLINQ().jslinq);</script>
+ <ul id="SampleList"></ul>
+ <br/>
+ <hr/>
+ <a href="default.htm">Back...</a>
+ <br />
+ <br />
+ <a href="http://codeplex.com/jslinq">JSLINQ Project Homepage</a>
+ </td>
+ <td valign="top">
+ <h2 id="lblSampleTitle"></h2>
+ <span id="lblSampleDescription"></span><br />
+ <br />
+ <h4>Code:</h4><br />
+ <textarea cols="75" rows="8" id="txtSampleCode"></textarea><br />
+ <br />
+ <table class="noborder" width="100%">
+ <tr>
+ <td width="50%" style="padding-right: 5px;">
+ <h4>Samples.People Source Array:</h4><br />
+ <div id="SourceData"></div>
+ </td>
+ <td width="50%" style="padding-left: 5px;">
+ <h4>Results of JSLINQ Operation:</h4><br />
+ <div id="ResultData"></div>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+</body>
+</html>
View
@@ -0,0 +1,111 @@
+//-----------------------------------------------------------------------
+// Visual Studio JavaScript Intellisense Helper for LINQ to JavaScript
+// Part of the LINQ to JavaScript (JSLINQ) v2.10 Project - http://jslinq.codeplex.com
+// Copyright (C) 2009 Chris Pietschmann (http://pietschsoft.com). All rights reserved.
+// This project is licensed under the Microsoft Reciprocal License (Ms-RL)
+// This license can be found here: http://jslinq.codeplex.com/license
+//-----------------------------------------------------------------------
+JSLINQ = function(dataItems) {
+ /// <summary>The JSLINQ Object that provides LINQ query syntax to work with JavaScript Arrays.</summary>
+ /// <param name="dataArray">The Array that this JSLINQ instance will work with.</param>
+ /// <field name="items">The internal Array that contains the actual data items.</field>
+};
+JSLINQ.prototype = {
+ ToArray: function() {
+ /// <summary>Gets the underlieing Array object that holds the data.</summary>
+ /// <returns type="Array"></returns>
+ },
+ Where: function(clause) {
+ /// <summary>Filters a sequence of values based on a clause predicate.</summary>
+ /// <param name="clause">The clause used to determine query matches.</param>
+ /// <returns type="JSLINQ"></returns>
+ },
+ Select: function(clause) {
+ /// <summary>Projects each element of a sequence into a new form.</summary>
+ /// <param name="clause">The clause used to determine what values to select.</param>
+ /// <returns type="JSLINQ"></returns>
+ },
+ OrderBy: function(clause) {
+ /// <summary>Sorts the elements of a sequence in ascending order.</summary>
+ /// <param name="clause">The clause used to determine how to order the data.</param>
+ /// <returns type="JSLINQ"></returns>
+ },
+ OrderByDescending: function(clause) {
+ /// <summary>Sorts the elements of a sequence in descending order.</summary>
+ /// <param name="clause">The clause used to determine how to order the data.</param>
+ /// <returns type="JSLINQ"></returns>
+ },
+ SelectMany: function(clause) {
+ /// <summary>Projects each element of a sequence to a JSLINQ and flattens the resulting sequences into one sequence.</summary>
+ /// <param name="clause">The clause used to determine what values to select.</param>
+ /// <returns type="JSLINQ"></returns>
+ },
+ Count: function(clause) {
+ /// <summary>Returns the number of elements in a sequence.</summary>
+ /// <param name="clause">The clause used to determine what values to count.</param>
+ /// <returns type="Number"></returns>
+ },
+ Distinct: function(clause) {
+ /// <summary>Returns distinct elements from a sequence.</summary>
+ /// <param name="clause">The clause used to determine what values to select.</param>
+ /// <returns type="JSLINQ"></returns>
+ },
+ Any: function(clause) {
+ /// <summary>Determines whether any element of a sequence exists or satisfies a condition.</summary>
+ /// <param name="clause">The clause used to determine if a match exists.</param>
+ /// <returns type="Boolean"></returns>
+ },
+ All: function(clause) {
+ /// <summary>Determines whether all elements of a sequence satisfy a condition.</summary>
+ /// <param name="clause">The clause used to determine if a match exists.</param>
+ /// <returns type="Boolean">true if every element of the source sequence passes the test in the specified clause predicate, or if the sequence is empty; otherwise, false.</returns>
+ },
+ Reverse: function() {
+ /// <summary>Inverts the order of the elements in a sequence.</summary>
+ /// <returns type="JSLINQ"></returns>
+ },
+ First: function(clause) {
+ /// <summary>Returns the first element of a sequence.</summary>
+ /// <param name="clause">The clause used to determine which group of elements to return the first element from.</param>
+ /// <returns type="Object"></returns>
+ },
+ Last: function(clause) {
+ /// <summary>Returns the last element of a sequence.</summary>
+ /// <param name="clause">The clause used to determine which group of elements to return the last element from.</param>
+ /// <returns type="Object"></returns>
+ },
+ ElementAt: function(index) {
+ /// <summary>Returns the element at a specified index in a sequence.</summary>
+ /// <param name="index">The zero-based index of the element to retrieve.</param>
+ /// <returns type="Object"></returns>
+ },
+ Concat: function(array) {
+ /// <summary>Concatenates two sequences. (Is actually Idendical to the Array.concat method.)</summary>
+ /// <param name="array">A JSLINQ or Array object that contains the elements to concatenate.</param>
+ /// <returns type="JSLINQ"></returns>
+ },
+ Intersect: function(secondArray, clause) {
+ /// <summary>Produces the set intersection of two sequences.</summary>
+ /// <param name="secondArray">The second JSLINQ element sequence to perform the Intersect on.</param>
+ /// <param name="clause"></param>
+ /// <returns type="JSLINQ"></returns>
+ },
+ DefaultIfEmpty: function(defaultValue) {
+ /// <summary>Returns the JSLINQ object, or a default value if the sequence is empty.</summary>
+ /// <param name="defaultValue">The default value to return if the sequence is empty.</param>
+ },
+ ElementAtOrDefault: function(index, defaultValue) {
+ /// <summary>Returns the element at a specified index in a sequence or a default value if the index is out of range.</summary>
+ /// <param name="index">The zero-based index of the element to retrieve.</param>
+ /// <param name="defaultValue">The default value to return if the index is out of range.</param>
+ /// <returns type="">defaultValue if the index is outside the bounds of the source sequence; otherwise, the element at the specified position in the source sequense.</returns>
+ },
+ FirstOrDefault: function(defaultValue) {
+ /// <summary>Returns the first element of a sequence, or a default value if no element is found.</summary>
+ /// <param name="defaultValue">The default value to return if no element is found.</param>
+ },
+ LastOrDefault: function(defaultValue) {
+ /// <summary>Returns the last element of a sequence, or a default value if no element is found.</summary>
+ /// <param name="defaultValue">The default value to return if no element is found.</param>
+ }
+};
Oops, something went wrong.

0 comments on commit d2e7b55

Please sign in to comment.