flipfind

    0.1.4 • Public • Published

    🔎 🎯 flipfind

    find and resolve files automatically searches nearby paths in an optimized order

    NPM version MIT License fliphub flipfam

    usage

    yarn add flipfind
    npm i flipfind --save
    // can be used as a class for chaining and debugging
    const {Finder} = require('flipfind')
     
    // or as a function for easier fun
    const finder = require('flipfind')

    🔊 debug

    example debug output

    const found = Finder.file('./src/eh').debug().all().asObj().find()

    👣 steps

    to optimize, it will go through the steps in order and return once it finds the correct existing path. If .debug is used with .all, it will go through every step and output the results so you can see the process.

    1. if a file and dir are given, it will attempt to resolve using file + dir
    2. if the given file is absolute, and if it exists
    3. checks with the cwd
    4. checks with require.main extracts the dirname from it
    5. checks the app-root-path
    6. checks a glob for very near files
    • filters to ensure it does-include the file and/or dir passed in through options
    1. checks with the mono-root

    📘 examples

    // will return null
    const found = Finder.file('not-real').find()
     
    // without ext
    Finder.file('eh').find()
    // with ext
    Finder.file('eh.js').find()
    // can use relative,  
    Finder.file('./src/eh').find()
    // or shorthand
    Finder.file('src/eh').find()
    // with dir
    Finder.file('eh').dir('test/fixtures').find()
     
    // return an object
    const {
      abs,
      file,
      name,
      ext,
      dir,
    } = Finder.file('src/eh').asObj().find()
     
    // as function
    find('src/eh')

    📝 todo

    • add fallback for resolving a file that does not yet exist - currently is null, will require an option
    • cache the results

    Install

    npm i flipfind

    DownloadsWeekly Downloads

    10

    Version

    0.1.4

    License

    none

    Last publish

    Collaborators

    • aretecode