npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fs-searching

v1.0.10

Published

Utilities for working with files.

Downloads

4

Readme

file-utils

Utilities for working with files.

Methods: // generate random string from string

  • randomString(size: number = 7, source?: string) // find file(s) /folder(s)
  • find(path: string, options: FindOptions): Promise<Map<string, IFindResult>> // iterate files /folders
  • foreachFiles(map: Map<string, IFindResult>, callback: (file: IItemFindFile) => void | Promise): Promise
  • foreachFolders(map: Map<string, IFindResult>, callback: (file: IItemFindFile) => void | Promise): Promise //find duplicate files/folders (duplicate names)
  • findFileDuplicates(paths: string[],options: FindOptions,checkDuplicateFolder = false): Promise<Map<string, string[]>> // generate uuid
  • getUUID(version: 1 | 4): string // generate name from original and check exist file
  • genFileName(fileName: string, opt: IGenerateOpt = {}): string // converting an interval from time to a string
  • timeConverter(startTime: number, endTime: number = Date.now()): string | number

Files search:

FindOptions
interface IFindOptions {
    recursive: boolean;
    maxSlave: number; // default = -1 - all child folders
    folderLevel: boolean; //return result only folders

    filterExts: FindExtension[];
    filterNames: FindFileNames[];
    filterFolders: FindFolderNames[];

    filter?: (item: IItemFindFile) => Promise<boolean>; // You can tell whether to add an item to the result or not
}
  • extension
FSUtils.find('.', <FindOptions>{
    filterExts: [
        // new FindExtension(['*']),                // include all files, defauld method=equals
        // new FindExtension(['json']),             // include all json files
        new FindExtension(['on'], EFindMethod.endsWith),
        {extensions: ['js', 'ts'], include: false, method: EFindMethod.equals},
        {extensions: ['md'], include: true, method: EFindMethod.startsWith},
    ]
})
  • filter by file name
FSUtils.find('.', <FindOptions>{
    filterNames: [
        // new FindFileNames(['*'], EFindMethod.startsWith,  true),
        // new FindFileNames(['pa', 'fs', 'fi'], EFindMethod.startsWith,  false),
        new FindFileNames(['pa'], EFindMethod.startsWith, true),
        // new FindFileNames(['pa', 'je', 'fs'], EFindMethod.startsWith,  true)
        new FindFileNames(['config'], EFindMethod.endsWith, true),
        new FindFileNames(['ign'], EFindMethod.indexOf, true),
        new FindFileNames(['tsconfig'], EFindMethod.equals, false),
        new FindFileNames(['pti'], EFindMethod.match, true),
        new FindFileNames(['lock', 'util'], EFindMethod.match, false),
    ]
})
  • filter by path folder
FSUtils.find('.', <FindOptions>{
    filterNames: [
        new FindFileNames(['*'], EFindMethod.equals, false),
    ],
    filterFolders: [
        new FindFolderNames(['coverage'], EFindMethod.equals, true)
    ]
})
  • recursion/slave/structure
await FSUtils.find('./../pcu/', <FindOptions>{
    recursive: true,
    maxSlave: 1,  // max slave, start from folder pcu/src/
    folderLevel: true  // result will be only as structure of folders
})
  • manual filter file or folder
await FSUtils.find('./../pcu/', <FindOptions>{
    recursive: true,
    maxSlave: 3,
    filter: (item => {
        return Promise.resolve(item.dirent.isFile()); // filter only if it is a file.
    })
})
  • foreach/files/folder
const map = await FSUtils.find('.', <FindOptions>{
    recursive: true,
    filterFolders: [
        new FindFolderNames(['node_modules'], EFindMethod.equals, false)
    ],
});
const files: string[] = [];
await FSUtils.foreachFiles(map, file => {
    files.push(file.fullPath)
});
const folders: string[] = [];
await FSUtils.foreachFolders(map, folder => {
    folders.push(folder.name)
})
  • duplicate
FSUtils.findFileDuplicates(['.'], <FindOptions>{
    recursive: true,
    filterFolders: [
        new FindFolderNames(['node_modules'], EFindMethod.equals, false)
    ],
}, false /*(file / folder)*/);
  • genFileName
interface IGenerateOpt {
    checkExistFile?: boolean;         // if true, there is resolved with process.cwd()
    rootDir?: string;                 // if checkExistFile=true && !rootDir, rootDir=process.cwd()

    type?: 'uuid' | 'date' | 'random' | 'val' // default 'uuid'
    offOriginName?: boolean;          //default false
    tmpVal?: string;

    randLength?: number;              //default 6
    uuidVersion?: 1 | 4;              //default 4

    separator?: string;               //default '_'
    side?: 'r' | 'l';                 //right|left default 'r'
}
FSUtils.genFileName('example.txt', {
    type:"uuid",
    uuidVersion:4,
    side:"l",
    separator:'===',
})
// console.log
//4aa642a0-6a94-4bfb-a2d6-de3050d8c309===example.txt