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

linq-arrays

v3.2.5

Published

Emulate LINQ syntax to work with Arrays in JS

Downloads

208

Readme

linq-arrays

The name LINQ is already used ::sad::

Based on System.Linq in C#, but in TS for browser and Node.js (server side);

Features

  • The same methods (not all) of Array.prototype
  • Typescript out of box
  • Make the massive and repetitive operations for you, like sort by key, order by key, sorter for strings/numbers/date
  • A set of tools in Fluent Interface to work with arrays

Install

Simple, just choose your package manage and drop the command

yarn add linq-arrays
npm i linq-arrays
pnpm add linq-arrays

Using

const array = new Linq([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
// you can create a instance with Linq.From(array) 
array.Sum() // 55
/* 
    with .Where, you can use some symbols to make your filter more simple
    - != : compare use !=
	- !== : compare use !== 
	- < : compare use <
	- <= : compare use <=
	- == : compare use ==
	- === : compare use ===
	- > : compare use >
	- >= : compare use >=
	eq: compare use Equals in `src/utils.ts`
	is: compare use Object.is (JS method)
*/
array.Where({symbol: "!==", value: 2}).Sum() // 53
// or you can pass you function
array.Where((number, index, allItems) => number !== 2) // the same of Array.prototype.filter
/* 
    args accept a method, the same of Array.prototype.map. 
    If empty, just return the array like .ToArray
*/
const result = array.Select((x) => x ** 2) // the same of Array.prototype.map

API

const array = new Linq([1, 2, 3, 4, 5, 6, 7, 8, 9])
  • Reverse(): use the Array.prototype.reverse to reverse array
  • Add(el: Type | Type[]): Add an item/items to last position of array with push/concat
  • Prepend(el: Type | Type[]): Add an item/items to first position of array with push/concat
  • Concat(list: Type[]): Concat an array to your array
  • Select(transform?: ArrayCallback<Type>): Get array from Linq instance. The argument is a optional function, and works equals Array.prototype.map
  • Take(init: number, end?: number): Take n items of array. If end is null, use n:array.length
  • Head(): Get first item of array
  • Tail(): Return all items, except first
  • Skip(jumps: number | ArrayCallbackAssertion<Type>): Skip the n items or skip while the callback is false
  • Distinct(): like Linq.Unique
  • ToArray(): Get array from instance
  • First(predicate?: ArrayCallbackAssertion<Type>): Return the first item of array or apply Array.prototype.find
  • Last(predicate?: ArrayCallbackAssertion<Type>): Return the last item of array or apply Array.prototype.find in reverse array (using Array.prototype.reverse)
  • Sum(key?: keyof Type): Sum all items of array. You can specify the property or sum all primitive values in array
  • Average(key?: keyof Type): Get Average of Linq.Sum
  • GroupBy(key: keyof Type): The same of static method Linq.GroupBy
  • Except(exceptions: Type[]): Get all items not in argument array
  • Intersect(commons: Type[]): Get all items in argument array
  • OrderBy(key?: keyof Type, sort?: OrderKeys): Order array from key
  • Includes(object: Type): Check if array includes the object
  • In(array: Type[]): Check if instance array has items in argument array
  • Empty(): nothing to comment
  • ToMap<KEY>(key: keyof Type): Map<KEY, Type>: convert the array to Map, using the value of object[key] to Map keys
  • Zip<T>(array: T[], fn: (first: Type, second?: T) => any)
  • Count(predicate?: ArrayCallbackAssertion<Type>): Count items based on predicate or just array.length
  • Get(n: number): Get item in n position
  • Clone(): deepClone instance array
  • ToObject(key: keyof Type): ArrayAsObj<Type>
  • All(predicate: ArrayCallbackAssertion<Type>): The same of Array.prototype.every