You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

linqscript

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

linqscript

C# alike List in Javascript. Simple lightweight lambda syntax library for Typescript, extending Array. Works with Angular

1.4.3
latest
Source
npmnpm
Version published
Weekly downloads
27
285.71%
Maintainers
1
Weekly downloads
 
Created
Source

NPM

C# alike List in Javascript. Simple lightweight lambda syntax library for Typescript, extending Array.

No jQuery required! Unit tested.

Typescript arrow functions allows us, to use lambda syntax, which makes this easy to use.
This library extends the native Array. Use full advantage of an Array, extended with this methods. Works with Angular.
import { List } from 'linqscript';

USAGE:

var fruits = new List<string>();
fruits.Add("apple");
fruits.Add("banana");

var fruit = fruits.Where(x => x === "apple").First();

You can use of course more complex objects:

enum Color {
	Green,
	Red
}

class Fruits {
	public Name: string;
	public Color: Color;
}

var fruits = new List<Fruits>();
var apple = new Fruit();
apple.Color = Color.Green;
apple.Name = "Apple";
fruits.Add(apple);

var redApple = new Fruit();
redApple.Color = Color.Red;
redApple.Name = "Apple";
fruits.Add(redApple);

var kiwi = new Fruit();
kiwi.Color = Color.Green;
kiwi.Name = "Kiwi";
fruits.Add(kiwi);

fruits.Where(x => x.Color === Color.Green);
Output:
{
	"Fruits": [{
		"Name": "Kiwi",
		"Color": 1
	}, {
		"Name": "Apple",
		"Color": 1
	}]
}
fruits.Select(x => x.Color);
{
	"Color": [
		"Green",
		"Red"
	]
}
fruits.Distinct(x => x.Name)
{
	"Name": [
		"Apple",
		"Kiwi"
	]
}
List.Range(3, 10)

[3,4,5,6,7,8,9,10,11,12] // starting at 3, generates 10 numbers
var numbersToSum = new List<number>();

numbersToSum.Add(1);
numbersToSum.Add("2"); // will be converted
numbersToSum.Add(3);
numbersToSum.Add(5);
numbersToSum.Add("eight"); // will be ignored
numbersToSum.Add(8);
numbersToSum.Add(13);

var sum = numbersToSum.Sum(); // 32

var sumPlusOne = numbersToSum.Sum(x => x+1); // 38 -> use delegate to manipulate.

Methods

MethodDescriptionParameter
WhereReturns list, where delegate returns true.Delegate
SelectReturns list of selected valueDelegate
DistinctReturns grouped selected value.Delegate
FirstReturns first item in list.
LastReturns last item in list.
Range (static)Creates list of numbers, within a specified range.start, length
AddAdds element to list.item
AddRangeAdds each item in given list.items
RemoveAtRemoves item from list by index.index
RemoveRemoves item from list.item
IndexOfGets index of given item.item
ContainsReturn true if list contains given item.item
GetGets item by index.index
ClearClears list.
ToArrayConverts list to array. Important for serialization.item
CountReturns listcount.
CountReturns listcount by delegate.Delegate
SumSummarizes numbers in list.
SumSummarizes numbers in list by delegate.Delegate
AnyReturns true if list contains any item.
AnyReturns true if list contains any item by delegate.Delegate
EqualsCompares list with another list. Returns true if lists are equal. If comparePosition is set to false, equality will be checked without comparison on positionitem, comparePosition (default true)
ToListConverts an Array to list.

any questions or feedback, please contact me!

Keywords

linqscript

FAQs

Package last updated on 29 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts