Skip to content

SylvainTirreau/nodeJSUtils

Repository files navigation

Node.js utils

Some utilities for Node.js

Installation

npm install https://github.com/SylvainTirreau/nodeJSUtils Lazy to register a npm package.

Usage

Walk

Simple version of the Python walkAsync function to get all directories and files in a folder.

As the Python walk function, for each directory in the tree rooted at directory, it yield an array [dirpath, dirnames, filenames].

Asynchronous function

import { os } from 'nodejsutils'
// or
// import { walkAsync as walk } from 'nodejsutils/utils/os'
import {join} from 'path'

const readSrc = async (): Promise<void> => {
  for await (const [root, dirs, files] of os.walkAsync('./src')) {
    for (const name of files) {
      console.log(join(root, name))
    }
    for (const name of dirs){
      console.log(join(root, name))
    }
  }
}

void readSrc()

Synchronous function

import { os } from 'nodejsutils'
// or
// import { walkSync as walk } from 'nodejsutils/utils/os'
import {join} from 'path'

for (const [root, dirs, files] of os.walkSync('./src')) {
  for (const name of files) {
      console.log(join(root, name))
    }
    for (const name of dirs){
      console.log(join(root, name))
    }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published