https://github.com/danielbayley/matchup
Find the first path matching a glob pattern, walking up from a given directory.
https://github.com/danielbayley/matchup
config configuration filesystem find find-up fs glob glob-pattern node nodejs npm npm-module npm-package npmjs path pathfinding pattern-matching
Last synced: about 2 months ago
JSON representation
Find the first path matching a glob pattern, walking up from a given directory.
- Host: GitHub
- URL: https://github.com/danielbayley/matchup
- Owner: danielbayley
- License: mit
- Created: 2025-01-27T00:08:47.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-02-26T18:17:01.000Z (3 months ago)
- Last Synced: 2025-03-24T18:49:35.336Z (2 months ago)
- Topics: config, configuration, filesystem, find, find-up, fs, glob, glob-pattern, node, nodejs, npm, npm-module, npm-package, npmjs, path, pathfinding, pattern-matching
- Language: JavaScript
- Homepage: https://npm.im/@danielbayley/matchup
- Size: 28.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
![]()
Matchup
=======
Find the first path matching a [_glob_ pattern], walking up from a given directory.## Example
~~~ js
import fs from "node:fs/promises"
import {matchup} from "@danielbayley/matchup"const cwd = import.meta.dirname
const metadata = await matchup("package.*", { cwd }) // package.json
.then(fs.readFile)
.then(JSON.parse)
.catch(console.error)console.log(metadata.type) // module
~~~Options
------------------------------------------------------------------------------------
| Option | Default | Description |
|:-----------|:------------------------|:------------------------------------------|
| `cwd` | [`import.meta.dirname`] | Search starting point. |
| `ignore` | `["node_modules"]` | `ignore` paths containing these patterns. |
| `parse` | | `return` a [`node:path`] object. |
| `max` | `10` | Maximum upward traversal depth. |
| `symlinks` | | `false` will not match [symbolic links]. |## Install
~~~ sh
pnpm install @danielbayley/matchup
~~~
> [!IMPORTANT]
> This package is _[ESM]_ [only], so must be [`import`]ed instead of [`require`]d,
> and [depends] on [_Node_.js] [`>=`][][`20`].Specify this requirement with [`engines`] and/or [`devEngines`]:
~~~ jsonc
// package.json
"type": "module",
"engines": {
"node": ">=20"
},
"devEngines": {
"runtime": {
"name": "node",
"version": ">=20"
}
},
~~~License
-------
[MIT] © [Daniel Bayley][MIT]: LICENSE.md
[Daniel Bayley]: https://github.com/danielbayley[_Node_.js]: https://nodejs.org
[ESM]: https://developer.mozilla.org/docs/Web/JavaScript/Guide/Modules
[only]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[`import`]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import
[`require`]: https://nodejs.org/api/modules.html#requireid
[depends]: https://docs.npmjs.com/cli/v11/configuring-npm/package-json#engines
[`>=`]: https://docs.npmjs.com/cli/v6/using-npm/semver#ranges
[`20`]: https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V20.md
[`engines`]: https://docs.npmjs.com/cli/v11/configuring-npm/package-json#engines
[`devEngines`]: https://docs.npmjs.com/cli/v11/configuring-npm/package-json#devengines[_glob_ pattern]: https://globster.xyz
[`import.meta.dirname`]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/import.meta
[`node:path`]: https://nodejs.org/api/path.html#pathparsepath
[symbolic links]: https://wikipedia.org/wiki/Symbolic_link