0.0.3 • Published 6 months ago

find-marker v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Find the closest arbitrary marker file

npm-badge

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.json

I 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:

optiondescriptiontypedefault
recursive?Whether to search recursively for the marker file.booleanfalse
file?The name of the marker file.string".marker"

Examples

findMarker({ file: "package.json" });

//-> Will search for the closest package.json
findMarker({ recursive: true, file: ".prettierrc" });

//-> Will recursively search for the closest .prettierrc

License

MIT (c) 2023 Saverio Scagnoli

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago