@transformation/glob

    4.1.2 • Public • Published

    @transformation/glob

    A package used to find paths matching glob patterns.

    glob

    Glob for file paths using globby and emit the paths as items.

    const { glob } = require("@transformation/glob");

    The simplest example is to just glob for a pattern. You can also provide an array of patterns as well.

    await expect(
      pipeline(glob("reports/20*/report.txt"), sort()),
      "to yield items",
      [
        "reports/2020/report.txt",
        "reports/2021/report.txt",
        "reports/2022/report.txt",
      ]
    );

    If you need more control you can provide an options object that supports all of the options of globby. Notice that also provide the patterns as options.

    await expect(
      pipeline(glob({ cwd: "reports", pattern: "2020/*.txt" }), sort()),
      "to yield items",
      ["2020/report.txt", "2020/transactions.txt"]
    );

    globEach

    Run a glob for incoming glob patterns and emit the paths.

    const { globEach } = require("@transformation/glob");
    await expect(
      pipeline(
        emitItems("reports/20*/report.txt", "reports/2020/*.txt", [
          "reports/2020/report.txt",
          "reports/2021/report.txt",
        ]),
        globEach({ cwd: testDir }),
        sort()
      ),
      "to yield items",
      [
        "reports/2020/report.txt",
        "reports/2020/report.txt",
        "reports/2020/report.txt",
        "reports/2020/transactions.txt",
        "reports/2021/report.txt",
        "reports/2021/report.txt",
        "reports/2022/report.txt",
      ]
    );

    You can also consume glob options and overlay options or patterns from the globEach transformation.

    await expect(
      pipeline(
        emitItems("2020", "2021"),
        map((year) => ({ cwd: path.join(testDir, year) })),
        globEach({ pattern: "*.txt", absolute: true }),
        map((path) => path.replace(/.*\/examples\//, "examples/")),
        sort()
      ),
      "to yield items",
      [
        "examples/reports/2020/report.txt",
        "examples/reports/2020/transactions.txt",
        "examples/reports/2021/report.txt",
        "examples/reports/2021/transactions.txt",
      ]
    );

    Install

    npm i @transformation/glob

    DownloadsWeekly Downloads

    76

    Version

    4.1.2

    License

    MIT

    Unpacked Size

    8.2 kB

    Total Files

    15

    Last publish

    Collaborators

    • sunesimonsen