Giter Site home page Giter Site logo

m0rtadelo / recursive-readdir-async Goto Github PK

View Code? Open in Web Editor NEW
17.0 17.0 7.0 1.53 MB

NPM Module to recursive read directory async (non blocking). Returns Promise. Configurable, extended filtering. progress, etc. Perfect to be used with aplications that can't be blocked.

License: MIT License

JavaScript 1.66% TypeScript 98.34%

recursive-readdir-async's People

Contributors

dependabot[bot] avatar gerhobbelt avatar m0rtadelo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

recursive-readdir-async's Issues

Would you consider adding Typescript type definitions?

I saw #7 adding support for ES6 modules, which is convenient. I currently use this library in a Typescript project via

import { list as rraList } from 'recursive-readdir-async';

Typescript throws a compilation error (that I have to ignore) saying:

TS7016: Could not find a declaration file for module 'recursive-readdir-async'. '/<redacted>/node_modules/recursive-readdir-async/build/module.cjs.js' implicitly has an 'any' type.   Try `npm install @types/recursive-readdir-async` if it exists or add a new declaration (.d.ts) file containing `declare module 'recursive-readdir-async';`

I am not super familiar on how to do that myself, but I see many projects have type definitions under @types. The documentation for that appears to be https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#publish-to-types. This page also has some documentation on how to build in typescript types natively to your library.

Is this something you'd consider doing? Would be a convenience when using this library with typescript. I currently suppress the error with:

// @ts-ignore
import { list as rraList } from 'recursive-readdir-async';

Add title key

Actually file object has:

  • name
  • path
  • fullname
  • extension

Add a title key with the name without extension (mydoc.txt -> mydoc)

special character compatibility

Hi and of course thanks for the great module.

Would you mind introducing special character safety by not using strings in fs functions?

The issue starts with:
FS.readdir(rpath, function (err, files) {

Readdir in this case returns a list of strings (utf8? utf16? not sure about it...) but in certain cases of special characters eg. mixed unicode, the string was translated wrongly and stat fails to work with it.

A safer version is to work with buffers:
FS.readdir(rpath, {encoding: 'buffer'},function (err, files) {

This should allow to work with virtually any file that resides on the filesystem, totally independent of their name composition.

Question about Include option?

Hi,
I'd like includ only c:/root/folder1 from next list:

c:/root/folder1/folder11
c:/root/folder2/folder22
c:/root/folder3/folder33
c:/root/anotherFolder/folder1/folder11

...
const options = {
    mode: rra.LIST,
    recursive: true,
    stats: false,
    ignoreFolders: true,
    extensions: false,
    deep: false,
    realPath: true,
    normalizePath: true,
    include: ['folder1'],
    exclude: [],
    readContent: false,
    encoding: 'base64'
}
const result = await rra.list('c:/root/', options
...

but I got the next result:

c:/root/folder1/folder11
c:/root/anotherFolder/folder1/folder11

Add additional properties to result object

Hi,
can I add additional properties to result object

my attempt, works only for file items, and skips directory items

const tree = await rra.list(config.DOC_ROOT, options, function (obj, index, total) {
            obj.isOpen = false;
            if (!obj.isDirectory && obj.name == "TREE.xlsx")
                return true;
        });

Rename result objec keys and add another custom keys

Hi,
First of all, nice work 👍, thank you!

I'd like to rename object keys, because of some components needs some specific names.
I'm using the next solution, but it would be nice to have a native way

const replaceKeysDeep = (obj, keysMap) => { 
    return _.transform(obj, function (result, value, key) { 
        var currentKey = keysMap[key] || key; 
        result[currentKey] = _.isObject(value) ? replaceKeysDeep(value, keysMap) : value; 
        inner function - replaceKeys
    });
}
const keysMap = {
                path: 'filepath',
                content: 'children'
            };
const result = replaceKeysDeep(tree, keysMap);

also, I'd like to add custom keys, for example isOpen, isChecked which uses some components

How use options include

Hello,

I had in options.include ['.xml'] for get only files with extension '.xml' but not working for me.
I get all files, but in exclude ['.xml'] all xml files not listed ?

const options = {
mode: rra.LIST,
recursive: true,
stats: false,
ignoreFolders: true,
extensions: true,
deep: false,
realPath: true,
normalizePath: true,
include: ['.xml'],
exclude: [],
readContent: false,
encoding: 'base64'
}

Where is my mistake ?

Thanks.

Best Regards

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.