walk-sync

WebJar for walk-sync

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

walk-sync
Last Version

Last Version

0.3.4
Release Date

Release Date

Type

Type

jar
Description

Description

walk-sync
WebJar for walk-sync
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/joliss/node-walk-sync

Download walk-sync

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/walk-sync/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>walk-sync</artifactId>
    <version>0.3.4</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/walk-sync/
implementation 'org.webjars.npm:walk-sync:0.3.4'
// https://jarcasting.com/artifacts/org.webjars.npm/walk-sync/
implementation ("org.webjars.npm:walk-sync:0.3.4")
'org.webjars.npm:walk-sync:jar:0.3.4'
<dependency org="org.webjars.npm" name="walk-sync" rev="0.3.4">
  <artifact name="walk-sync" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='walk-sync', version='0.3.4')
)
libraryDependencies += "org.webjars.npm" % "walk-sync" % "0.3.4"
[org.webjars.npm/walk-sync "0.3.4"]

Dependencies

compile (2)

Group / Artifact Type Version
org.webjars.npm : ensure-posix-path jar [1.0.0,2)
org.webjars.npm : matcher-collection jar [1.0.0,2)

Project Modules

There are no modules declared in this project.

node-walk-sync

Build Status Build status

Return an array containing all recursive files and directories under a given directory, similar to Unix find. Follows symlinks. Bare-bones, but very fast.

Similar to wrench.readdirSyncRecursive, but adds trailing slashes to directories.

Not to be confused with node-walk, which has both an asynchronous and a synchronous API.

Installation

yarn add walk-sync

Usage

const walkSync = require('walk-sync');
const paths = walkSync('project')

Given project/one.txt and project/subdir/two.txt, paths will be the following array:

['one.txt', 'subdir/', 'subdir/two.txt']

Directories come before their contents, and have a trailing forward-slash (on all platforms).

Symlinks are followed.

Entries

Sometimes, it is important to get additional information from a walk of a directory; for instance if the downstream consumer needs to stat the files we can leverage the stats from the walk.

To accommodate, walkSync.entries(path [, options]) is also provided, instead of returning a list of files and/or directories it returns an array of objects which correspond to a given file or directory, except with more data.

entry.relativePath
entry.mode  // => fs.statSync(fullPath).mode
entry.size  // => fs.statSync(fullPath).size
entry.mtime // => fs.statSync(fullPath).mtime.getTime()

entry.isDirectory() // => true if directory

Options

  • globs: An array of globs. Only files and directories that match at least one of the provided globs will be returned.

    const paths = walkSync('project', { globs: ['subdir/**/*.txt'] });
    // => ['subdir/two.txt']

    As an alternative to string globs, you can pass an array of precompiled minimatch.Minimatch instances. This is faster and allows to specify your own globbing options.

  • directories (default: true): Pass false to only return files, not directories:

    const paths = walkSync('project', { directories: false })
    // => ['one.txt', 'subdir/two.txt']
  • ignore: An array of globs. Files and directories that match at least one of the provided globs will be pruned while searching.

    const paths = walkSync('project', { ignore: ['subdir'] })
    // => ['one.txt']

    As an alternative to string globs, you can pass an array of precompiled minimatch.Minimatch instances. This is faster and allows to specify your own globbing options.

  • includeBasePath (default: false): Pass true to include the basePath in the output. note: this flag is only for walkSync(..) not walkSync.entries(..)

     const paths = walkSync('project', { includeBasePath: true });
     // => ['project/one.txt', 'project/subdir/two.txt']
  • fs: Allows an alternative implementation of fs to be supplied. examples of alternative filesystems include memfs or graceful-fs

     import {Volume, createFsFromVolume} from 'memfs'
     const fs = createFsFromVolume(Volume.fromJSON({'aDir/aFile': 'some-contents'}))
     const paths = walkSync('project', { fs });
     // => ['aDir/', 'aDir/aFile']
  • globOptions: Pass any options for Minimatch that will be applied to all items in globs and ignore that are strings.

    If items in globs or ignore are instances of minimatch.Minimatch, the globOptions will not be applied.

Background

walkSync(baseDir) is a faster substitute for

glob.sync('**', {
  cwd: baseDir,
  dot: true,
  mark: true,
  strict: true
})

Versions

Version
0.3.4
0.3.2
0.3.1
0.2.5