0.0.3 • Published 2 years ago
find-marker v0.0.3
Find the closest arbitrary marker file
Usage
Let's say you have a project, called "root", and secondary sub-projects called "child-1" and "child-2", so your tree looks like this:
base/path/to/root/
├── child-1/
│ ├── index.js
│ └── package.json
├── child-2/
│ └── package.json
├── ...
└── package.jsonI really really need to get the path of the "root" folder from "child-1/index.js".
Using this package, you can add a .marker file to your "root" folder, and using this snippet, you can get it!
import { findMarker } from "find-marker";
const rootPath = findMarker();
// -> "base/path/to/root"You can pass options to the findMarker function:
| option | description | type | default | 
|---|---|---|---|
| recursive? | Whether to search recursively for the marker file. | boolean | false | 
| file? | The name of the marker file. | string | ".marker" | 
Examples
findMarker({ file: "package.json" });
//-> Will search for the closest package.jsonfindMarker({ recursive: true, file: ".prettierrc" });
//-> Will recursively search for the closest .prettierrcLicense
MIT (c) 2023 Saverio Scagnoli