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

split-lazy

v1.0.3

Published

[![Codacy Badge](https://app.codacy.com/project/badge/Grade/ae3028bdccea48bf9a7b05ed91284fbd)](https://www.codacy.com/gh/miyavsu-limited/split-lazy/dashboard?utm_source=github.com&utm_medium=referral&utm_content=miyavsu-limited/split-lazy&utm_

Downloads

7

Readme

split-lazy 🗡🦭

Codacy Badge Codacy coverage npm bundle size

This package provides ways to split arrays, strings or other iterables (sync and async) lazily. It returns an iterable that calculates the result lazily (while iterating on it).

👉 Learn more about iterators here.

Installing

Use yarn or npm to install it.

npm install split-lazy

splitLazy

function splitLazy<I, T extends Iterable<I>>(
  iterable: T,
  separator: unknown
): Generator<I[], void, void>

First argument is iterable to search inside and split. Second argument is either an iterable or an element to look for in the given first argument.

separator can be an Iterable or anything else as an element. If separator is an iterable, it will be searched as a sub iterator.

Examples

import { splitLazy } from "split-lazy";

const arr = [1, 3, 5, 7, 9];
const result = splitLazy(arr, 5);

for (const item of result) {
    console.log(item);
}
// outputs:
// [1, 3]
// [7, 9]
import { splitLazy } from "split-lazy";

const arr = [1, 3, 5, 7, 9];
const iterable = splitLazy(arr, 5);

expect(iterable.next().value).toEqual([1, 3]); // ✅
expect(iterable.next().value).toEqual([7, 9]); // ✅
import { splitLazy } from "split-lazy";

function* generator() {
    yield 1;
    yield 3;
    yield 5;
    yield 7;
    yield 9;
}

const iterable = generator();
const result = splitLazy(iterable, 5);

for (const item of result) {
    console.log(item);
}
// outputs:
// [1, 3]
// [7, 9]

It can also search for sub-iterables in iterables:

import { splitLazy } from "split-lazy";

const arr = [1, 3, 5, 7, 9, 11];
const iterable = splitLazy(arr, [5, 7]);

expect(iterable.next().value).toEqual([1, 3]); // ✅
expect(iterable.next().value).toEqual([9, 11]); // ✅

asyncSplitLazy

async function* asyncSplitLazy<I, T extends AsyncIterable<I>>(
  iterable: T,
  separator: unknown
): AsyncGenerator<I[], void, void>

Iterable can be an AsyncIterable. Separator can be an Iterable, AsyncIterable or anything else as an element. If separator is an iterable, it will be searched as a sub iterator.

Note that if separator argument is an AsyncIterable, asyncSplitLazy fully iterates the given separator before it starts searching for it in the first argument (iterable).

Contributing

Help is needed for documentation in general. Adding/improving TSDoc, a better README, added/improved reference would be amazing 💫. Please open/find an issue to discuss.

Tests

Jest tests are set up to run with npm test.