@ffflorian/file-index
TypeScript icon, indicating that this package has built-in type declarations

2.6.2 • Public • Published

file-index License: GPL v3 npm version

Generate a file index.

Prerequisites

Installation

ℹ️ This is a hybrid CommonJS / ESM module.

Run yarn add @ffflorian/file-index or npm install @ffflorian/file-index.

Usage

Definition

function generateIndex(directory: string): Promise<DirEntry>;
function generateIndexSync(directory: string): DirEntry;

interface FileEntry {
  fullPath: string;
  name: string;
  size: number;
  type: 'file';
}

interface LinkEntry {
  fullPath: string;
  name: string;
  type: 'link';
}

interface DirEntry extends Entry {
  directories: {[name: string]: DirEntry};
  files: {[name: string]: FileEntry};
  links: {[name: string]: LinkEntry};
  type: 'directory';
}

YourFile.ts

import {generateIndex} from '@ffflorian/file-index';

generateIndex('./')
  .then(index => {
    // see result
  })
  .catch(error => console.error(error));

generateIndex('./', 5) // with depth of 5
  .then(index => {
    // see result
  })
  .catch(error => console.error(error));

Result

{
  directories: {
    '.github': {
      directories: {},
      files: {
        'main.workflow': {
          fullPath: '/home/user/file-index/.github/main.workflow',
          name: 'main.workflow',
          size: 1369,
          type: 'file',
        },
      },
      fullPath: '/home/user/file-index/.github/',
      links: {},
      name: '.github',
      type: 'directory',
    },
    dist: {
      directories: {},
      files: {
        'fileIndex.d.ts': {
          fullPath: '/home/user/file-index/dist/fileIndex.d.ts',
          name: 'fileIndex.d.ts',
          size: 190,
          type: 'file',
        },
        // ...
      },
      fullPath: '/home/user/file-index/dist/',
      links: {},
      name: 'dist',
      type: 'directory',
    },
    src: {
      directories: {},
      files: {
        'FileIndex.ts': {
          fullPath: '/home/user/file-index/src/FileIndex.ts',
          name: 'FileIndex.ts',
          size: 2635,
          type: 'file',
        },
        // ...
      },
      fullPath: '/home/user/file-index/src/',
      links: {},
      name: 'src',
      type: 'directory',
    },
    // ...
  },
  fullPath: '/home/user/file-index/',
  links: {},
  name: 'file-index',
  type: 'directory',
}

Package Sidebar

Install

npm i @ffflorian/file-index

Weekly Downloads

134

Version

2.6.2

License

GPL-3.0

Unpacked Size

47.8 kB

Total Files

17

Last publish

Collaborators

  • ffflorian