7.0.2 • Published 1 year ago

@transformation/glob v7.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
1 year ago

@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",
  ]
);
7.0.0

1 year ago

7.0.2

1 year ago

7.0.1

1 year ago

5.1.1

2 years ago

5.1.0

2 years ago

5.0.0

2 years ago

6.0.0

2 years ago

4.2.0

2 years ago

4.3.0

2 years ago

4.1.2

3 years ago

4.1.0

3 years ago

4.1.1

3 years ago

4.0.1

3 years ago

4.0.0

3 years ago

3.8.0

3 years ago

3.7.0

4 years ago

3.6.0

4 years ago

3.5.3

4 years ago

3.5.1

4 years ago

3.5.0

4 years ago

3.4.0

4 years ago

3.3.0

4 years ago

3.2.0

4 years ago

3.1.0

4 years ago

2.3.0

4 years ago

3.0.0

4 years ago

2.0.0

4 years ago

1.34.0

4 years ago

1.33.0

4 years ago

1.32.0

4 years ago

1.31.0

4 years ago

1.30.2

4 years ago

1.30.1

4 years ago

1.30.0

4 years ago

1.29.0

4 years ago

1.29.1

4 years ago

1.28.0

4 years ago

1.27.1

4 years ago

1.27.0

4 years ago

1.25.0

4 years ago

1.26.0

4 years ago

1.24.0

4 years ago

1.23.0

4 years ago

1.22.0

4 years ago

1.21.0

4 years ago

1.20.2

4 years ago

1.20.1

4 years ago

1.20.0

4 years ago

1.19.0

4 years ago

1.18.1

4 years ago

1.18.0

4 years ago

1.18.2

4 years ago

1.17.0

4 years ago

1.16.0

4 years ago

1.15.0

4 years ago

1.14.1

4 years ago

1.14.0

4 years ago

1.13.0

4 years ago

1.12.3

4 years ago

1.12.2

4 years ago

1.12.1

4 years ago

1.12.0

4 years ago

1.11.0

4 years ago

1.10.0

4 years ago

1.9.1

4 years ago

1.9.0

4 years ago