Coder Social home page Coder Social logo

somewhatabstract / ancesdir Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 0.0 5.56 MB

Find a specific ancestor/root directory given a starting location and a search parameter

License: MIT License

JavaScript 42.86% TypeScript 57.14%
nodejs-modules nodejs nodejs-development paths

ancesdir's Introduction

ancesdir

Node CI codecov npm (tag) Node Version Required

Find a specific ancestor/root directory given a starting location and a search parameter

There are a few packages out there that already support finding the root directory of a project based off assumptions like that directory containing package.json or node_modules. However, this is not always the case. I needed a way to find an ancestor directory that may not always have these markers. So, this provides the means to specify a custom marker file or directory as the means to identify the ancestor that you may need.

This may be useful in a variety of situations. For example, a monorepo where you want to differentiate in development scripts between the root folder of each package, and the root folder of the entire repository.

Getting Started

yarn

yarn add ancesdir

npm

npm install ancesdir

Usage

Default

import ancesdir from "ancesdir";

console.log(ancesdir());

Outputs the absolute path of the first parent directory to the ancesdir package that contains package.json.

In most cases, this is likely all you need.

From Specific Location

import ancesdir from "ancesdir";

console.log(ancesdir(__dirname));

Outputs the absolute path of the first parent directory to __dirname that contains package.json.

Custom Target From Specific Location

import ancesdir from "ancesdir";

console.log(ancesdir(__dirname, ".mymarkerfile");

Outputs the absolute path of the first parent directory that contains a file or directory called .mymarkerfile.

This is useful if you don't have a classic file hierarchy or you want to use this for more advanced use cases where having control over the file system item that identifies your ancestor is useful.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.