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-fns

v0.0.5-beta

Published

LINQ for Javascript, written by TypeScript

Downloads

11

Readme

linq-fns

.NET LINQ functions for JavaScript written in TypeScript.

  • ⚡ Provides Queryable<T>,which is reusable, variable and uses a predicate collection for deferred execution.
  • 🔨 Contains most of the original .NET methods and some additional methods.
  • 🔨 Supports Promise as an input source.
  • 🙅 All APIs are JavaScript native methods so can be easily incorporated into existing JavaScript projects.
  • 📊 Includes some simple drivers (such as Firebase Realtime database).
npm install linq-fns --save

This version is an alpha release so if you have any problems, please don't hesitate to let me know. 👋

Browser client files can be found in the release folder.

Basic example

Node or browser

// ES6
import { Queryable } from 'linq-fns';

// ES5
const Queryable = require('linq-fns').Queryable;

let query = Queryable
            .from(nations)
            .join(continents, (x, y) => x.areaId === y.id)
            .groupBy(o => o.y.areaName)
            .select(x => {
                return {
                    area: x.key,
                    total: Queryable.fromSync(x.items).count() // This will return a number, not Promise<number>
                }
            })
const asyncData = query.toList(); // Will return Promise<{area:string, total:number}>
asyncData.then(data => {
    console.log(data);
    // [
    //     {area: 'Euro': total: 2},
    //     {area:'South America', total: 1}
    // ]

// Or use async/await
const data = await query.toList();
console.log(data);
});

Firebase

const FireBaseQueryable = require('linq-fns').FireBaseQueryable;
const admin = require('firebase-admin');
const serviceAccount = require('./serviceAccountKey');

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: 'https://xxx.firebaseio.com'
});

const db = admin.database();
const postsQuery = new FireBaseQueryable(db,'<yourdb>.posts');

// READ AND QUERY DATA
// ES5 Promise
postsQuery.getQuery().where('...').select('...').toList().then(x=>'...');

// Async/await
const data = await postsQuery.getQuery().where('...').select('...').toList();

// WRITE DATA
// Prepare calls, but do not send requests to server
postsQuery.add(item);
postsQuery.remove(item);
postsQuery.update(item);

// Call this to execute 3 above methods
postsQuery.commitChanges();

localStorage


// Node
const LocalStorageQueryable = require('linq-fns').LocalStorageQueryable;

const postsQuery = new LocalStorageQueryable("posts");

postsQuery.add(item);
postsQuery.remove(item);
postsQuery.update(item);

// Call this to execute 3 above methods
postsQuery.commitChanges();

gist file


//Node
const GistQueryable = require('linq-fns').GistQueryable;

const postsQuery = new GistQueryable(
    "6d183b7f997819cd5a8354f35c1e471f123", // gist file
    "259f97b96762c9d3a155630d12321fd1cfaf253ff", // access token
    "posts") // table name

postsQuery.add(item);
postsQuery.remove(item);
postsQuery.update(item);
postsQuery.commitChanges();

Process

1.Methods

  • [x] from
  • [x] where
  • [x] select
  • [x] selectMany
  • [x] join
  • [x] leftJoin
  • [x] groupJoin
  • [x] orderBy
  • [x] orderByDescending
  • [x] take
  • [x] takeWhile
  • [x] skip
  • [x] skipWhile
  • [x] groupBy
  • [x] distinct
  • [x] concat
  • [x] zip
  • [x] union
  • [x] intersect
  • [x] except
  • [x] first : Promise<T>
  • [x] firstOrDefault : Promise<T | null>
  • [x] last : Promise<T>
  • [x] lastOrDefault : Promise<T | null>
  • [x] single
  • [x] singleOrDefault
  • [x] contains
  • [x] sequenceEqual
  • [x] any : Promise<boolean>
  • [x] all : Promise<boolean>
  • [x] count : Promise<number>
  • [x] min : Promise<number>
  • [x] max : Promise<number>
  • [x] sum : Promise<number>
  • [x] average
  • [x] aggregate
  • [x] toList : Promise<T[]>

2. Drivers

  • [x] Firebase : Node
  • [x] Localstorage : Node & Browser
  • [x] Gists Github : Node & Browser
  • [ ] ...

License

MIT License