2.6.0 • Public • Published


    npm version Pipeline Badge

    Pedantry is a readable stream that puts together all files and nested directories in the given directory in sorted order (,, 3/, 3/,, etc). It will also read and as first and last files respectively if found.

    yarn add pedantry
    npm i pedantry

    Table Of Contents


    The main export of the program is the Pedantry duplex stream which should only be used as a Readable.

    import Pedantry from 'pedantry'

    class Pedantry

    A Pedantry instance reads files in order one-by-one and pushes the results further down the pipe.


    Name Type & Description
    constructor new (source: string, options?: !Options) => Pedantry
    Constructor method.
    source* string: The path to the root directory.
    options !Options (optional): Options for Pedantry.

    Create a new readable stream. Upon creation, Pedantry will start reading files in the source directory recursively in the following order:

    1. the content of the file will go first if it exists,
    2. then of all files and directories in the folder recursively in a sorted order (possibly in reverse),
    3. and the content of the file will go last if found.

    Options: Options for Pedantry.

    Name Type Description Default
    reverse boolean Whether to print files in reverse order, i.e., before false
    addNewLine boolean Add a new line separator (\n, \r\n on Windows, or sep from options) between the content of each file. false
    sep string The separator to use between files. os.EOL
    addBlankLine boolean Add a blank line between the content of each file, which is equivalent to inserting \n\n. false
    includeFilename boolean When this is set to true, Pedantry will write data in object mode, pushing an object with file and data properties. New and blank lines will have the file property set to separator. false
    ignoreHidden boolean Don't read files that start with the . symbol. false

    Given the directory structure:


    The usage of Pedantry is as below:

    import Pedantry from 'pedantry'
    const pedantry = new Pedantry('example/test')
    pedantry.pipe(process.stdout) Welcome to Quotes
    This is a collection of quotes.
    ## Mikhail Bulgakov, The Master and Margarita
    “You pronounced your words as if you don’t acknowledge the shadows, or the evil
    either. Would you be so kind as to give a little thought to the question of what
    your good would be doing if evil did not exist, and how the earth would look if
    the shadows were to disappear from it?”
    ## Mikhail Bulgakov, The Master and Margarita
    “I believe you!' the artiste exclaimed finally and extinguishes his gaze. 'I do!
    These eyes are not lying! How many times have I told you that your basic error
    consists in underestimating the significance of the human eye. Understand that
    the tongue can conceal the truth, but the eyes - never! A sudden question is put
    to you, you don't even flinch, in one second you get hold of yourself and know
    what you must say to conceal the truth, and you speak quite convincingly, and
    not a wrinkle on your face moves, but - alas - the truth which the question
    stirs up from the bottom of your soul leaps momentarily into your eyes, and it's
    all over! They see it, and you're caught!”
    ## Mikhail Bulgakov, The Master and Margarita
    “The brick is neither here nor there,' interrupted the stranger in an imposing
    fashion, 'it never merely falls on someone's head from out of nowhere. In your
    case, I can assure you that a brick poses no threat whatsoever. You will die
    another kind of death."
    'And you know just what that will be?' queried Berlioz with perfectly
    understandable irony, letting himself be drawn into a truly absurd conversation.
    'And can you tell me what that is?'
    'Gladly,' replied the stranger. He took Berlioz's measure as if intending to
    make him a suit and muttered something through his teeth that sounded like 'One,
    two.. Mercury in the Second House... the moon has set... six-misfortune...
    evening-seven...' Then he announced loudly and joyously, 'Your head will be cut
    ## Friedrich Nietzsche
    > To live is to suffer, to survive is to find some meaning in the suffering.
    ## Copyright

    Reverse Order

    To print in reverse order, the reverse option can be set. This feature could be useful when writing a blog, for example, as date 23 will follow 22, and in the output it will be printed first.

    With a simpler directory structure:


    It could be printed in reverse:

    import Pedantry from 'pedantry'
    const pedantry = new Pedantry('example/simple-test', {
      reverse: true,


    The Pedantry stream will emit file events when a file is started to be read. The content of this event is the path to the currently read file relative to the source directory.

    import Pedantry from 'pedantry'
    const pedantry = new Pedantry('example/simple-test')
    pedantry.on('file', f => console.log(f))

    Object Mode

    To get access to the currently processed file, Pedantry can be run in object mode, in which it will emit the data event with an object consisting of file and data properties. If blank lines are added, their will be reported as coming from the separator file.

    import Pedantry from 'pedantry'
    import { Transform } from 'stream'
    const pedantry = new Pedantry('example/simple-test', {
      includeFilename: true,
      addBlankLine: true,
    const t = new Transform({
      objectMode: true,
      transform(object, _, next) {
    { file: 'example/simple-test/', data: '\n' }
    { file: 'separator', data: '\n\n' }
    { file: 'example/simple-test/', data: '\n' }
    { file: 'separator', data: '\n\n' }
    { file: 'example/simple-test/', data: '\n' }
    { file: 'separator', data: '\n\n' }
    { file: 'example/simple-test/', data: '\n' }
    { file: 'separator', data: '\n\n' }
    { file: 'example/simple-test/', data: '\n' }
    { file: 'separator', data: '\n\n' }
    { file: 'example/simple-test/', data: '' }

    Ignore Hidden

    To ignore hidden files, the { ignore: hidden } option can be passed to Pedantry. By default, this is set to false.

    The Source The Tree
    import Pedantry from 'pedantry'
    const HIDDEN = 'example/hidden'
    const pedantry = new Pedantry(HIDDEN, {
      ignoreHidden: true,
    ├── .ignore
    The Output hello world

    Copyright & License

    GNU Affero General Public License v3.0

    Art Deco © Art Deco™ 2020 AGPL-3.0


    npm i pedantry

    DownloadsWeekly Downloads






    Unpacked Size

    76.1 kB

    Total Files


    Last publish


    • zvr