npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@geffencode/linqscript

v1.0.2

Published

A basic implementation of LINQ methods for Typescript.

Downloads

4

Readme

Project Title

A basic implementation of LINQ methods for Typescript.

Installation

$ npm install @geffencode/linqscript

Usage/Examples

import { AsLinq, LINQArray} from "@geffencode/linqscript";

interface Person {
    id: number;
    name: string;
    age: number;
    city: string;
    hobbies: string[]
}

const persons: Person[] = myService.getPersons();

// By declaring a new LINQArray
const linqArray = new LINQArray<Person>(...persons);
const names = linqArray.Select(p => p.name); // ['John Doe', 'Jane Doe', 'Jane Smith', ...]

// Copying an existing array as LINQArray
const ids = AsLinq(persons).Select(p => p.id); // [1, 2, 3, ...]

// Getting the hobbies of people older than 30 for a city
const hobbies = linqArray.Where(p => p.age > 30 && p.city == 'Mogadishu')
                                  .SelectMany(p => p.hobbies)
                                  .Distinct(); // Remove duplicates

// Id, name and age of all people that play competitive chess boxing in Thimphu
// ordered by age descending, returning a regular array.
const chessboxers = linqArray.Where(p => p.city === 'Thimphu')
                            .Select(({id, name, age}) => ({id, name, age}))
                            .OrderByDescending(p => p.age)
                            .ToArray();

// Get all persons grouped by city
const byCity = linqArray.GroupBy(p => p.city);

API Reference

|Method|Argument|Return|Description| |:----|:----|:----|:----| |Add|item: T|None|Adds an item to the end of the array.| |AddRange|arr: T[]|None|Adds multiple items to the end of the array.| |GroupBy|predicate: (item: T) => K|Record<K, T[]>|Groups the elements in the array by the specified key selector.| |Select|predicate: (item: T) => K|LINQArray|Projects each element of the array to a new form using the specified selector function.| |Where|predicate: (item: T) => boolean|LINQArray|Filters the elements of the array based on a predicate function.| |First|predicate?: (item: T) => boolean|T or undefined|Returns the first element of the array that satisfies a specified condition, or undefined if no such element is found.| |FirstOrDefault|predicate?: (item: T) => boolean|T or undefined|Returns the first element of the array that satisfies a specified condition, or undefined if no such element is found.| |SelectMany|predicate: (item: T) => K[]|LINQArray|Projects each element of the array to a sequence and flattens the resulting sequences into one LINQArray.| |Distinct|None|LINQArray|Returns a new LINQArray containing only the distinct elements of the original array.| |DistinctBy|predicate: (item: T) => K|LINQArray|Returns a new LINQArray containing only the distinct elements of the original array, determined by the specified key selector function.| |OrderBy|predicate: (item: T) => K|LINQArray|Sorts the elements of the array in ascending order according to the specified key selector function.| |OrderByDescending|predicate: (item: T) => K|LINQArray|Sorts the elements of the array in descending order based on the specified predicate.| |Any|predicate?: (item: T) => boolean|boolean|Determines whether any element of the array satisfies the specified predicate.| |Take|i: number|LINQArray|Returns a new array that contains the specified number of elements from the start of the array.| |Skip|i: number|LINQArray|Bypasses a specified number of elements in the array and returns the remaining elements.| |ToArray|None|T[]|Copies the elements of the LINQArray to a new Array.| |_log|None|LINQArray|Logs the current array to the console and returns it.|