├── .github └── FUNDING.yml ├── .gitignore ├── .vs └── JSLINQ │ ├── FileContentIndex │ ├── 34d0f1e7-9351-42f7-96ab-3aaca0b2a1ce.vsidx │ ├── 404ae511-edc9-4a24-a13c-0e47a4bedbd3.vsidx │ ├── 4a490397-843f-43d0-b841-bfe9ec47dd98.vsidx │ └── read.lock │ ├── config │ └── applicationhost.config │ └── v17 │ ├── .suo │ └── TestStore │ └── 0 │ ├── 000.testlog │ └── testlog.manifest ├── JSLINQ.sln ├── JSLINQ.vssscc ├── LICENSE ├── Nuget ├── NuGet.exe ├── build.bat ├── jslinq.2.10.1.nupkg ├── jslinq.2.10.nupkg ├── jslinq.2.30.nupkg └── package │ ├── Content │ └── Scripts │ │ ├── JSLINQ-vsdoc.js │ │ └── JSLINQ.js │ └── jslinq.nuspec ├── README.md ├── Website ├── Default.htm ├── Examples │ ├── Array │ │ ├── CountSetOfWords.htm │ │ └── CountWordOccurrences.htm │ ├── Extensions │ │ └── get.htm │ └── HtmlDomTable.htm ├── ReadMe.txt ├── Samples.htm ├── TestSamples.htm ├── Web.config └── scripts │ ├── JSLINQ-vsdoc.js │ ├── JSLINQ.js │ └── Samples.js └── images └── Nuget-jslinq-install.png /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: https://paypal.me/simplovation 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .vs/JSLINQ/v17/.suo 3 | -------------------------------------------------------------------------------- /.vs/JSLINQ/FileContentIndex/34d0f1e7-9351-42f7-96ab-3aaca0b2a1ce.vsidx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crpietschmann/jslinq/177cba044a8c3843e5f6a9947f71a8a2f43aae22/.vs/JSLINQ/FileContentIndex/34d0f1e7-9351-42f7-96ab-3aaca0b2a1ce.vsidx -------------------------------------------------------------------------------- /.vs/JSLINQ/FileContentIndex/404ae511-edc9-4a24-a13c-0e47a4bedbd3.vsidx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crpietschmann/jslinq/177cba044a8c3843e5f6a9947f71a8a2f43aae22/.vs/JSLINQ/FileContentIndex/404ae511-edc9-4a24-a13c-0e47a4bedbd3.vsidx -------------------------------------------------------------------------------- /.vs/JSLINQ/FileContentIndex/4a490397-843f-43d0-b841-bfe9ec47dd98.vsidx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crpietschmann/jslinq/177cba044a8c3843e5f6a9947f71a8a2f43aae22/.vs/JSLINQ/FileContentIndex/4a490397-843f-43d0-b841-bfe9ec47dd98.vsidx -------------------------------------------------------------------------------- /.vs/JSLINQ/FileContentIndex/read.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crpietschmann/jslinq/177cba044a8c3843e5f6a9947f71a8a2f43aae22/.vs/JSLINQ/FileContentIndex/read.lock -------------------------------------------------------------------------------- /.vs/JSLINQ/config/applicationhost.config: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 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 | 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 | 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 | 1001 | 1002 | 1003 | 1004 | 1005 | 1006 | 1007 | 1008 | 1009 | 1010 | 1011 | 1012 | 1013 | 1014 | 1015 | 1016 | 1017 | 1018 | 1019 | 1020 | 1021 | 1022 | 1023 | 1024 | 1025 | -------------------------------------------------------------------------------- /.vs/JSLINQ/v17/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crpietschmann/jslinq/177cba044a8c3843e5f6a9947f71a8a2f43aae22/.vs/JSLINQ/v17/.suo -------------------------------------------------------------------------------- /.vs/JSLINQ/v17/TestStore/0/000.testlog: -------------------------------------------------------------------------------- 1 | !!tItseT -------------------------------------------------------------------------------- /.vs/JSLINQ/v17/TestStore/0/testlog.manifest: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crpietschmann/jslinq/177cba044a8c3843e5f6a9947f71a8a2f43aae22/.vs/JSLINQ/v17/TestStore/0/testlog.manifest -------------------------------------------------------------------------------- /JSLINQ.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.5.33424.131 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "Website", "Website\", "{397777F9-0620-4C99-B329-B09AB03D85F3}" 7 | ProjectSection(WebsiteProperties) = preProject 8 | SccProjectName = "SAK" 9 | SccAuxPath = "SAK" 10 | SccLocalPath = "SAK" 11 | SccProvider = "SAK" 12 | TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.8" 13 | Debug.AspNetCompiler.VirtualPath = "/Website" 14 | Debug.AspNetCompiler.PhysicalPath = "Website\" 15 | Debug.AspNetCompiler.TargetPath = "PrecompiledWeb\Website\" 16 | Debug.AspNetCompiler.Updateable = "true" 17 | Debug.AspNetCompiler.ForceOverwrite = "true" 18 | Debug.AspNetCompiler.FixedNames = "false" 19 | Debug.AspNetCompiler.Debug = "True" 20 | Release.AspNetCompiler.VirtualPath = "/Website" 21 | Release.AspNetCompiler.PhysicalPath = "Website\" 22 | Release.AspNetCompiler.TargetPath = "PrecompiledWeb\Website\" 23 | Release.AspNetCompiler.Updateable = "true" 24 | Release.AspNetCompiler.ForceOverwrite = "true" 25 | Release.AspNetCompiler.FixedNames = "false" 26 | Release.AspNetCompiler.Debug = "False" 27 | VWDPort = "1560" 28 | SlnRelativePath = "Website\" 29 | DefaultWebSiteLanguage = "Visual C#" 30 | EndProjectSection 31 | EndProject 32 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Nuget", "Nuget", "{9CC0875D-29D0-447F-8231-E9F4D7F03C14}" 33 | ProjectSection(SolutionItems) = preProject 34 | build.bat = build.bat 35 | Nuget\jslinq.2.10.1.nupkg = Nuget\jslinq.2.10.1.nupkg 36 | Nuget\jslinq.2.10.nupkg = Nuget\jslinq.2.10.nupkg 37 | Nuget\NuGet.exe = Nuget\NuGet.exe 38 | EndProjectSection 39 | EndProject 40 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "package", "package", "{C9B10C36-5744-4D25-8BE8-1E993624D4DB}" 41 | ProjectSection(SolutionItems) = preProject 42 | Nuget\package\jslinq.nuspec = Nuget\package\jslinq.nuspec 43 | EndProjectSection 44 | EndProject 45 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Content", "Content", "{59D05196-6DEF-4FD2-95EF-E625094232BB}" 46 | EndProject 47 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{C4E3084D-1B0F-47F8-8CEE-8533E0E85EDD}" 48 | ProjectSection(SolutionItems) = preProject 49 | Nuget\package\Content\Scripts\JSLINQ-vsdoc.js = Nuget\package\Content\Scripts\JSLINQ-vsdoc.js 50 | Nuget\package\Content\Scripts\JSLINQ.js = Nuget\package\Content\Scripts\JSLINQ.js 51 | EndProjectSection 52 | EndProject 53 | Global 54 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 55 | Debug|Any CPU = Debug|Any CPU 56 | EndGlobalSection 57 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 58 | {397777F9-0620-4C99-B329-B09AB03D85F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 59 | {397777F9-0620-4C99-B329-B09AB03D85F3}.Debug|Any CPU.Build.0 = Debug|Any CPU 60 | EndGlobalSection 61 | GlobalSection(SolutionProperties) = preSolution 62 | HideSolutionNode = FALSE 63 | EndGlobalSection 64 | GlobalSection(NestedProjects) = preSolution 65 | {C9B10C36-5744-4D25-8BE8-1E993624D4DB} = {9CC0875D-29D0-447F-8231-E9F4D7F03C14} 66 | {59D05196-6DEF-4FD2-95EF-E625094232BB} = {C9B10C36-5744-4D25-8BE8-1E993624D4DB} 67 | {C4E3084D-1B0F-47F8-8CEE-8533E0E85EDD} = {59D05196-6DEF-4FD2-95EF-E625094232BB} 68 | EndGlobalSection 69 | GlobalSection(ExtensibilityGlobals) = postSolution 70 | SolutionGuid = {198ABC44-7984-4C66-A375-24F8807658F9} 71 | EndGlobalSection 72 | EndGlobal 73 | -------------------------------------------------------------------------------- /JSLINQ.vssscc: -------------------------------------------------------------------------------- 1 | "" 2 | { 3 | "FILE_VERSION" = "9237" 4 | "ENLISTMENT_CHOICE" = "NEVER" 5 | "PROJECT_FILE_RELATIVE_PATH" = "" 6 | "NUMBER_OF_EXCLUDED_FILES" = "0" 7 | "ORIGINAL_PROJECT_FILE_PATH" = "" 8 | "NUMBER_OF_NESTED_PROJECTS" = "0" 9 | "SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT" 10 | } 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-2023 Chris Pietschmann 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Nuget/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crpietschmann/jslinq/177cba044a8c3843e5f6a9947f71a8a2f43aae22/Nuget/NuGet.exe -------------------------------------------------------------------------------- /Nuget/build.bat: -------------------------------------------------------------------------------- 1 | nuget.exe pack package/jslinq.nuspec -------------------------------------------------------------------------------- /Nuget/jslinq.2.10.1.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crpietschmann/jslinq/177cba044a8c3843e5f6a9947f71a8a2f43aae22/Nuget/jslinq.2.10.1.nupkg -------------------------------------------------------------------------------- /Nuget/jslinq.2.10.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crpietschmann/jslinq/177cba044a8c3843e5f6a9947f71a8a2f43aae22/Nuget/jslinq.2.10.nupkg -------------------------------------------------------------------------------- /Nuget/jslinq.2.30.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crpietschmann/jslinq/177cba044a8c3843e5f6a9947f71a8a2f43aae22/Nuget/jslinq.2.30.nupkg -------------------------------------------------------------------------------- /Nuget/package/Content/Scripts/JSLINQ-vsdoc.js: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------- 2 | // Visual Studio JavaScript Intellisense Helper for LINQ to JavaScript 3 | // LINQ to JavaScript (JSLINQ) Project - https://github.com/crpietschmann/jslinq 4 | // Copyright (c) 2012-2023 Chris Pietschmann (http://pietschsoft.com) 5 | // This license can be found here: https://github.com/crpietschmann/jslinq/blob/master/LICENSE 6 | //----------------------------------------------------------------------- 7 | JSLINQ = function(dataItems) { 8 | /// The JSLINQ Object that provides LINQ query syntax to work with JavaScript Arrays. 9 | /// The Array that this JSLINQ instance will work with. 10 | /// The internal Array that contains the actual data items. 11 | /// 12 | }; 13 | JSLINQ.prototype = { 14 | ToArray: function () { 15 | /// Gets the underlieing Array object that holds the data. 16 | /// 17 | }, 18 | Where: function (clause) { 19 | /// Filters a sequence of values based on a clause predicate. 20 | /// The clause used to determine query matches. 21 | /// 22 | }, 23 | Select: function (clause) { 24 | /// Projects each element of a sequence into a new form. 25 | /// The clause used to determine what values to select. Or a comma delimited string containing the object properties to select. 26 | /// 27 | }, 28 | OrderBy: function (clause) { 29 | /// Sorts the elements of a sequence in ascending order. 30 | /// The clause used to determine how to order the data. 31 | /// 32 | }, 33 | OrderByDescending: function (clause) { 34 | /// Sorts the elements of a sequence in descending order. 35 | /// The clause used to determine how to order the data. 36 | /// 37 | }, 38 | SelectMany: function (clause) { 39 | /// Projects each element of a sequence to a JSLINQ and flattens the resulting sequences into one sequence. 40 | /// The clause used to determine what values to select. 41 | /// 42 | }, 43 | Count: function (clause) { 44 | /// Returns the number of elements in a sequence. 45 | /// The clause used to determine what values to count. 46 | /// 47 | }, 48 | Distinct: function (clause) { 49 | /// Returns distinct elements from a sequence. 50 | /// The clause used to determine what values to select. 51 | /// 52 | }, 53 | Any: function (clause) { 54 | /// Determines whether any element of a sequence exists or satisfies a condition. 55 | /// The clause used to determine if a match exists. 56 | /// 57 | }, 58 | All: function (clause) { 59 | /// Determines whether all elements of a sequence satisfy a condition. 60 | /// The clause used to determine if a match exists. 61 | /// true if every element of the source sequence passes the test in the specified clause predicate, or if the sequence is empty; otherwise, false. 62 | }, 63 | Reverse: function () { 64 | /// Inverts the order of the elements in a sequence. 65 | /// 66 | }, 67 | First: function (clause) { 68 | /// Returns the first element of a sequence. 69 | /// The clause used to determine which group of elements to return the first element from. 70 | /// 71 | }, 72 | Last: function (clause) { 73 | /// Returns the last element of a sequence. 74 | /// The clause used to determine which group of elements to return the last element from. 75 | /// 76 | }, 77 | ElementAt: function (index) { 78 | /// Returns the element at a specified index in a sequence. 79 | /// The zero-based index of the element to retrieve. 80 | /// 81 | }, 82 | Concat: function (array) { 83 | /// Concatenates two sequences. (Is actually Idendical to the Array.concat method.) 84 | /// A JSLINQ or Array object that contains the elements to concatenate. 85 | /// 86 | }, 87 | Intersect: function (secondArray, clause) { 88 | /// Produces the set intersection of two sequences. 89 | /// The second JSLINQ element sequence to perform the Intersect on. 90 | /// 91 | /// 92 | }, 93 | DefaultIfEmpty: function (defaultValue) { 94 | /// Returns the JSLINQ object, or a default value if the sequence is empty. 95 | /// The default value to return if the sequence is empty. 96 | }, 97 | ElementAtOrDefault: function (index, defaultValue) { 98 | /// Returns the element at a specified index in a sequence or a default value if the index is out of range. 99 | /// The zero-based index of the element to retrieve. 100 | /// The default value to return if the index is out of range. 101 | /// defaultValue if the index is outside the bounds of the source sequence; otherwise, the element at the specified position in the source sequense. 102 | }, 103 | FirstOrDefault: function (defaultValue) { 104 | /// Returns the first element of a sequence, or a default value if no element is found. 105 | /// The default value to return if no element is found. 106 | }, 107 | LastOrDefault: function (defaultValue) { 108 | /// Returns the last element of a sequence, or a default value if no element is found. 109 | /// The default value to return if no element is found. 110 | }, 111 | Take: function (count) { 112 | /// Returns a specified number of contiguous elements from the start of a sequence. 113 | /// The number of elements to return. 114 | }, 115 | Skip: function (count) { 116 | /// Bypasses a specified number of elements in a sequence and then returns the remaining elements. 117 | /// The number of elements to skip before returning the remaining elements. 118 | }, 119 | Each: function (clause) { 120 | /// Executes a clause predicate on each element. 121 | /// The clause to execute on each element. 122 | }, 123 | Random: function (count) { 124 | /// This method will returns the specified number of elements at random. If no number is specified, then 1 is returned. 125 | /// The number of elements to return 126 | } 127 | }; -------------------------------------------------------------------------------- /Nuget/package/Content/Scripts/JSLINQ.js: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------- 2 | // LINQ to JavaScript (JSLINQ) Project - https://github.com/crpietschmann/jslinq 3 | // Copyright (c) 2012-2023 Chris Pietschmann (http://pietschsoft.com) 4 | // This license can be found here: https://github.com/crpietschmann/jslinq/blob/master/LICENSE 5 | //----------------------------------------------------------------------- 6 | (function () { 7 | var JSLINQ = window.jslinq = window.JSLINQ = function (dataItems) { 8 | return new JSLINQ.fn.init(dataItems); 9 | }, 10 | utils = { 11 | processLambda: function (clause) { 12 | if (utils.isLambda(clause)) { 13 | var expr = clause.match(/^[(\s]*([^()]*?)[)\s]*=>(.*)/); 14 | return new Function(expr[1], "return (" + expr[2] + ")"); 15 | } 16 | return clause; 17 | }, 18 | isLambda: function (clause) { 19 | return (clause.indexOf("=>") > -1); 20 | }, 21 | randomIndex: function (max, existing) { 22 | var q, r, f = function () { return this == r; }; 23 | if (!existing) { 24 | return parseInt(Math.random() * max, 10); 25 | } else { 26 | q = JSLINQ(existing); 27 | r = -1; 28 | while (r < 0 || q.Where(f).Count() !== 0) { 29 | r = utils.randomIndex(max); 30 | } 31 | return r; 32 | } 33 | } 34 | }; 35 | JSLINQ.fn = JSLINQ.prototype = { 36 | init: function (dataItems) { 37 | this.items = dataItems; 38 | }, 39 | 40 | // The current version of JSLINQ being used 41 | jslinq: '2.30', 42 | 43 | toArray: function () { return this.items; }, 44 | forEach: function (callback) { 45 | this.items.forEach(callback); 46 | return this; 47 | }, 48 | where: function (clause) { 49 | var newArray = []; 50 | // The clause was passed in as a Method that return a Boolean 51 | this.forEach((item, i) => { 52 | if (clause.apply(item, [item, i])) newArray[newArray.length] = item; 53 | }); 54 | return JSLINQ(newArray); 55 | }, 56 | select: function (clause) { 57 | var newArray = [], field = clause; 58 | if (typeof (clause) !== "function") { 59 | if (clause.indexOf(",") === -1) { 60 | clause = function () { return this[field]; }; 61 | } else { 62 | clause = function () { 63 | var obj = {}; 64 | field.split(',').forEach((f) => { 65 | obj[f] = this[f]; 66 | }); 67 | return obj; 68 | }; 69 | } 70 | } 71 | 72 | // The clause was passed in as a Method that returns a Value 73 | this.forEach((item, i) => { 74 | val = clause.apply(item, [item]); 75 | if (val) newArray[newArray.length] = val; 76 | }); 77 | return JSLINQ(newArray); 78 | }, 79 | orderBy: function (clause) { 80 | var tempArray = []; 81 | this.forEach((item) => { 82 | tempArray.push(item); 83 | }); 84 | 85 | if (typeof (clause) !== "function") { 86 | var field = clause; 87 | if (utils.isLambda(field)) { 88 | clause = utils.processLambda(field); 89 | } else { 90 | clause = function () { return this[field]; }; 91 | } 92 | } 93 | 94 | return JSLINQ(tempArray.sort(function (a, b) { 95 | var x = clause.apply(a, [a]), y = clause.apply(b, [b]); 96 | return ((x < y) ? -1 : ((x > y) ? 1 : 0)); 97 | }) 98 | ); 99 | }, 100 | orderByDescending: function (clause) { 101 | var tempArray = [], field; 102 | this.forEach((item) => { 103 | tempArray.push(item); 104 | }); 105 | 106 | if (typeof (clause) !== "function") { 107 | field = clause; 108 | if (utils.isLambda(field)) { 109 | clause = utils.processLambda(field); 110 | } else { 111 | clause = function () { return this[field]; }; 112 | } 113 | } 114 | 115 | return JSLINQ(tempArray.sort(function (a, b) { 116 | var x = clause.apply(b, [b]), y = clause.apply(a, [a]); 117 | return ((x < y) ? -1 : ((x > y) ? 1 : 0)); 118 | })); 119 | }, 120 | selectMany: function (clause) { 121 | var r = []; 122 | this.forEach((item) => { 123 | r = r.concat(clause.apply(item, [item])); 124 | }); 125 | return JSLINQ(r); 126 | }, 127 | count: function (clause) { 128 | if (clause === undefined) { 129 | return this.items.length; 130 | } 131 | return this.Where(clause).items.length; 132 | }, 133 | distinct: function (clause) { 134 | var dict = {}, retVal = []; 135 | this.forEach((item) => { 136 | var val = clause.apply(item, [item]); 137 | // TODO - This doesn't correctly compare Objects. Need to fix this 138 | if (dict[val] === undefined) { 139 | dict[val] = true; 140 | retVal.push(val); 141 | } 142 | }); 143 | dict = null; 144 | return JSLINQ(retVal); 145 | }, 146 | any: function (clause) { 147 | var item; 148 | for (var i = 0; i < this.items.length; i++) { 149 | item = this.items[i]; 150 | if (clause.apply(item, [item, i])) return true; 151 | } 152 | return false; 153 | }, 154 | all: function (clause) { 155 | for (var i = 0; i < this.items.length; i++) { 156 | if (!clause(this.items[i], i)) return false; 157 | } 158 | return true; 159 | }, 160 | reverse: function () { 161 | var retVal = []; 162 | for (var i = this.items.length - 1; i > -1; i--) { 163 | retVal[retVal.length] = this.items[i]; 164 | } 165 | return JSLINQ(retVal); 166 | }, 167 | first: function (clause) { 168 | if (clause !== undefined) { 169 | return this.Where(clause).First(); 170 | } else if (this.items.length > 0) { 171 | // If no clause was specified, then return the First element in the Array 172 | return this.items[0]; 173 | } 174 | return null; 175 | }, 176 | last: function (clause) { 177 | if (clause !== undefined) { 178 | return this.Where(clause).Last(); 179 | } else { 180 | // If no clause was specified, then return the First element in the Array 181 | if (this.items.length > 0) { 182 | return this.items[this.items.length - 1]; 183 | } 184 | } 185 | return null; 186 | }, 187 | elementAt: function (i) { 188 | return this.items[i]; 189 | }, 190 | concat: function (array) { 191 | var arr = array.items || array; 192 | return JSLINQ(this.items.concat(arr)); 193 | }, 194 | intersect: function (secondArray, clause) { 195 | var method, sa = (secondArray.items || secondArray), result = []; 196 | if (clause !== undefined) { 197 | method = clause; 198 | } else { 199 | method = (item, i1, item2, i2) => item === item2; 200 | } 201 | 202 | for (var a = 0; a < this.items.length; a++) { 203 | for (var b = 0; b < sa.length; b++) { 204 | if (method(this.items[a], a, sa[b], b)) { 205 | result[result.length] = this.items[a]; 206 | } 207 | } 208 | } 209 | return JSLINQ(result); 210 | }, 211 | defaultIfEmpty: function (defaultValue) { 212 | if (this.items.length === 0) { 213 | return defaultValue; 214 | } 215 | return this; 216 | }, 217 | elementAtOrDefault: function (i, defaultValue) { 218 | if (i >= 0 && i < this.items.length) { 219 | return this.items[i]; 220 | } 221 | return defaultValue; 222 | }, 223 | firstOrDefault: function (defaultValue) { 224 | return this.First() || defaultValue; 225 | }, 226 | lastOrDefault: function (defaultValue) { 227 | return this.Last() || defaultValue; 228 | }, 229 | take: function (count) { 230 | return this.Where(function (item, index) { return index < count; }); 231 | }, 232 | skip: function (count) { 233 | return this.Where(function (item, index) { return index >= count; }); 234 | }, 235 | each: function (clause) { 236 | var len = this.items.length; 237 | for (var i = 0; i < len; i++) { 238 | clause.apply(this.items[i], [this.items[i], i]); 239 | } 240 | return this; 241 | }, 242 | random: function (count) { 243 | var len = this.Count(), rnd = []; 244 | if (!count) { count = 1; } 245 | for (var i = 0; i < count; i++) { 246 | rnd.push(utils.randomIndex(len - 1, rnd)); 247 | } 248 | rnd = JSLINQ(rnd); 249 | return this.Where(function (item, index) { 250 | return rnd.Where(function () { 251 | return this == index; 252 | }).Count() > 0; 253 | }); 254 | } 255 | }; 256 | 257 | (function (fn) { 258 | fn.ToArray = fn.toArray; 259 | fn.ForEach = fn.forEach; 260 | fn.Where = fn.where; 261 | fn.Select = fn.select; 262 | fn.OrderBy = fn.orderBy; 263 | fn.OrderByDescending = fn.orderByDescending; 264 | fn.SelectMany = fn.selectMany; 265 | fn.Count = fn.count; 266 | fn.Distinct = fn.distinct; 267 | fn.Any = fn.any; 268 | fn.All = fn.all; 269 | fn.Reverse = fn.reverse; 270 | fn.First = fn.first; 271 | fn.Last = fn.last; 272 | fn.ElementAt = fn.elementAt; 273 | fn.Concat = fn.concat; 274 | fn.Intersect = fn.intersect; 275 | fn.DefaultIfEmpty = fn.defaultIfEmpty; 276 | fn.ElementAtOrDefault = fn.elementAtOrDefault; 277 | fn.FirstOrDefault = fn.firstOrDefault; 278 | fn.LastOrDefault = fn.lastOrDefault; 279 | fn.Take = fn.take; 280 | fn.Skip = fn.skip; 281 | fn.Each = fn.each; 282 | fn.Random = fn.random; 283 | })(JSLINQ.fn); 284 | 285 | JSLINQ.fn.init.prototype = JSLINQ.fn; 286 | })(); -------------------------------------------------------------------------------- /Nuget/package/jslinq.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | jslinq 5 | LINQ to JavaScript 6 | 2.30 7 | Chris Pietschmann 8 | Chris Pietschmann 9 | https://github.com/crpietschmann/jslinq/blob/master/LICENSE 10 | https://github.com/crpietschmann/jslinq 11 | false 12 | LINQ to JavaScript (JSLINQ) is an implementation of LINQ to Objects for JavaScript. It is simple to use and gives much needed power and flexibility to performing LINQ style queries agains traditional JavaScript Arrays. If you are using an Array, you can use LINQ to JavaScript to step up your game. 13 | https://github.com/crpietschmann/jslinq/blob/master/Website/ReadMe.txt 14 | Copyright (c) 2013-2023 Chris Pietschmann 15 | javascript js linq array objects 16 | 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LINQ to JavaScript 2 | 3 | LINQ to JavaScript (`JSLINQ`) is LINQ to Objects for JavaScript arrays, and adds power and flexibility of LINQ style queries to traditional JavaScript code. 4 | 5 | ## What is LINQ to JavaScript? 6 | 7 | LINQ to JavaScript (JSLINQ for short) is an implementation of LINQ to Objects implemented in JavaScript. It is built using a set of extension methods built on top of the JavaScript Array object. If you are using Arrays then you can use JSLINQ; it's that simple! 8 | 9 | ## Nuget Package 10 | 11 | [http://nuget.org/packages/jslinq](http://nuget.org/packages/jslinq) 12 | 13 | ![](images/Nuget-jslinq-install.png) 14 | 15 | ## Example Usage 16 | 17 | If you don't know what LINQ it's a feature set in the .NET development framework that allows more SQL-like querying of any kind of data. In the case of `JSLINQ` / LINQ to JavaScript, it provides the ability to query against Arrays. 18 | 19 | var myList = [ 20 | {FirstName:"Chris",LastName:"Pearson"}, 21 | {FirstName:"Kate",LastName:"Johnson"}, 22 | {FirstName:"Josh",LastName:"Sutherland"}, 23 | {FirstName:"John",LastName:"Ronald"}, 24 | {FirstName:"Steve",LastName:"Pinkerton"} 25 | ]; 26 | 27 | var exampleArray = JSLINQ(myList) 28 | .Where((item) => item.FirstName == "Chris") 29 | .OrderBy((item) => item.FirstName) 30 | .Select((item) => item.FirstName); 31 | 32 | ## Using LINQ to JavaScript 33 | 34 | We will use this Array for the following examples: 35 | 36 | var myList = [ 37 | {FirstName:"Chris",LastName:"Pearson"}, 38 | {FirstName:"Kate",LastName:"Johnson"}, 39 | {FirstName:"Josh",LastName:"Sutherland"}, 40 | {FirstName:"John",LastName:"Ronald"}, 41 | {FirstName:"Steve",LastName:"Pinkerton"} 42 | ]; 43 | 44 | **Create an Instance of the JSLINQ object with your data** 45 | 46 | You need to create a new JSLINQ object and pass it the javascript array of data that you will be querying. 47 | 48 | var example = JSLINQ(myList); 49 | 50 | **Using the Where operator to specify query criteria** 51 | 52 | In this case, we're getting all items in the Array that have FirstName property set to Chris. 53 | 54 | var whereExample1 = JSLINQ(myList). 55 | Where(function(item){ return item.FirstName == "Chris"; }); 56 | 57 | **Using the Select operator to specify which data to return** 58 | 59 | In this case, we're going to return only the FirstName property of each item in the Array. 60 | 61 | var selectTest2 = JSLINQ(myList). 62 | Select(function(item){ return item.FirstName; }); 63 | 64 | **Using the OrderBy operator to determine how to sort the order of the items in the Array** 65 | 66 | In this case, we're going to order them by the FirstName property. 67 | 68 | var sortTest1 = JSLINQ(myList) 69 | .OrderBy(function(item){ return item.FirstName; }); 70 | 71 | ## Related Links 72 | 73 | [JSLinq Editor](http://secretgeek.net/JsLinq/) 74 | 75 | 2010/03/16: [LINQ for JavaScript: Using and Extending JSLINQ](http://www.gregshackles.com/2010/03/linq-for-javascript-using-and-extending-jslinq/) 76 | 77 | 2008/01/24: [LINQ to JavaScript (JSLINQ) Open Source Project Launched!](http://pietschsoft.com/post/2008/01/24/LINQ-to-JavaScript-%28JSLINQ%29-Open-Source-Project-Launched!.aspx) 78 | -------------------------------------------------------------------------------- /Website/Default.htm: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |

10 | 13 | 14 | 30 | 31 |
32 | Visit the project homepage: https://github.com/crpietschmann/jslinq
33 |
34 | This project is created and maintained by Chris Pietschmann. 35 | 36 | 37 | -------------------------------------------------------------------------------- /Website/Examples/Array/CountSetOfWords.htm: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | JSLINQ Example: Count Occurrences of a Set of Words within a String 6 | 7 | 21 | 22 | 23 |

JSLINQ Example: Count Occurrences of a Set of Words within a String

24 |

This examples shows how to count the number of times each word within a set of words occurs within a string.

25 |

26 | Words to find: (seperate by a space)
27 | String to check:
28 |
29 |
30 | 31 |

32 |
33 | Back... 34 | 35 | 36 | -------------------------------------------------------------------------------- /Website/Examples/Array/CountWordOccurrences.htm: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | JSLINQ Example: Count Occurrences of a Word in a String 6 | 7 | 24 | 25 | 26 |

JSLINQ Example: Count Occurrences of a Word in a String

27 |

This examples shows how to count the number of time a specific words occurs within a string.

28 |

29 | Word to find: 
30 | String to check:
31 |
32 |
33 | 34 |

35 |
36 | Back... 37 | 38 | 39 | -------------------------------------------------------------------------------- /Website/Examples/Extensions/get.htm: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | JSLINQ Extensibility Example: "get" method 6 | 7 | 21 | 22 | 23 | 24 | 42 | 57 | 58 | 59 |

JSLINQ Extensibility Example: "get" method

60 |

This is an example of adding a "get" method to the JSLINQ object that works similarly to the "ElementAtOrDefault" method.

61 |

To use this sample "get" plugin, just pass in the "index" and "defaultValue" parameters the same as you would with the "ElementAtOrDefault" method. You can get the First element by omitting the "index" parameter.

62 | 63 |

Plugin Source Code:

64 | 65 | 68 |
69 | 70 |

Example Usage:

71 | 72 | 73 | 74 | 163 | 166 | 167 |
75 |

The full list of data that is being selected by the below example usages are located to the right.

76 | 77 |
78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 91 | 101 | 102 | 103 | 109 | 119 | 120 | 121 | 127 | 137 | 138 | 139 | 147 | 159 | 160 |
Usage / Operation 
86 | Select First:
87 |
88 | JSLINQ(Samples.People).get(); 89 |
90 |
92 | 93 | 100 |
104 | Select First or Default:
105 |
106 | JSLINQ(Samples.People).get({ID: 0, FirstName: "John", LastName: "Doe", Books: []}); 107 |
108 |
110 | 111 | 118 |
122 | Select Third:
123 |
124 | JSLINQ(Samples.People).get(2); 125 |
126 |
128 | 129 | 136 |
140 | Select Fifteenth or Default:
141 |
142 | JSLINQ(Samples.People).get(15, 143 | {ID: 0, FirstName: "John", LastName: "Doe", Books: []} 144 | ); 145 |
146 |
148 | 149 | 158 |
161 | 162 |
164 |
    165 |
    168 | 169 |
    170 | 171 | Back... 172 | 173 | 174 | -------------------------------------------------------------------------------- /Website/Examples/HtmlDomTable.htm: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | JSLINQ Example: Search HTML DOM Table 6 | 7 | 55 | 56 | 57 |

    JSLINQ Example: Search HTML DOM Table

    58 |

    This example demonstrates using an HTML Table as the data source for the JSLINQ query, and then displaying the search results within another Table on the page.

    59 | 60 |

    Query Results

    61 | First Name contains:    62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 |
    IDFirstNameLastName
    73 | 74 |

    Source Data

    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 |
    IDFirstNameLastName
    1ChrisPearson
    2KateJohnson
    3JoshSutherland
    4JohnRonald
    5StevePinkerton
    6KatieZimmerman
    7DirkAnderson
    8ChrisStevenson
    9BernardSutherland
    10KatePinkerton
    136 | 137 |
    138 | Back... 139 | 140 | -------------------------------------------------------------------------------- /Website/ReadMe.txt: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------- 2 | // Part of the LINQ to JavaScript (JSLINQ) v2.x Project - https://github.com/crpietschmann/jslinq 3 | // Copyright (C) 2012-2023 Chris Pietschmann (http://pietschsoft.com) 4 | // This license can be found here: https://github.com/crpietschmann/jslinq/blob/master/LICENSE 5 | //----------------------------------------------------------------------- 6 | 7 | LINQ To JavaScript Project - https://github.com/crpietschmann/jslinq 8 | 9 | To Run the Interactive SDK: 10 | - Open up the Default.htm file in a web browser 11 | 12 | To include JSLINQ within a website: 13 | - 1) Copy the JSLINQ.js file into your website 14 | - 2) Place the following script tag in the Head of your web page: 15 | 16 | 17 | 18 | JSLINQ Change Log 19 | ----------------- 20 | Version 2.3 (11/17/2023) 21 | ------------- 22 | - Cleaned up Javascript code to be a little more clean as per modern javascript standards 23 | - Updated License and other links to point to Github project 24 | - Add `forEach(callback)` function to JSLINQ object 25 | 26 | Version 2.2 27 | ------------- 28 | - Added lower case "jslinq" option that can be used interchangably with "JSLINQ" 29 | 30 | - Added lower case options for the operator methods (ex: .where = .Where, .select = .Select, .orderBy = .OrderBy) that can be used interchangably with the upper case options. 31 | 32 | - added a couple more fixes recommended by jslint, plus made TestSamples.htm run test automatically on page load 33 | 34 | - Fixed js code, ala http://www.jslint.com 35 | 36 | - Add ".Random(count)" method to return a random set of elements 37 | 38 | - modified "new Array()" calls to "[]", and "new Object()" to "{}" to make the code cleaner 39 | 40 | - Added ".Each" method 41 | 42 | - Modified ".Select" to accept multiple fields to select by passing them in as a delimited string. 43 | 44 | - Added "Skip" method to Bypasses a specified number of elements in a sequence and then returns the remaining elements. 45 | 46 | - Added "Take" method to return the first 'n' number of elements in the array. 47 | 48 | - Modify "OrderBy" and "OrderByDescending" to access "C#-like Lambda" expressions also. 49 | var sample = JSLINQ(Samples.People) 50 | .OrderBy("item => item.FirstName"); 51 | 52 | - Modify "Select" to accept fields/properties to select by passing in a string. 53 | var sample = JSLINQ(Samples.People) 54 | .Select("FirstName"); 55 | OR 56 | var sample = JSLINQ(Samples.People) 57 | .Select("ID,FirstName,LastName"); 58 | 59 | - Modify "OrderByDescending" to accept the field/property to order by as a string in addition to accepting a "clause function"/lambda expression. 60 | var sample = JSLINQ(Samples.People) 61 | .OrderByDescending("FirstName"); 62 | 63 | - Modify "OrderBy" to accept the field/property to order by as a string in addition to accepting a "clause function"/lambda expression. 64 | var sample = JSLINQ(Samples.People) 65 | .OrderBy("FirstName"); 66 | 67 | - Select method fix: Stop calling "clause" twice for each iteration of an element. This improves performance of calling "Select". 68 | - Modify all "clauses" / lambda expressions to get called having "this" equal to the Array Item where appropriate. 69 | var exampleArray = JSLINQ(myList) 70 | .Where(function(){ return this.FirstName == "Chris"; }) 71 | .OrderBy(function() { return this.FirstName; }) 72 | .Select(function(){ return this.FirstName; }); 73 | 74 | - Replace all "new JSLINQ()" usage with "JSLINQ()" in JSLINQ.js file. Helps make file smaller and utilizes the new method of calling JSLINQ. 75 | - Replaced "index" variable name with "i" for iterator loops in JSLINQ.js. Just to make the file a little bit smaller. 76 | 77 | 78 | Version 2.10 (4/20/2015) 79 | ------------- 80 | - Modified the JSLINQ object to allow you to create an instance of JSLINQ containing an Array of elements 81 | using either of the following methods: 82 | var option1 = JSLINQ(myArray); 83 | var option2 = new JSLINQ(myArray); 84 | 85 | - Added an extensibility example; located at "/Examples/Extensions/get.htm" 86 | - Added Improved Intellisense Support and moved it to the "JSLINQ-vsdoc.js" file. 87 | 88 | 89 | Version 2.00 90 | ------------- 91 | - Removed use of "eval" method 92 | - Added an example of search an HTML DOM Table using JSLINQ 93 | - Placed all functionality within the global JSLINQ object. This is to improve possible compatibility with other 94 | javascript frameworks (like jQuery and ASP.NET AJAX). 95 | 96 | 97 | Version 1.03 98 | ------------ 99 | - Added Intersect Operator 100 | - Added DefaultIfEmpty Operator 101 | - Added ElementAtOrDefault Operator 102 | - Added FirstOrDefault Operator 103 | - Added LastOrDefault Operator 104 | - Started adding Usage Examples 105 | -- Count Word Occurrences 106 | -- Count Set of Words 107 | 108 | Version 1.02 109 | ------------ 110 | - A few Bug fixes that were revealed with Unit Tests 111 | - Interactive SDK Created 112 | - Unit Test Created 113 | --- Intial testing of the Samples Unit Tests yielded the following speed results for all tests: 114 | ------ IE7: ~10 milliseconds 115 | ------ FireFox 2: ~10 milliseconds 116 | ------ Safari 3 for Windows: ~4 milliseconds 117 | 118 | Version 1.01 119 | ------------ 120 | - Added the OrderByDescending Operator 121 | - Added the SelectMany Operator 122 | - Added the Count Operator 123 | - Added the Distinct Operator 124 | - Added the Any Operator 125 | - Added the All Operator 126 | - Made it so you can access the elements "index" within the clause/predicate of each of the following Operators: Where, Count, Any, All 127 | - Added the Reverse Operator, this also allows access to the elements "index" within the clause/predicate 128 | - Added First Operator, this also allows access to the elements "index" within the clause/predicate 129 | - Added Last Operator, this also allows access to the elements "index" within the clause/predicate 130 | - Added ElementAt Operator 131 | - Added Concat Operator - this is identical to JavaScripts Array.concat method 132 | 133 | Version 1.00 134 | ------------ 135 | Operators 136 | - From 137 | - Where 138 | - OrderBy 139 | - Select -------------------------------------------------------------------------------- /Website/Samples.htm: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | LINQ to JavaScript SDK - Samples 6 | 7 | 18 | 19 | 20 | 21 | 22 | 30 | 31 | 32 | 33 |

    LINQ to JavaScript - Samples

    34 |

    These are some basic samples of using JSLINQ to select/manipulate your JavaScript Arrays.

    35 | 36 | 37 | 47 | 67 | 68 |
    38 | JSLINQ v 39 |
      40 |
      41 |
      42 | Back... 43 |
      44 |
      45 | JSLINQ Project Homepage 46 |
      48 |

      49 |
      50 |
      51 |

      Code:


      52 |
      53 |
      54 | 55 | 56 | 60 | 64 | 65 |
      57 |

      Samples.People Source Array:


      58 |
      59 |
      61 |

      Results of JSLINQ Operation:


      62 |
      63 |
      66 |
      69 | 70 | 71 | -------------------------------------------------------------------------------- /Website/TestSamples.htm: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | LINQ to JavaScript - Samples Unit Tests 6 | 7 | 8 | 9 | 10 |

      LINQ to JavaScript - Test Samples

      11 | 12 | JSLINQ v 13 | 14 |

      This page performs automated unit tests on each of the JSLINQ Samples.
      Just click "Run Test" to start the Unit Tests. The results will be displayed below once they are finished.

      15 | Test Results:
      16 |

      17 |
      18 | Back... 19 | 20 | 23 | 24 | -------------------------------------------------------------------------------- /Website/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 10 | 11 | 12 | 13 | 21 | 22 | 28 | 29 | 36 | 48 | 49 | 50 | 54 | -------------------------------------------------------------------------------- /Website/scripts/JSLINQ-vsdoc.js: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------- 2 | // Visual Studio JavaScript Intellisense Helper for LINQ to JavaScript 3 | // LINQ to JavaScript (JSLINQ) Project - https://github.com/crpietschmann/jslinq 4 | // Copyright (c) 2012-2023 Chris Pietschmann (http://pietschsoft.com) 5 | // This license can be found here: https://github.com/crpietschmann/jslinq/blob/master/LICENSE 6 | //----------------------------------------------------------------------- 7 | JSLINQ = function(dataItems) { 8 | /// The JSLINQ Object that provides LINQ query syntax to work with JavaScript Arrays. 9 | /// The Array that this JSLINQ instance will work with. 10 | /// The internal Array that contains the actual data items. 11 | /// 12 | }; 13 | JSLINQ.prototype = { 14 | ToArray: function () { 15 | /// Gets the underlieing Array object that holds the data. 16 | /// 17 | }, 18 | Where: function (clause) { 19 | /// Filters a sequence of values based on a clause predicate. 20 | /// The clause used to determine query matches. 21 | /// 22 | }, 23 | Select: function (clause) { 24 | /// Projects each element of a sequence into a new form. 25 | /// The clause used to determine what values to select. Or a comma delimited string containing the object properties to select. 26 | /// 27 | }, 28 | OrderBy: function (clause) { 29 | /// Sorts the elements of a sequence in ascending order. 30 | /// The clause used to determine how to order the data. 31 | /// 32 | }, 33 | OrderByDescending: function (clause) { 34 | /// Sorts the elements of a sequence in descending order. 35 | /// The clause used to determine how to order the data. 36 | /// 37 | }, 38 | SelectMany: function (clause) { 39 | /// Projects each element of a sequence to a JSLINQ and flattens the resulting sequences into one sequence. 40 | /// The clause used to determine what values to select. 41 | /// 42 | }, 43 | Count: function (clause) { 44 | /// Returns the number of elements in a sequence. 45 | /// The clause used to determine what values to count. 46 | /// 47 | }, 48 | Distinct: function (clause) { 49 | /// Returns distinct elements from a sequence. 50 | /// The clause used to determine what values to select. 51 | /// 52 | }, 53 | Any: function (clause) { 54 | /// Determines whether any element of a sequence exists or satisfies a condition. 55 | /// The clause used to determine if a match exists. 56 | /// 57 | }, 58 | All: function (clause) { 59 | /// Determines whether all elements of a sequence satisfy a condition. 60 | /// The clause used to determine if a match exists. 61 | /// true if every element of the source sequence passes the test in the specified clause predicate, or if the sequence is empty; otherwise, false. 62 | }, 63 | Reverse: function () { 64 | /// Inverts the order of the elements in a sequence. 65 | /// 66 | }, 67 | First: function (clause) { 68 | /// Returns the first element of a sequence. 69 | /// The clause used to determine which group of elements to return the first element from. 70 | /// 71 | }, 72 | Last: function (clause) { 73 | /// Returns the last element of a sequence. 74 | /// The clause used to determine which group of elements to return the last element from. 75 | /// 76 | }, 77 | ElementAt: function (index) { 78 | /// Returns the element at a specified index in a sequence. 79 | /// The zero-based index of the element to retrieve. 80 | /// 81 | }, 82 | Concat: function (array) { 83 | /// Concatenates two sequences. (Is actually Idendical to the Array.concat method.) 84 | /// A JSLINQ or Array object that contains the elements to concatenate. 85 | /// 86 | }, 87 | Intersect: function (secondArray, clause) { 88 | /// Produces the set intersection of two sequences. 89 | /// The second JSLINQ element sequence to perform the Intersect on. 90 | /// 91 | /// 92 | }, 93 | DefaultIfEmpty: function (defaultValue) { 94 | /// Returns the JSLINQ object, or a default value if the sequence is empty. 95 | /// The default value to return if the sequence is empty. 96 | }, 97 | ElementAtOrDefault: function (index, defaultValue) { 98 | /// Returns the element at a specified index in a sequence or a default value if the index is out of range. 99 | /// The zero-based index of the element to retrieve. 100 | /// The default value to return if the index is out of range. 101 | /// defaultValue if the index is outside the bounds of the source sequence; otherwise, the element at the specified position in the source sequense. 102 | }, 103 | FirstOrDefault: function (defaultValue) { 104 | /// Returns the first element of a sequence, or a default value if no element is found. 105 | /// The default value to return if no element is found. 106 | }, 107 | LastOrDefault: function (defaultValue) { 108 | /// Returns the last element of a sequence, or a default value if no element is found. 109 | /// The default value to return if no element is found. 110 | }, 111 | Take: function (count) { 112 | /// Returns a specified number of contiguous elements from the start of a sequence. 113 | /// The number of elements to return. 114 | }, 115 | Skip: function (count) { 116 | /// Bypasses a specified number of elements in a sequence and then returns the remaining elements. 117 | /// The number of elements to skip before returning the remaining elements. 118 | }, 119 | Each: function (clause) { 120 | /// Executes a clause predicate on each element. 121 | /// The clause to execute on each element. 122 | }, 123 | Random: function (count) { 124 | /// This method will returns the specified number of elements at random. If no number is specified, then 1 is returned. 125 | /// The number of elements to return 126 | } 127 | }; -------------------------------------------------------------------------------- /Website/scripts/JSLINQ.js: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------- 2 | // LINQ to JavaScript (JSLINQ) Project - https://github.com/crpietschmann/jslinq 3 | // Copyright (c) 2012-2023 Chris Pietschmann (http://pietschsoft.com) 4 | // This license can be found here: https://github.com/crpietschmann/jslinq/blob/master/LICENSE 5 | //----------------------------------------------------------------------- 6 | (function () { 7 | var JSLINQ = window.jslinq = window.JSLINQ = function (dataItems) { 8 | return new JSLINQ.fn.init(dataItems); 9 | }, 10 | utils = { 11 | processLambda: function (clause) { 12 | if (utils.isLambda(clause)) { 13 | var expr = clause.match(/^[(\s]*([^()]*?)[)\s]*=>(.*)/); 14 | return new Function(expr[1], "return (" + expr[2] + ")"); 15 | } 16 | return clause; 17 | }, 18 | isLambda: function (clause) { 19 | return (clause.indexOf("=>") > -1); 20 | }, 21 | randomIndex: function (max, existing) { 22 | var q, r, f = function () { return this == r; }; 23 | if (!existing) { 24 | return parseInt(Math.random() * max, 10); 25 | } else { 26 | q = JSLINQ(existing); 27 | r = -1; 28 | while (r < 0 || q.Where(f).Count() !== 0) { 29 | r = utils.randomIndex(max); 30 | } 31 | return r; 32 | } 33 | } 34 | }; 35 | JSLINQ.fn = JSLINQ.prototype = { 36 | init: function (dataItems) { 37 | this.items = dataItems; 38 | }, 39 | 40 | // The current version of JSLINQ being used 41 | jslinq: '2.30', 42 | 43 | toArray: function () { return this.items; }, 44 | forEach: function (callback) { 45 | this.items.forEach(callback); 46 | return this; 47 | }, 48 | where: function (clause) { 49 | var newArray = []; 50 | // The clause was passed in as a Method that return a Boolean 51 | this.forEach((item, i) => { 52 | if (clause.apply(item, [item, i])) newArray[newArray.length] = item; 53 | }); 54 | return JSLINQ(newArray); 55 | }, 56 | select: function (clause) { 57 | var newArray = [], field = clause; 58 | if (typeof (clause) !== "function") { 59 | if (clause.indexOf(",") === -1) { 60 | clause = function () { return this[field]; }; 61 | } else { 62 | clause = function () { 63 | var obj = {}; 64 | field.split(',').forEach((f) => { 65 | obj[f] = this[f]; 66 | }); 67 | return obj; 68 | }; 69 | } 70 | } 71 | 72 | // The clause was passed in as a Method that returns a Value 73 | this.forEach((item, i) => { 74 | val = clause.apply(item, [item]); 75 | if (val) newArray[newArray.length] = val; 76 | }); 77 | return JSLINQ(newArray); 78 | }, 79 | orderBy: function (clause) { 80 | var tempArray = []; 81 | this.forEach((item) => { 82 | tempArray.push(item); 83 | }); 84 | 85 | if (typeof (clause) !== "function") { 86 | var field = clause; 87 | if (utils.isLambda(field)) { 88 | clause = utils.processLambda(field); 89 | } else { 90 | clause = function () { return this[field]; }; 91 | } 92 | } 93 | 94 | return JSLINQ(tempArray.sort(function (a, b) { 95 | var x = clause.apply(a, [a]), y = clause.apply(b, [b]); 96 | return ((x < y) ? -1 : ((x > y) ? 1 : 0)); 97 | }) 98 | ); 99 | }, 100 | orderByDescending: function (clause) { 101 | var tempArray = [], field; 102 | this.forEach((item) => { 103 | tempArray.push(item); 104 | }); 105 | 106 | if (typeof (clause) !== "function") { 107 | field = clause; 108 | if (utils.isLambda(field)) { 109 | clause = utils.processLambda(field); 110 | } else { 111 | clause = function () { return this[field]; }; 112 | } 113 | } 114 | 115 | return JSLINQ(tempArray.sort(function (a, b) { 116 | var x = clause.apply(b, [b]), y = clause.apply(a, [a]); 117 | return ((x < y) ? -1 : ((x > y) ? 1 : 0)); 118 | })); 119 | }, 120 | selectMany: function (clause) { 121 | var r = []; 122 | this.forEach((item) => { 123 | r = r.concat(clause.apply(item, [item])); 124 | }); 125 | return JSLINQ(r); 126 | }, 127 | count: function (clause) { 128 | if (clause === undefined) { 129 | return this.items.length; 130 | } 131 | return this.Where(clause).items.length; 132 | }, 133 | distinct: function (clause) { 134 | var dict = {}, retVal = []; 135 | this.forEach((item) => { 136 | var val = clause.apply(item, [item]); 137 | // TODO - This doesn't correctly compare Objects. Need to fix this 138 | if (dict[val] === undefined) { 139 | dict[val] = true; 140 | retVal.push(val); 141 | } 142 | }); 143 | dict = null; 144 | return JSLINQ(retVal); 145 | }, 146 | any: function (clause) { 147 | var item; 148 | for (var i = 0; i < this.items.length; i++) { 149 | item = this.items[i]; 150 | if (clause.apply(item, [item, i])) return true; 151 | } 152 | return false; 153 | }, 154 | all: function (clause) { 155 | for (var i = 0; i < this.items.length; i++) { 156 | if (!clause(this.items[i], i)) return false; 157 | } 158 | return true; 159 | }, 160 | reverse: function () { 161 | var retVal = []; 162 | for (var i = this.items.length - 1; i > -1; i--) { 163 | retVal[retVal.length] = this.items[i]; 164 | } 165 | return JSLINQ(retVal); 166 | }, 167 | first: function (clause) { 168 | if (clause !== undefined) { 169 | return this.Where(clause).First(); 170 | } else if (this.items.length > 0) { 171 | // If no clause was specified, then return the First element in the Array 172 | return this.items[0]; 173 | } 174 | return null; 175 | }, 176 | last: function (clause) { 177 | if (clause !== undefined) { 178 | return this.Where(clause).Last(); 179 | } else { 180 | // If no clause was specified, then return the First element in the Array 181 | if (this.items.length > 0) { 182 | return this.items[this.items.length - 1]; 183 | } 184 | } 185 | return null; 186 | }, 187 | elementAt: function (i) { 188 | return this.items[i]; 189 | }, 190 | concat: function (array) { 191 | var arr = array.items || array; 192 | return JSLINQ(this.items.concat(arr)); 193 | }, 194 | intersect: function (secondArray, clause) { 195 | var method, sa = (secondArray.items || secondArray), result = []; 196 | if (clause !== undefined) { 197 | method = clause; 198 | } else { 199 | method = (item, i1, item2, i2) => item === item2; 200 | } 201 | 202 | for (var a = 0; a < this.items.length; a++) { 203 | for (var b = 0; b < sa.length; b++) { 204 | if (method(this.items[a], a, sa[b], b)) { 205 | result[result.length] = this.items[a]; 206 | } 207 | } 208 | } 209 | return JSLINQ(result); 210 | }, 211 | defaultIfEmpty: function (defaultValue) { 212 | if (this.items.length === 0) { 213 | return defaultValue; 214 | } 215 | return this; 216 | }, 217 | elementAtOrDefault: function (i, defaultValue) { 218 | if (i >= 0 && i < this.items.length) { 219 | return this.items[i]; 220 | } 221 | return defaultValue; 222 | }, 223 | firstOrDefault: function (defaultValue) { 224 | return this.First() || defaultValue; 225 | }, 226 | lastOrDefault: function (defaultValue) { 227 | return this.Last() || defaultValue; 228 | }, 229 | take: function (count) { 230 | return this.Where(function (item, index) { return index < count; }); 231 | }, 232 | skip: function (count) { 233 | return this.Where(function (item, index) { return index >= count; }); 234 | }, 235 | each: function (clause) { 236 | var len = this.items.length; 237 | for (var i = 0; i < len; i++) { 238 | clause.apply(this.items[i], [this.items[i], i]); 239 | } 240 | return this; 241 | }, 242 | random: function (count) { 243 | var len = this.Count(), rnd = []; 244 | if (!count) { count = 1; } 245 | for (var i = 0; i < count; i++) { 246 | rnd.push(utils.randomIndex(len - 1, rnd)); 247 | } 248 | rnd = JSLINQ(rnd); 249 | return this.Where(function (item, index) { 250 | return rnd.Where(function () { 251 | return this == index; 252 | }).Count() > 0; 253 | }); 254 | } 255 | }; 256 | 257 | (function (fn) { 258 | fn.ToArray = fn.toArray; 259 | fn.ForEach = fn.forEach; 260 | fn.Where = fn.where; 261 | fn.Select = fn.select; 262 | fn.OrderBy = fn.orderBy; 263 | fn.OrderByDescending = fn.orderByDescending; 264 | fn.SelectMany = fn.selectMany; 265 | fn.Count = fn.count; 266 | fn.Distinct = fn.distinct; 267 | fn.Any = fn.any; 268 | fn.All = fn.all; 269 | fn.Reverse = fn.reverse; 270 | fn.First = fn.first; 271 | fn.Last = fn.last; 272 | fn.ElementAt = fn.elementAt; 273 | fn.Concat = fn.concat; 274 | fn.Intersect = fn.intersect; 275 | fn.DefaultIfEmpty = fn.defaultIfEmpty; 276 | fn.ElementAtOrDefault = fn.elementAtOrDefault; 277 | fn.FirstOrDefault = fn.firstOrDefault; 278 | fn.LastOrDefault = fn.lastOrDefault; 279 | fn.Take = fn.take; 280 | fn.Skip = fn.skip; 281 | fn.Each = fn.each; 282 | fn.Random = fn.random; 283 | })(JSLINQ.fn); 284 | 285 | JSLINQ.fn.init.prototype = JSLINQ.fn; 286 | })(); -------------------------------------------------------------------------------- /Website/scripts/Samples.js: -------------------------------------------------------------------------------- 1 | /// 2 | //----------------------------------------------------------------------- 3 | // Part of the LINQ to JavaScript (JSLINQ) v2.x Project - https://github.com/crpietschmann/jslinq 4 | // Copyright (C) 2012-2023 Chris Pietschmann (http://pietschsoft.com) 5 | // This license can be found here: https://github.com/crpietschmann/jslinq/blob/master/LICENSE 6 | //----------------------------------------------------------------------- 7 | var Samples = {}; 8 | 9 | /* *** Arrays that Sample Code Uses *** */ 10 | Samples.People = [ 11 | { ID: 1, FirstName: "Chris", LastName: "Pearson", BookIDs: [1001, 1002, 1003] }, 12 | { ID: 2, FirstName: "Kate", LastName: "Johnson", BookIDs: [2001, 2002, 2003] }, 13 | { ID: 3, FirstName: "Josh", LastName: "Sutherland", BookIDs: [3001, 3002, 3003] }, 14 | { ID: 4, FirstName: "John", LastName: "Ronald", BookIDs: [4001, 4002, 4003] }, 15 | { ID: 5, FirstName: "Steve", LastName: "Pinkerton", BookIDs: [1001, 1002, 1003] }, 16 | { ID: 6, FirstName: "Katie", LastName: "Zimmerman", BookIDs: [2001, 2002, 2003] }, 17 | { ID: 7, FirstName: "Dirk", LastName: "Anderson", BookIDs: [3001, 3002, 3003] }, 18 | { ID: 8, FirstName: "Chris", LastName: "Stevenson", BookIDs: [4001, 4002, 4003] }, 19 | { ID: 9, FirstName: "Bernard", LastName: "Sutherland", BookIDs: [1001, 2002, 3003] }, 20 | { ID: 10, FirstName: "Kate", LastName: "Pinkerton", BookIDs: [4001, 3002, 2003] } 21 | ]; 22 | 23 | /* *** Array of Samples Contained in this page *** */ 24 | Samples.SampleList = [ 25 | { Group: "Where Operator", Samples: ["Samples.Where01", "Samples.Where02", "Samples.Where03"] }, 26 | { Group: "Select Operator", Samples: ["Samples.Select01", "Samples.Select02", "Samples.Select03"] }, 27 | { Group: "SelectMany Operator", Samples: ["Samples.SelectMany01"] }, 28 | { Group: "OrderBy Operator", Samples: ["Samples.OrderBy01", "Samples.OrderBy02", "Samples.OrderBy03"] }, 29 | { Group: "OrderByDescending Operator", Samples: ["Samples.OrderByDescending01", "Samples.OrderByDescending02", "Samples.OrderByDescending03"] }, 30 | { Group: "All Operator", Samples: ["Samples.All01", "Samples.All02"] }, 31 | { Group: "Any Operator", Samples: ["Samples.Any01", "Samples.Any02"] }, 32 | { Group: "Count Operator", Samples: ["Samples.Count01", "Samples.Count02", "Samples.Count03"] }, 33 | { Group: "DefaultIfEmpty Operator", Samples: ["Samples.DefaultIfEmpty01", "Samples.DefaultIfEmpty02"] }, 34 | { Group: "Distinct Operator", Samples: ["Samples.Distinct01"] }, 35 | { Group: "ElementAt Operator", Samples: ["Samples.ElementAt01"] }, 36 | { Group: "ElementAtOrDefault Operator", Samples: ["Samples.ElementAtOrDefault01"] }, 37 | { Group: "First Operator", Samples: ["Samples.First01", "Samples.First02"] }, 38 | { Group: "FirstOrDefault Operator", Samples: ["Samples.FirstOrDefault01"] }, 39 | { Group: "Intersect Operator", Samples: ["Samples.Intersect01", "Samples.Intersect02", "Samples.Intersect03"] }, 40 | { Group: "Last Operator", Samples: ["Samples.Last01", "Samples.Last02"] }, 41 | { Group: "LastOrDefault Operator", Samples: ["Samples.LastOrDefault01"] }, 42 | { Group: "Reverse Operator", Samples: ["Samples.Reverse01"] }, 43 | { Group: "Take", Samples: ["Samples.Take01"] }, 44 | { Group: "Skip", Samples: ["Samples.Skip01"] }, 45 | { Group: "Each", Samples: ["Samples.Each01"] }, 46 | { Group: "Random", Samples: ["Samples.Random01", "Samples.Random02"] }, 47 | { Group: "Other Unit Tests", Samples: ["Samples.OtherUnitTests01","Samples.OtherUnitTests02","Samples.OtherUnitTests03"] } 48 | ]; 49 | 50 | 51 | /* *** Code used for executing and showing the samples in the page *** */ 52 | Samples.ShowSampleList = function() { 53 | var sampleList = document.getElementById("SampleList"); 54 | for (var g = 0; g < Samples.SampleList.length; g++) { 55 | var group = document.createElement("li"); 56 | group.innerHTML = Samples.SampleList[g].Group; 57 | sampleList.appendChild(group); 58 | group = document.createElement("ul"); 59 | 60 | for (var s = 0; s < Samples.SampleList[g].Samples.length; s++) { 61 | var sample = eval("new " + Samples.SampleList[g].Samples[s] + "()"); 62 | 63 | var sampleElement = document.createElement("li"); 64 | sampleElement.innerHTML = "" + sample.Name + ""; 65 | group.appendChild(sampleElement); 66 | } 67 | 68 | sampleList.appendChild(group); 69 | } 70 | }; 71 | Samples.ShowSourceData = function(){ 72 | document.getElementById("SourceData").innerHTML = Samples.Views.People(Samples.People); 73 | }; 74 | Samples.Show = function(sample) { 75 | if (typeof sample === "string") { sample = eval(sample); } 76 | var s = new sample(); 77 | // Display Sample Name, Description and Code on the page 78 | document.getElementById("lblSampleTitle").innerHTML = s.Title; 79 | document.getElementById("lblSampleDescription").innerHTML = s.Description; 80 | document.getElementById("txtSampleCode").value = s.Code; 81 | // Execute the Sample to prove it works 82 | var results = s.Code(); 83 | document.getElementById("ResultData").innerHTML = s.View(results.items || results); 84 | }; 85 | Samples.RunTests = function(){ 86 | var failureCount = 0; 87 | var successCount = 0; 88 | var strFailedTest = ""; 89 | 90 | var start = (new Date()).getTime(); 91 | 92 | Samples.SampleList.forEach((sampleList) => { 93 | sampleList.Samples.forEach((sample) => { 94 | var s = eval("new " + sample + "()"); 95 | try { 96 | var result = s.Test(); 97 | if (result) { 98 | successCount++; 99 | } else { 100 | failureCount++; 101 | strFailedTest += sample + "
      "; 102 | } 103 | } catch (error) { 104 | console.error(`Unit Test: ${sample} - ${error}`); 105 | failureCount++; 106 | strFailedTest += sample + "
      "; 107 | } 108 | }); 109 | }); 110 | 111 | var end = (new Date()).getTime(); 112 | 113 | var elem = document.getElementById("TestResults"); 114 | elem.innerHTML = "Successes: " + successCount + " - Failures: " + failureCount + " - Timing: " + (end - start); 115 | if (failureCount > 0) { 116 | elem.innerHTML += "
      Failed Tests:
      " + strFailedTest; 117 | } 118 | }; 119 | 120 | Samples.Views = {}; 121 | Samples.Views.People = function(people) { 122 | var str = ""; 123 | if (people.length == undefined) 124 | { 125 | /// If the length of the people array is undefined, then it's not an array but a Person object instead. 126 | str += ""; 127 | } 128 | else 129 | { 130 | for(var i = 0; i < people.length; i++){ 131 | str += ""; 132 | } 133 | } 134 | str += "
      IDFirst NameLast NameBooks
      " + people.ID + "" + people.FirstName + "" + people.LastName + "" + Samples.Views.StringArray(people.BookIDs) + "
      " + people[i].ID + "" + people[i].FirstName + "" + people[i].LastName + "" + Samples.Views.StringArray(people[i].BookIDs) + "
      "; 135 | return str; 136 | }; 137 | Samples.Views.ObjectArray = function (array) { 138 | if (array.length == 0) { 139 | return ""; 140 | } else { 141 | var str = ""; 142 | for (var a in array[0]) { 143 | str += ""; 144 | } 145 | str += ""; 146 | for (var i = 0; i < array.length; i++) { 147 | str += ""; 148 | for (var f in array[i]) { 149 | str += ""; 150 | } 151 | str += ""; 152 | } 153 | str += "
      " + a + "
      " + array[i][f] + "
      "; 154 | return str; 155 | } 156 | }; 157 | Samples.Views.StringArray = function(strArray) { 158 | var str = ""; 159 | for(var i = 0; i < strArray.length; i++){ 160 | str += ""; 161 | } 162 | str += "
      " + strArray[i] + "
      "; 163 | return str; 164 | }; 165 | Samples.Views.Count = function(b) { 166 | return "Count: " + b.toString(); 167 | }; 168 | Samples.Views.Boolean = function(b) { 169 | return b.toString(); 170 | }; 171 | Samples.Views.String = function(str){ 172 | return str; 173 | }; 174 | 175 | 176 | 177 | /* *** Where Operator Samples *** */ 178 | Samples.Where01 = function(){ 179 | this.Name = "Basic Function Clause"; 180 | this.Title = "Where Operator: " + this.Name; 181 | this.Description = "This is the most basic example of using the Where Operator by passing in a function for the operator clause."; 182 | this.View = Samples.Views.People; 183 | }; 184 | Samples.Where01.prototype = { 185 | Code: function() { 186 | var sample = JSLINQ(Samples.People). 187 | Where((item) => item.FirstName == 'Chris'); 188 | return sample; 189 | }, 190 | Test:function(){ 191 | var r = this.Code().items; 192 | return (r.length == 2); 193 | } 194 | }; 195 | 196 | Samples.Where02 = function(){ 197 | this.Name = "Reference Item Index"; 198 | this.Title = "Where Operator: " + this.Name; 199 | this.Description = "This is the most basic example of using the Where Operator by passing in a function for the operator clause, and referencing the Array items index within the clause."; 200 | this.View = Samples.Views.People; 201 | }; 202 | Samples.Where02.prototype = { 203 | Code:function(){ 204 | var sample = JSLINQ(Samples.People). 205 | Where(function(item, index){return item.FirstName == 'Chris' && index == 0;}); 206 | return sample; 207 | }, 208 | Test:function(){ 209 | var r = this.Code().items; 210 | return (r.length == 1); 211 | } 212 | }; 213 | 214 | Samples.Where03 = function () { 215 | this.Name = "Nested Where Clause"; 216 | this.Title = "Where Operator: " + this.Name; 217 | this.Description = "This example takes '.Where' a little further by querying all People whos BookIDs property contains the value of 1002. This is essentially a nested JSLINQ query."; 218 | this.View = Samples.Views.People; 219 | }; 220 | Samples.Where03.prototype = { 221 | Code: function () { 222 | var sample = JSLINQ(Samples.People). 223 | Where((item, index) => { 224 | return JSLINQ(item.BookIDs) 225 | .Where((item) => item == 1002) 226 | .Count() > 0; 227 | }); 228 | return sample; 229 | }, 230 | Test: function () { 231 | var r = this.Code().items; 232 | return (r.length == 2); 233 | } 234 | }; 235 | 236 | /* *** Select Operator *** */ 237 | Samples.Select01 = function(){ 238 | this.Name = "Basic Function Clause"; 239 | this.Title = "Select Operator: " + this.Name; 240 | this.Description = "This is the most basic example of using the Select Operator by passing in a function for the operator clause."; 241 | this.View = Samples.Views.StringArray; 242 | }; 243 | Samples.Select01.prototype = { 244 | Code: function(){ 245 | var sample = JSLINQ(Samples.People). 246 | Select((x) => x.FirstName); 247 | return sample; 248 | }, 249 | Test: function(){ 250 | var r = this.Code().items; 251 | return (r.length == 10 && typeof(r[0]) == 'string'); 252 | } 253 | }; 254 | 255 | Samples.Select02 = function() { 256 | this.Name = "Basic - Pass field as string"; 257 | this.Title = "Select Operator: " + this.Name; 258 | this.Description = "This example shows using the Select Operator by passing in a single field/property to select as a string."; 259 | this.View = Samples.Views.StringArray; 260 | }; 261 | Samples.Select02.prototype = { 262 | Code: function() { 263 | var sample = JSLINQ(Samples.People). 264 | Select("FirstName"); 265 | return sample; 266 | }, 267 | Test: function() { 268 | 269 | var r = this.Code().items; 270 | return (r.length == 10 && typeof (r[0]) == 'string'); 271 | 272 | } 273 | }; 274 | 275 | Samples.Select03 = function () { 276 | this.Name = "Basic - Pass many fields as string"; 277 | this.Title = "Select Operator: " + this.Name; 278 | this.Description = "This example shows using the Select Operator by passing in multiple fields/properties to select as an object."; 279 | this.View = Samples.Views.ObjectArray; 280 | }; 281 | Samples.Select03.prototype = { 282 | Code: function () { 283 | var sample = JSLINQ(Samples.People). 284 | Select("ID,FirstName,LastName"); 285 | return sample; 286 | }, 287 | Test: function () { 288 | var r = this.Code().items; 289 | return (r.length == 10 && 290 | r[0].ID == 1 && 291 | r[1].ID == 2 && 292 | r[2].ID == 3 && 293 | r[3].ID == 4 && 294 | r[4].ID == 5 && 295 | r[5].ID == 6 && 296 | r[6].ID == 7 && 297 | r[7].ID == 8 && 298 | r[8].ID == 9 && 299 | r[9].ID == 10); 300 | } 301 | }; 302 | 303 | 304 | /* *** SelectMany Operator * ***/ 305 | Samples.SelectMany01 = function(){ 306 | this.Name = "Basic Function Clause"; 307 | this.Title = "SelectMany Operator: " + this.Name; 308 | this.Description = "This is the most basic example of using the SelectMany Operator by passing in a function for the operator clause."; 309 | this.View = Samples.Views.StringArray; 310 | }; 311 | Samples.SelectMany01.prototype = { 312 | Code:function(){ 313 | var sample = JSLINQ(Samples.People). 314 | SelectMany((item) => item.BookIDs); 315 | return sample; 316 | }, 317 | Test:function(){ 318 | try 319 | { 320 | var r = this.Code().items; 321 | return (r.length == 30 && typeof(r[0]) == 'number'); 322 | } 323 | catch(ex) 324 | { 325 | return false; 326 | } 327 | } 328 | }; 329 | 330 | /* *** OrderBy Operator *** */ 331 | Samples.OrderBy01 = function(){ 332 | this.Name = "Basic Function Clause"; 333 | this.Title = "Select Operator: " + this.Name; 334 | this.Description = "This is the most basic example of using the OrderBy Operator by passing in a function
      for the operator clause."; 335 | this.View = Samples.Views.People; 336 | }; 337 | Samples.OrderBy01.prototype = { 338 | Code:function(){ 339 | var sample = JSLINQ(Samples.People). 340 | OrderBy(function(){return this.FirstName;}); 341 | return sample; 342 | }, 343 | Test:function(){ 344 | try 345 | { 346 | var r = this.Code().items; 347 | return (r.length == 10 && r[0].FirstName == "Bernard" && r[r.length - 1].FirstName == "Steve"); 348 | } 349 | catch(ex) 350 | { 351 | return false; 352 | } 353 | } 354 | }; 355 | 356 | Samples.OrderBy02 = function() { 357 | this.Name = "Basic - Pass in 'field' name"; 358 | this.Title = "Select Operator: " + this.Name; 359 | this.Description = "This example of using the OrderBy Operator demonstrates passing in the field to order by as a string."; 360 | this.View = Samples.Views.People; 361 | }; 362 | Samples.OrderBy02.prototype = { 363 | Code: function() { 364 | var sample = JSLINQ(Samples.People). 365 | OrderBy("FirstName"); 366 | return sample; 367 | }, 368 | Test: function() { 369 | try { 370 | var r = this.Code().items; 371 | return (r.length == 10 && r[0].FirstName == "Bernard" && r[r.length - 1].FirstName == "Steve"); 372 | } 373 | catch (ex) { 374 | return false; 375 | } 376 | } 377 | }; 378 | 379 | Samples.OrderBy03 = function() { 380 | this.Name = "Basic Lambda"; 381 | this.Title = "Select Operator: " + this.Name; 382 | this.Description = ""; 383 | this.View = Samples.Views.People; 384 | }; 385 | Samples.OrderBy03.prototype = { 386 | Code: function() { 387 | var sample = JSLINQ(Samples.People). 388 | OrderBy("item => item.FirstName"); 389 | return sample; 390 | }, 391 | Test: function() { 392 | try { 393 | var r = this.Code().items; 394 | return (r.length == 10 && r[0].FirstName == "Bernard" && r[r.length - 1].FirstName == "Steve"); 395 | } 396 | catch (ex) { 397 | return false; 398 | } 399 | } 400 | }; 401 | 402 | /* *** OrderByDescending Operator *** */ 403 | Samples.OrderByDescending01 = function(){ 404 | this.Name = "Basic Function Clause"; 405 | this.Title = "Select Operator: " + this.Name; 406 | this.Description = "This is the most basic example of using the OrderByDescending Operator by passing in a function for the operator clause."; 407 | this.View = Samples.Views.People; 408 | }; 409 | Samples.OrderByDescending01.prototype = { 410 | Code:function(){ 411 | var sample = JSLINQ(Samples.People). 412 | OrderByDescending(function(){return this.FirstName;}); 413 | return sample; 414 | }, 415 | Test:function(){ 416 | try 417 | { 418 | var r = this.Code().items; 419 | return (r.length == 10 && r[0].FirstName == "Steve" && r[r.length - 1].FirstName == "Bernard"); 420 | } 421 | catch(ex) 422 | { 423 | return false; 424 | } 425 | } 426 | }; 427 | 428 | Samples.OrderByDescending02 = function() { 429 | this.Name = "Basic - Pass in 'field' name"; 430 | this.Title = "Select Operator: " + this.Name; 431 | this.Description = "This example of using the OrderByDescending Operator demonstrates passing in the field to order by as a string."; 432 | this.View = Samples.Views.People; 433 | }; 434 | Samples.OrderByDescending02.prototype = { 435 | Code: function() { 436 | var sample = JSLINQ(Samples.People). 437 | OrderByDescending("FirstName"); 438 | return sample; 439 | }, 440 | Test: function() { 441 | try { 442 | var r = this.Code().items; 443 | return (r.length == 10 && r[0].FirstName == "Steve" && r[r.length - 1].FirstName == "Bernard"); 444 | } 445 | catch (ex) { 446 | return false; 447 | } 448 | } 449 | }; 450 | 451 | Samples.OrderByDescending03 = function() { 452 | this.Name = "Basic Lambda"; 453 | this.Title = "Select Operator: " + this.Name; 454 | this.Description = ""; 455 | this.View = Samples.Views.People; 456 | }; 457 | Samples.OrderByDescending03.prototype = { 458 | Code: function() { 459 | var sample = JSLINQ(Samples.People). 460 | OrderByDescending("item => item.FirstName"); 461 | return sample; 462 | }, 463 | Test: function() { 464 | try { 465 | var r = this.Code().items; 466 | return (r.length == 10 && r[0].FirstName == "Steve" && r[r.length - 1].FirstName == "Bernard"); 467 | } 468 | catch (ex) { 469 | return false; 470 | } 471 | } 472 | }; 473 | 474 | /* *** Count Operator *** */ 475 | Samples.Count01 = function(){ 476 | this.Name = "Basic Usage"; 477 | this.Title = "Count Operator: " + this.Name; 478 | this.Description = "This is the most basic example of using the Count Operator."; 479 | this.View = Samples.Views.Count; 480 | }; 481 | Samples.Count01.prototype = { 482 | Code:function(){ 483 | var sample = JSLINQ(Samples.People).Count(); 484 | return sample; 485 | }, 486 | Test:function(){ 487 | try 488 | { 489 | var r = this.Code(); 490 | return (r == 10); 491 | } 492 | catch(ex) 493 | { 494 | return false; 495 | } 496 | } 497 | }; 498 | 499 | Samples.Count02 = function(){ 500 | this.Name = "Basic Function Clause"; 501 | this.Title = "Count Operator: " + this.Name; 502 | this.Description = "This is the most basic example of using the Count Operator by passing in a function for the operator clause."; 503 | this.View = Samples.Views.Count; 504 | }; 505 | Samples.Count02.prototype = { 506 | Code:function(){ 507 | var sample = JSLINQ(Samples.People). 508 | Count(function(){return this.FirstName == 'Chris';}); 509 | return sample; 510 | }, 511 | Test:function(){ 512 | try 513 | { 514 | var r = this.Code(); 515 | return (r == 2); 516 | } 517 | catch(ex) 518 | { 519 | return false; 520 | } 521 | } 522 | }; 523 | 524 | Samples.Count03 = function(){ 525 | this.Name = "Function Clause - Reference Item Index"; 526 | this.Title = "Count Operator: " + this.Name; 527 | this.Description = "This is the most basic example of using the Count Operator by passing in a function for the operator clause, and referencing the Array items index within the clause."; 528 | this.View = Samples.Views.Count; 529 | }; 530 | Samples.Count03.prototype = { 531 | Code:function(){ 532 | var sample = JSLINQ(Samples.People). 533 | Count(function(item, index){return item.FirstName == 'Chris' && index == 4;}); 534 | return sample; 535 | }, 536 | Test:function(){ 537 | try 538 | { 539 | var r = this.Code(); 540 | return (r == 0); 541 | } 542 | catch(ex) 543 | { 544 | return false; 545 | } 546 | } 547 | }; 548 | 549 | 550 | /* *** Distinct Operator *** */ 551 | Samples.Distinct01 = function(){ 552 | this.Name = "Basic Function Clause"; 553 | this.Title = "Distinct Operator: " + this.Name; 554 | this.Description = "This is the most basic example of using the Distinct Operator by passing in a function for the operator clause."; 555 | this.View = Samples.Views.StringArray; 556 | }; 557 | Samples.Distinct01.prototype = { 558 | Code:function(){ 559 | var sample = JSLINQ(Samples.People). 560 | Distinct(function(){return this.FirstName;}); 561 | return sample; 562 | }, 563 | Test:function(){ 564 | var r = this.Code().items; 565 | return (r.length == 8); 566 | } 567 | }; 568 | 569 | 570 | 571 | /* *** Any Operator *** */ 572 | Samples.Any01 = function(){ 573 | this.Name = "Basic Function Clause"; 574 | this.Title = "Any Operator: " + this.Name; 575 | this.Description = "This is the most basic example of using the Any Operator by passing in a function for the operator clause."; 576 | this.View = Samples.Views.Boolean; 577 | }; 578 | Samples.Any01.prototype = { 579 | Code:function(){ 580 | var sample = JSLINQ(Samples.People).Any(function() { return this.FirstName == 'Chris' }); 581 | return sample; 582 | }, 583 | Test:function(){ 584 | return (this.Code() == true); 585 | } 586 | }; 587 | 588 | Samples.Any02 = function(){ 589 | this.Name = "Function Clause - Reference Item Index"; 590 | this.Title = "Any Operator: " + this.Name; 591 | this.Description = "This is the most basic example of using the Any Operator by passing in a function for the operator clause, and referencing the Array items index within the clause."; 592 | this.View = Samples.Views.Boolean; 593 | }; 594 | Samples.Any02.prototype = { 595 | Code:function(){ 596 | var sample = JSLINQ(Samples.People).Any(function(item, index) { return item.FirstName == 'Chris' && index == 4 }); 597 | return sample; 598 | }, 599 | Test:function(){ 600 | try 601 | { 602 | return (this.Code() == false); 603 | } 604 | catch(ex) 605 | { 606 | return false; 607 | } 608 | } 609 | }; 610 | 611 | /* *** All Operator *** */ 612 | Samples.All01 = function(){ 613 | this.Name = "Basic Function Clause"; 614 | this.Title = "All Operator: " + this.Name; 615 | this.Description = "This is the most basic example of using the All Operator by passing in a function for the operator clause."; 616 | this.View = Samples.Views.Boolean; 617 | }; 618 | Samples.All01.prototype = { 619 | Code:function(){ 620 | var sample = JSLINQ(Samples.People).All(function() { return this.FirstName == 'Chris' }); 621 | return sample; 622 | }, 623 | Test:function(){ 624 | try 625 | { 626 | return (this.Code() == false); 627 | } 628 | catch(ex) 629 | { 630 | return false; 631 | } 632 | } 633 | }; 634 | 635 | Samples.All02 = function(){ 636 | this.Name = "Function Clause - Reference Item Index"; 637 | this.Title = "All Operator: " + this.Name; 638 | this.Description = "This is the most basic example of using the All Operator by passing in a function for the operator clause, and referencing the Array items index within the clause."; 639 | this.View = Samples.Views.Boolean; 640 | }; 641 | Samples.All02.prototype = { 642 | Code:function(){ 643 | var sample = JSLINQ(Samples.People).All(function(item, index) { return item.FirstName == 'Chris' && index == 0 }); 644 | return sample; 645 | }, 646 | Test:function(){ 647 | try 648 | { 649 | return (this.Code() == false); 650 | } 651 | catch(ex) 652 | { 653 | return false; 654 | } 655 | } 656 | }; 657 | 658 | 659 | 660 | /* *** Reverse Operator * ***/ 661 | Samples.Reverse01 = function(){ 662 | this.Name = "Basic Usage"; 663 | this.Title = "Reverse Operator: " + this.Name; 664 | this.Description = "This is the most basic example of using the Reverse Operator by passing in a string for the operator clause."; 665 | this.View = Samples.Views.People; 666 | }; 667 | Samples.Reverse01.prototype = { 668 | Code:function(){ 669 | var sample = JSLINQ(Samples.People).Reverse(); 670 | return sample; 671 | }, 672 | Test:function(){ 673 | try 674 | { 675 | var r = this.Code().items; 676 | return (r.length == 10 && r[0].FirstName == "Kate" && r[r.length - 1].FirstName == "Chris"); 677 | } 678 | catch(ex) 679 | { 680 | return false; 681 | } 682 | } 683 | }; 684 | 685 | 686 | 687 | /* *** First Operator * ***/ 688 | Samples.First01 = function(){ 689 | this.Name = "Basic Function Clause"; 690 | this.Title = "First Operator: " + this.Name; 691 | this.Description = "This is the most basic example of using the First Operator by passing in a function for the operator clause."; 692 | this.View = Samples.Views.People; 693 | }; 694 | Samples.First01.prototype = { 695 | Code:function(){ 696 | var sample = JSLINQ(Samples.People).First(function() { return this.FirstName == 'Chris' }); 697 | return sample; 698 | }, 699 | Test:function(){ 700 | try 701 | { 702 | var r = this.Code(); 703 | return (r.FirstName == "Chris" && r.ID == 1); 704 | } 705 | catch(ex) 706 | { 707 | return false; 708 | } 709 | } 710 | }; 711 | 712 | Samples.First02 = function(){ 713 | this.Name = "Function Clause - Reference Item Index"; 714 | this.Title = "First Operator: " + this.Name; 715 | this.Description = "This is the most basic example of using the First Operator by passing in a function for the operator clause, and referencing the Array items index within the clause."; 716 | this.View = Samples.Views.People; 717 | }; 718 | Samples.First02.prototype = { 719 | Code:function(){ 720 | var sample = JSLINQ(Samples.People).First(function(item, index) { return item.FirstName == 'Chris' && index == 0 }); 721 | return sample; 722 | }, 723 | Test:function(){ 724 | try 725 | { 726 | var r = this.Code(); 727 | return (r.FirstName == "Chris" && r.ID == 1); 728 | } 729 | catch(ex) 730 | { 731 | return false; 732 | } 733 | } 734 | }; 735 | 736 | 737 | 738 | /* *** Last Operator * ***/ 739 | Samples.Last01 = function(){ 740 | this.Name = "Basic Function Clause"; 741 | this.Title = "Last Operator: " + this.Name; 742 | this.Description = "This is the most basic example of using the Last Operator by passing in a function for the operator clause."; 743 | this.View = Samples.Views.People; 744 | }; 745 | Samples.Last01.prototype = { 746 | Code:function(){ 747 | var sample = JSLINQ(Samples.People).Last(function() { return this.FirstName == 'Chris' }); 748 | return sample; 749 | }, 750 | Test:function(){ 751 | try 752 | { 753 | var r = this.Code(); 754 | return (r.FirstName == "Chris" && r.ID == 8); 755 | } 756 | catch(ex) 757 | { 758 | return false; 759 | } 760 | } 761 | }; 762 | 763 | Samples.Last02 = function(){ 764 | this.Name = "Function Clause - Reference Item Index"; 765 | this.Title = "Last Operator: " + this.Name; 766 | this.Description = "This is the most basic example of using the Last Operator by passing in a function for the operator clause, and referencing the Array items index within the clause."; 767 | this.View = Samples.Views.People; 768 | }; 769 | Samples.Last02.prototype = { 770 | Code:function(){ 771 | var sample = JSLINQ(Samples.People).Last(function(item, index) { return item.FirstName == 'Chris' && index == 0 }); 772 | return sample; 773 | }, 774 | Test:function(){ 775 | try 776 | { 777 | var r = this.Code(); 778 | return (r.FirstName == "Chris" && r.ID == 1); 779 | } 780 | catch(ex) 781 | { 782 | return false; 783 | } 784 | } 785 | }; 786 | 787 | 788 | /* *** ElementAt Operator * ***/ 789 | Samples.ElementAt01 = function(){ 790 | this.Name = "Basic Usage"; 791 | this.Title = "ElementAt Operator: " + this.Name; 792 | this.Description = "This is the most basic example of using the ElementAt Operator."; 793 | this.View = Samples.Views.People; 794 | }; 795 | Samples.ElementAt01.prototype = { 796 | Code:function(){ 797 | var sample = JSLINQ(Samples.People).ElementAt(1); 798 | return sample; 799 | }, 800 | Test:function(){ 801 | try 802 | { 803 | var r = this.Code(); 804 | return (r.FirstName == "Kate" && r.ID == 2); 805 | } 806 | catch(ex) 807 | { 808 | return false; 809 | } 810 | } 811 | }; 812 | 813 | /* *** Intersect Operator * ***/ 814 | Samples.Intersect01 = function(){ 815 | this.Name = "Basic Usage"; 816 | this.Title = "Intersect Operator: " + this.Name; 817 | this.Description = "This is the most basic example of using the Intersect Operator, passing an Array for the secondArray parameter."; 818 | this.View = Samples.Views.StringArray; 819 | }; 820 | Samples.Intersect01.prototype = { 821 | Code:function(){ 822 | var NameList1 = ["Chris","Steve","John"]; 823 | var NameList2 = ["Katie","Chris","John", "Aaron"]; 824 | var sample = JSLINQ(NameList1).Intersect(NameList2); 825 | return sample; 826 | }, 827 | Test:function(){ 828 | try 829 | { 830 | var r = this.Code().items; 831 | return (r.length == 2); 832 | } 833 | catch(ex) 834 | { 835 | return false; 836 | } 837 | } 838 | }; 839 | 840 | Samples.Intersect02 = function() { 841 | this.Name = "Basic Usage"; 842 | this.Title = "Intersect Operator: " + this.Name; 843 | this.Description = "This is the most basic example of using the Intersect Operator, passing an JSLINQ object for the secondArray parameter."; 844 | this.View = Samples.Views.StringArray; 845 | }; 846 | Samples.Intersect02.prototype = { 847 | Code: function() { 848 | var NameList1 = ["Chris", "Steve", "John"]; 849 | var NameList2 = ["Katie", "Chris", "John", "Aaron"]; 850 | var sample = JSLINQ(NameList1).Intersect(JSLINQ(NameList2)); 851 | return sample; 852 | }, 853 | Test: function() { 854 | try { 855 | var r = this.Code().items; 856 | return (r.length == 2); 857 | } 858 | catch (ex) { 859 | return false; 860 | } 861 | } 862 | }; 863 | 864 | Samples.Intersect03 = function(){ 865 | this.Name = "Function Clause"; 866 | this.Title = "Intersect Operator: " + this.Name; 867 | this.Description = "This is the most basic example of using the Intersect Operator by passing in a function for the operator clause."; 868 | this.View = Samples.Views.People; 869 | }; 870 | Samples.Intersect03.prototype = { 871 | Code:function(){ 872 | var NameList1 = ["Katie","Chris","John", "Aaron"]; 873 | var sample = JSLINQ(Samples.People).Intersect(NameList1, function(item, index, item2, index2) { return item.FirstName == item2; }); 874 | return sample; 875 | }, 876 | Test:function(){ 877 | try 878 | { 879 | var r = this.Code().items; 880 | return (r.length == 4); 881 | } 882 | catch(ex) 883 | { 884 | return false; 885 | } 886 | } 887 | }; 888 | 889 | /* *** DefaultIfEmpty Operator * ***/ 890 | Samples.DefaultIfEmpty01 = function(){ 891 | this.Name = "Basic Usage"; 892 | this.Title = "DefaultIfEmpty Operator: " + this.Name; 893 | this.Description = "This is the most basic example of using the DefaultIfEmpty Operator, passing in a JSLINQ object as the Default value."; 894 | this.View = Samples.Views.People; 895 | }; 896 | Samples.DefaultIfEmpty01.prototype = { 897 | Code:function(){ 898 | var people = []; 899 | var sample = JSLINQ(people).DefaultIfEmpty(JSLINQ(Samples.People)); 900 | return sample; 901 | }, 902 | Test:function(){ 903 | try 904 | { 905 | var r = this.Code().items; 906 | return (r.length == 10); 907 | } 908 | catch(ex) 909 | { 910 | return false; 911 | } 912 | } 913 | }; 914 | 915 | Samples.DefaultIfEmpty02 = function() { 916 | this.Name = "Basic Usage, pass Array"; 917 | this.Title = "DefaultIfEmpty Operator: " + this.Name; 918 | this.Description = "This is the most basic example of using the DefaultIfEmpty Operator, passing in an Array object as the Default value."; 919 | this.View = Samples.Views.People; 920 | }; 921 | Samples.DefaultIfEmpty02.prototype = { 922 | Code: function() { 923 | var people = []; 924 | var sample = JSLINQ(people).DefaultIfEmpty(Samples.People); 925 | return sample; 926 | }, 927 | Test: function() { 928 | try { 929 | var r = this.Code(); 930 | return (r.length == 10); 931 | } 932 | catch (ex) { 933 | return false; 934 | } 935 | } 936 | }; 937 | 938 | /* *** ElementAtOrDefault Operator * ***/ 939 | Samples.ElementAtOrDefault01 = function(){ 940 | this.Name = "Basic Usage"; 941 | this.Title = "ElementAtOrDefault Operator: " + this.Name; 942 | this.Description = "This is the most basic example of using the ElementAtOrDefault Operator."; 943 | this.View = Samples.Views.String; 944 | }; 945 | Samples.ElementAtOrDefault01.prototype = { 946 | Code:function(){ 947 | var sample = JSLINQ(Samples.People).ElementAtOrDefault(150, "DefaultValue"); 948 | return sample; 949 | }, 950 | Test:function(){ 951 | try 952 | { 953 | var r = this.Code(); 954 | return (r == "DefaultValue"); 955 | } 956 | catch(ex) 957 | { 958 | return false; 959 | } 960 | } 961 | }; 962 | 963 | /* *** FirstOrDefault Operator * ***/ 964 | Samples.FirstOrDefault01 = function(){ 965 | this.Name = "Basic Usage"; 966 | this.Title = "FirstOrDefault Operator: " + this.Name; 967 | this.Description = "This is the most basic example of using the FirstOrDefault Operator."; 968 | this.View = Samples.Views.People; 969 | }; 970 | Samples.FirstOrDefault01.prototype = { 971 | Code:function(){ 972 | var defaultValue = {ID:999,FirstName:"Johny",LastName:"Stone",BookIDs:[999]}; 973 | var sample = JSLINQ(Samples.People).FirstOrDefault(defaultValue); 974 | return sample; 975 | }, 976 | Test:function(){ 977 | try 978 | { 979 | var r = this.Code(); 980 | return (r.FirstName == "Chris"); 981 | } 982 | catch(ex) 983 | { 984 | return false; 985 | } 986 | } 987 | }; 988 | 989 | /* *** LastOrDefault Operator * ***/ 990 | Samples.LastOrDefault01 = function(){ 991 | this.Name = "Basic Usage"; 992 | this.Title = "LastOrDefault Operator: " + this.Name; 993 | this.Description = "This is the most basic example of using the LastOrDefault Operator."; 994 | this.View = Samples.Views.People; 995 | }; 996 | Samples.LastOrDefault01.prototype = { 997 | Code: function() { 998 | var defaultValue = { ID: 999, FirstName: "Johny", LastName: "Stone", BookIDs: [999] }; 999 | var sample = JSLINQ(Samples.People).LastOrDefault(defaultValue); 1000 | return sample; 1001 | }, 1002 | Test: function() { 1003 | try { 1004 | var r = this.Code(); 1005 | return (r.FirstName == "Kate"); 1006 | } 1007 | catch (ex) { 1008 | return false; 1009 | } 1010 | } 1011 | }; 1012 | 1013 | /* *** Take Operator Samples *** */ 1014 | Samples.Take01 = function () { 1015 | this.Name = "Get First n Count Items"; 1016 | this.Title = "Take Operator: " + this.Name; 1017 | this.Description = "This sample retrieves the first 3 results from the array."; 1018 | this.View = Samples.Views.People; 1019 | }; 1020 | Samples.Take01.prototype = { 1021 | Code: function () { 1022 | var sample = JSLINQ(Samples.People).Take(3); 1023 | 1024 | return sample; 1025 | }, 1026 | Test: function () { 1027 | try { 1028 | var r = this.Code().items; 1029 | return (r.length == 3) && r[0].ID == 1 && r[1].ID == 2 && r[2].ID == 3; 1030 | } 1031 | catch (ex) { 1032 | return false; 1033 | } 1034 | } 1035 | }; 1036 | 1037 | /* *** Skip Operator Samples *** */ 1038 | Samples.Skip01 = function () { 1039 | this.Name = "Skip First n Items and Return Rest"; 1040 | this.Title = "Skip Operator: " + this.Name; 1041 | this.Description = "This sample skips the first 3 results and returns the remaining elements."; 1042 | this.View = Samples.Views.People; 1043 | }; 1044 | Samples.Skip01.prototype = { 1045 | Code: function () { 1046 | var sample = JSLINQ(Samples.People).Skip(3); 1047 | 1048 | return sample; 1049 | }, 1050 | Test: function () { 1051 | try { 1052 | var r = this.Code().items; 1053 | return (r.length == 7) 1054 | && r[0].ID == 4 && r[1].ID == 5 && r[2].ID == 6 && r[3].ID == 7 && r[4].ID == 8 && r[5].ID == 9 && r[6].ID == 10; 1055 | } 1056 | catch (ex) { 1057 | return false; 1058 | } 1059 | } 1060 | }; 1061 | 1062 | /* *** Each Operator Samples *** */ 1063 | Samples.Each01 = function () { 1064 | this.Name = "Run code over each element"; 1065 | this.Title = "Each Operator: " + this.Name; 1066 | this.Description = "This sample shows how to easily execute a specific function over each element in the array."; 1067 | this.View = Samples.Views.People; 1068 | }; 1069 | Samples.Each01.prototype = { 1070 | Code: function () { 1071 | var sample = JSLINQ(Samples.People).Each(function (item, index) { 1072 | this.ID = this.ID + 100; 1073 | }); 1074 | 1075 | return sample; 1076 | }, 1077 | Test: function () { 1078 | try { 1079 | var r = this.Code().items; 1080 | return (r.length == 10) 1081 | && r[0].ID == 101 && r[1].ID == 102 && r[2].ID == 103 && r[3].ID == 104 && r[4].ID == 105 && r[5].ID == 106 && r[7].ID == 108 && r[8].ID == 109 && r[9].ID == 110; 1082 | } 1083 | catch (ex) { 1084 | return false; 1085 | } 1086 | } 1087 | }; 1088 | 1089 | /* *** Skip Operator Samples *** */ 1090 | Samples.Random01 = function () { 1091 | this.Name = "Get Random Element"; 1092 | this.Title = "Random Operator: " + this.Name; 1093 | this.Description = "This method will returns the specified number of elements at random. If no number is specified, then 1 is returned."; 1094 | this.View = Samples.Views.People; 1095 | }; 1096 | Samples.Random01.prototype = { 1097 | Code: function () { 1098 | var sample = JSLINQ(Samples.People).Random(); 1099 | 1100 | return sample; 1101 | }, 1102 | Test: function () { 1103 | try { 1104 | var r = this.Code().items; 1105 | return (r.length == 1); 1106 | } 1107 | catch (ex) { 1108 | return false; 1109 | } 1110 | } 1111 | }; 1112 | Samples.Random02 = function () { 1113 | this.Name = "Get 3 Random Elements"; 1114 | this.Title = "Random Operator: " + this.Name; 1115 | this.Description = "This method will returns the specified number of elements at random. If no number is specified, then 1 is returned."; 1116 | this.View = Samples.Views.People; 1117 | }; 1118 | Samples.Random02.prototype = { 1119 | Code: function () { 1120 | var sample = JSLINQ(Samples.People).Random(3); 1121 | 1122 | return sample; 1123 | }, 1124 | Test: function () { 1125 | try { 1126 | var r = this.Code().items; 1127 | return (r.length == 3); 1128 | } 1129 | catch (ex) { 1130 | return false; 1131 | } 1132 | } 1133 | }; 1134 | 1135 | 1136 | Samples.UnitTest = function (name, title, desc, view, code, test) { 1137 | this.Name = name; 1138 | this.Title = title; 1139 | this.Description = desc; 1140 | this.View = view; 1141 | this.Code = code; 1142 | this.Test = test; 1143 | }; 1144 | 1145 | function createUnitTest(name, view, code, test) { 1146 | return new Samples.UnitTest(name, name, '', view, code, test); 1147 | } 1148 | 1149 | /* *** Other Unit Tests *** */ 1150 | Samples.OtherUnitTests01 = function () { 1151 | this.Name = "Other Unit Test 01"; 1152 | this.Title = "Other Unit Test 01"; 1153 | this.Description = ""; 1154 | this.View = Samples.Views.People; 1155 | }; 1156 | Samples.OtherUnitTests01.prototype = { 1157 | Code: function () { 1158 | return JSLINQ(Samples.People).first(); 1159 | }, 1160 | Test: function () { 1161 | try { 1162 | return this.Code() === JSLINQ(Samples.People).First(); 1163 | } 1164 | catch (ex) { 1165 | return false; 1166 | } 1167 | } 1168 | }; 1169 | Samples.OtherUnitTests02 = function () { 1170 | this.Name = this.Title = "Other Unit Test 02"; 1171 | this.Description = ""; 1172 | this.View = Samples.Views.People; 1173 | this.Code = function () { 1174 | return jslinq(Samples.People).firstOrDefault(); 1175 | }; 1176 | this.Test = function () { 1177 | try { 1178 | return this.Code() === JSLINQ(Samples.People).FirstOrDefault(); 1179 | } 1180 | catch (ex) { 1181 | return false; 1182 | } 1183 | }; 1184 | }; 1185 | Samples.OtherUnitTests03 = function () { 1186 | this.Name = this.Title = "Other Unit Test 03"; 1187 | this.Description = ""; 1188 | this.View = Samples.Views.Count; 1189 | this.Code = function () { 1190 | return jslinq(Samples.People).where(function () { return this.FirstName == 'Chris'; }).count(); 1191 | }; 1192 | this.Test = function () { 1193 | try { 1194 | return this.Code() === JSLINQ(Samples.People).Where(function () { return this.FirstName == 'Chris'; }).Count(); 1195 | } 1196 | catch (ex) { 1197 | return false; 1198 | } 1199 | }; 1200 | }; -------------------------------------------------------------------------------- /images/Nuget-jslinq-install.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crpietschmann/jslinq/177cba044a8c3843e5f6a9947f71a8a2f43aae22/images/Nuget-jslinq-install.png --------------------------------------------------------------------------------