Code Monkey home page Code Monkey logo

fs-walker's Introduction

@saulx/fs-walker

Walks folders and runs function on each item that matches. Uses @saulx/walker check for more details.

import { fsWalk } from '@saulx/fs-walker;

const result = []
await fsWalk('./path_to_walt', async (item, info) => {
  result.push({
    value: item,     // item path
    name: info.name, // file/dir name
    path: info.path, // item path
    type: info.type  // 'file' | 'dir'
  })
}) // returns void

Configurable options:

await fsWalk(
  path,           // starting path
  itemFn,         // function to run for each matched item
  options: {
                  // check walker for details
    itemMatchFn,  // function to choose which items to run itemFn on
    recurseFn,    // function to choose which items to recurse on
    previousPath, // prefix to add to paths
  }
})

Exemple: Get all package.json file paths

const packageJsons = []
await fsWalk(
  './',
  async (item, _info) => {
    packageJsons.push(item)
  },
  {
    itemMatchFn: async (item) =>
      item.type === 'file' && item.name === 'package.json',
    recurseFn: async (item) =>
      item.type === 'dir' &&
      !['node_modules', 'tmp', 'dists'].includes(item.name),
  }
)

fs-walker's People

Contributors

nfrade avatar youzi avatar

Watchers

 avatar  avatar

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.