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

@ldflex/async-iteration-handlers

v1.1.1

Published

LDflex handlers for asynchronous iteration operations

Downloads

4

Readme

@ldflex/async-iteration-handlers

This library acts as a wrapper for functions from the async library, exporting them as handlers to be used by LDflex.

npm version build Dependency Status

All exported handlers (defaultIterationHandlers)

Initialization

const { PathFactory, defaultHandlers } = require('ldflex');
const { default: ComunicaEngine } = require('@ldflex/comunica');
const { default: defaultIterationHandlers } = require('@ldflex/async-iteration-handlers');
const { namedNode } = require('@rdfjs/data-model');

// The JSON-LD context for resolving properties
const context = {
  "@context": {
    "@vocab": "http://xmlns.com/foaf/0.1/",
    "friends": "knows",
    "label": "http://www.w3.org/2000/01/rdf-schema#label",
  }
};
// The query engine and its source
const queryEngine = new ComunicaEngine('https://ruben.verborgh.org/profile/');
// The object that can create new paths
const path = new PathFactory({
  context,
  queryEngine,
  handlers: {
    ...defaultHandlers,
    ...defaultIterationHandlers
  }
});

const ruben = path.create({ subject: namedNode('https://ruben.verborgh.org/profile/#me') });

ruben.friends.forEach(async (x: any) => {
  console.log(`${await x}`)
});

Available Methods

  • .every
  • .everyLimit
  • .everySeries
// This executes asynchronously
const allFriendsLabelled: Promise<boolean> = path.friends.every(
  async friend => `${await friend.label}` !== 'undefined'
);

// This executes synchronously
const allFriendsLabelled: Promise<boolean> = path.friends.everySeries(
  async friend => `${await friend.label}` !== 'undefined'
);

// This executes asynchronously, but at most 5 entities are processed in parrallel at any time
const allFriendsLabelled: Promise<boolean> = path.friends.everyLimit(
  async friend => `${await friend.label}` !== 'undefined',
  5
);
  • .filter
  • .filterLimit
  • .filterSeries
// This executes asynchronously
const labelledFriends: Promise<string[]> = path.friends.filter(
  async friend => `${await friend.label}` !== 'undefined'
);

// This executes synchronously
const labelledFriends: Promise<string[]> = path.friends.filterSeries(
  async friend => `${await friend.label}` !== 'undefined'
);

// This executes asynchronously, but at most 5 entities are processed in parrallel at any time
const labelledFriends: Promise<string[]> = path.friends.filterLimit(
  async friend => `${await friend.label}` !== 'undefined',
  5
);
  • .find
  • .findLimit
  • .findSeries
// This executes asynchronously
const labelledFriend: Promise<string> = path.friends.find(
  async friend => `${await friend.label}` !== 'undefined'
);

// This executes synchronously
const labelledFriend: Promise<string> = path.friends.findSeries(
  async friend => `${await friend.label}` !== 'undefined'
);

// This executes asynchronously, but at most 5 entities are processed in parrallel at any time
const labelledFriend: Promise<string> = path.friends.findLimit(
  async friend => `${await friend.label}` !== 'undefined',
  5
);
  • .forEach
  • .forEachLimit
  • .forEachSeries
const labelledFriend = [];

// This executes asynchronously
path.friends.forEach(
  async friend => {
    if (`${await friend.label}` !== 'undefined') {
      labelledFriend.push(friend)
    }
  }
);

// This executes synchronously
path.friends.forEachSeries(
  async friend => {
    if (`${await friend.label}` !== 'undefined') {
      labelledFriend.push(friend)
    }
  }
);

// This executes asynchronously, but at most 5 entities are processed in parrallel at any time
path.friends.forEachLimit(
  async friend => {
    if (`${await friend.label}` !== 'undefined') {
      labelledFriend.push(friend)
    }
  },
  5
);
  • .forEachOf
  • .forEachOfLimit
  • .forEachOfSeries
const labelledFriend = [];

// This executes asynchronously
path.friends.forEachOf(
  async (friend, index) => {
    if (`${await friend.label}` !== 'undefined') {
      labelledFriend.push(friend)
    }
  }
);

// This executes synchronously
path.friends.forEachOfSeries(
  async (friend, index) => {
    if (`${await friend.label}` !== 'undefined') {
      labelledFriend.push(friend)
    }
  }
);

// This executes asynchronously, but at most 5 entities are processed in parrallel at any time
path.friends.forEachOfLimit(
  async (friend, index) => {
    if (`${await friend.label}` !== 'undefined') {
      labelledFriend.push(friend)
    }
  },
  5
);
  • .map
  • .mapLimit
  • .mapSeries
// This executes asynchronously
const friendLabels: Promise<string[]> = path.friends.map(
  async friend => `${await friend.label}`
);

// This executes synchronously
const friendLabels: Promise<string[]> = path.friends.mapSeries(
  async friend => `${await friend.label}`
);

// This executes asynchronously, but at most 5 entities are processed in parrallel at any time
const friendLabels: Promise<string[]> = path.friends.mapLimit(
  async friend => `${await friend.label}`,
  5
);
  • .some
  • .someLimit
  • .someSeries
// This executes asynchronously
const someFriendsLabelled: Promise<boolean> = path.friends.some(
  friend => `${friend.label}` !== 'undefined'
);

// This executes synchronously
const someFriendsLabelled: Promise<boolean> = path.friends.someLimit(
  friend => `${friend.label}` !== 'undefined'
);

// This executes asynchronously, but at most 5 entities are processed in parrallel at any time
const someFriendsLabelled: Promise<boolean> = path.friends.someSeries(
  friend => `${friend.label}` !== 'undefined',
  5
);
  • .reduce
// This executes synchronously
const friendLabels: Promise<string>= path.friends.reduce(
  async (total, friend) => `${total}&${await friend.label}`,
  ''
);

Alternatively if you wish to only use sychronous handlers (seriesIterationHandlers)

Initialization

const { PathFactory } = require('ldflex');
const { default: ComunicaEngine, defaultHandlers } = require('@ldflex/comunica');
const { seriesIterationHandlers } = require('@ldflex/async-iteration-handlers');
const { namedNode } = require('@rdfjs/data-model');

// The JSON-LD context for resolving properties
const context = {
  "@context": {
    "@vocab": "http://xmlns.com/foaf/0.1/",
    "friends": "knows",
    "label": "http://www.w3.org/2000/01/rdf-schema#label",
  }
};
// The query engine and its source
const queryEngine = new ComunicaEngine('https://ruben.verborgh.org/profile/');
// The object that can create new paths
const path = new PathFactory({
  context,
  queryEngine,
  handlers: [
    ...defaultHandlers,
    ...seriesIterationHandlers
  ]
});

Available Methods

  • .every
// This executes synchronously
const allFriendsLabelled: Promise<boolean> = path.friends.every(
  async friend => `${await friend.label}` !== 'undefined'
);
  • .filter
// This executes synchronously
const labelledFriends: Promise<string[]> = path.friends.filter(
  async friend => `${await friend.label}` !== 'undefined'
);
  • .find
// This executes synchronously
const labelledFriend: Promise<string> = path.friends.find(
  async friend => `${await friend.label}` !== 'undefined'
);
  • .forEach
const labelledFriend = [];

// This executes synchronously
path.friends.forEach(
  async friend => {
    if (`${await friend.label}` !== 'undefined') {
      labelledFriend.push(friend)
    }
  }
);
  • .forEachOf
const labelledFriend = [];

// This executes synchronously
path.friends.forEachOf(
  async (friend, index) => {
    if (`${await friend.label}` !== 'undefined') {
      labelledFriend.push(friend)
    }
  }
);
  • .map
// This executes synchronously
const friendLabels: Promise<string[]> = path.friends.map(
  async friend => `${await friend.label}`
);
  • .some
// This executes synchronously
const someFriendsLabelled: Promise<boolean> = path.friends.some(
  friend => `${friend.label}` !== 'undefined'
);
  • .reduce
// This executes synchronously
const friendLabels: Promise<string>= path.friends.reduce(
  async (total, friend) => `${total}&${await friend.label}`,
  ''
);

NOTE

By default, methods with limited asynchronicity process at most 5 entities concurrently.

License

©2020–present Jesse Wright, Ruben Verborgh, Ruben Taelman. MIT License.