• Version 0.10.1
  • Published
  • 15.7 kB
  • 3 dependencies
  • MIT license


npm i majo
yarn add majo
pnpm add majo


A minimal module to manipulate files.



function majo

majo: () => Majo;

    function outputFile

    outputFile: (
    filepath: string,
    data: any,
    | string
    | {
    encoding?: string | null | undefined;
    mode?: string | number | undefined;
    flag?: string | undefined;
    | null
    | undefined
    ) => Promise<void>;
    • Ensure directory exists before writing file

    function remove

    remove: (arg1: string) => Promise<void>;


      class Majo

      class Majo {}



          property baseDir

          baseDir?: string;
          • Base directory You normally set this by calling .source

          property dotFiles

          dotFiles?: boolean;

            property fileList

            readonly fileList: string[];
            • Get an array of sorted file paths

            property files

            files: { [filename: string]: File };

              property meta

              meta: { [k: string]: any };
              • An object you can use across middleware to share states

              property middlewares

              middlewares: Middleware[];

                property onWrite

                onWrite?: OnWrite;

                  property sourcePatterns

                  sourcePatterns?: string[];

                    method createFile

                    createFile: (relativePath: string, file: File) => this;
                    • Create a new file

                      Parameter relativePath

                      Relative path

                      Parameter file

                    method deleteFile

                    deleteFile: (relativePath: string) => this;
                    • Delete a file

                      Parameter relativePath

                      Relative path

                    method dest

                    dest: (dest: string, options?: DestOptions) => Promise<this>;
                    • Run middlewares and write processed files to disk

                      Parameter dest

                      Target directory

                      Parameter opts


                      opts.baseDir Base directory to resolve target directory


                      opts.clean Clean directory before writing

                    method file

                    file: (relativePath: string) => File;
                    • Get a file by relativePath path

                      Parameter relativePath

                      Relative path

                    method fileContents

                    fileContents: (relativePath: string) => string;
                    • Get file contents as a UTF-8 string

                      Parameter relativePath

                      Relative path

                    method fileStats

                    fileStats: (relativePath: string) => fs.Stats;
                    • Get the fs.Stats object of specified file relativePath Relative path

                    method filter

                    filter: (fn: FilterHandler) => this;
                    • Filter files

                      Parameter fn

                      Filter handler

                    method process

                    process: () => Promise<this>;
                    • Process middlewares against files

                    method rename

                    rename: (fromPath: string, toPath: string) => this;

                      method source

                      source: (patterns: string | string[], options?: SourceOptions) => this;
                      • Find files from specific directory

                        Parameter source

                        Glob patterns

                        Parameter opts


                        opts.baseDir The base directory to find files


                        opts.dotFiles Including dot files

                      method transform

                      transform: (relativePath: string, fn: TransformHandler) => Promise<void>;
                      • Transform file at given path

                        Parameter relativePath

                        Relative path

                        Parameter fn

                        Transform handler

                      method use

                      use: (middleware: Middleware) => this;
                      • Use a middleware

                      method writeContents

                      writeContents: (relativePath: string, contents: string) => this;
                      • Write contents to specific file

                        Parameter relativePath

                        Relative path

                        Parameter string

                        File content as a UTF-8 string


                      interface DestOptions

                      interface DestOptions {}

                        property baseDir

                        baseDir?: string;
                        • The base directory to write files to process.cwd()

                        property clean

                        clean?: boolean;
                        • Whether to clean output directory before writing files false

                        interface File

                        interface File {}

                          property contents

                          contents: Buffer;

                            property path

                            path: string;
                            • The absolute path of the file

                            property stats

                            stats: fs.Stats;

                              interface SourceOptions

                              interface SourceOptions {}

                                property baseDir

                                baseDir?: string;
                                • The base directory to search files from process.cwd()

                                property dotFiles

                                dotFiles?: boolean;
                                • Whether to include dot files true

                                property onWrite

                                onWrite?: OnWrite;
                                • This function is called when a file is written

                                Type Aliases

                                type FilterHandler

                                type FilterHandler = (relativePath: string, file: File) => boolean;

                                  type Middleware

                                  type Middleware = (ctx: Majo) => Promise<void> | void;

                                    type OnWrite

                                    type OnWrite = (relativePath: string, outputPath: string) => void;

                                      type TransformHandler

                                      type TransformHandler = (contents: string) => Promise<string> | string;

                                        Package Files (1)

                                        Dependencies (3)

                                        Dev Dependencies (14)

                                        Peer Dependencies (0)

                                        No peer dependencies.


                                        To add a badge like this badgeto your package's README, use the codes available below.

                                        You may also use to create a custom badge linking to

                                        • Markdown
                                        • HTML
                                          <a href=""><img src="" alt=""></a>