Pedantry is a readable stream that puts together all files and nested directories in the given directory in sorted order (1.md
, 2.md
, 3/1.md
, 3/1.5.md
, 10.md
, etc). It will also read index.md
and footer.md
as first and last files respectively if found.
yarn add pedantrynpm i pedantry
Table Of Contents
API
The main export of the program is the Pedantry
duplex stream which should only be used as a Readable.
Pedantry
class 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:
- the content of the
index.md
file will go first if it exists, - then of all files and directories in the folder recursively in a sorted order (possibly in reverse),
- and the content of the
footer.md
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., 30-file.md before 1-file.md . |
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:
example/test├── 1-words.md├── 11-to-live.md├── 2-believe.md├── 3-brick.md├── footer.md└── index.md
The usage of Pedantry is as below:
const pedantry = 'example/test'pedantry
# index.md: Welcome to Quotes This is a collection of quotes. ## 1-words.md: Mikhail Bulgakov, The Master and Margarita “You pronounced your words as if you don’t acknowledge the shadows, or the evileither. Would you be so kind as to give a little thought to the question of whatyour good would be doing if evil did not exist, and how the earth would look ifthe shadows were to disappear from it?” ## 2-believe.md: 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 errorconsists in underestimating the significance of the human eye. Understand thatthe tongue can conceal the truth, but the eyes - never! A sudden question is putto you, you don't even flinch, in one second you get hold of yourself and knowwhat you must say to conceal the truth, and you speak quite convincingly, andnot a wrinkle on your face moves, but - alas - the truth which the questionstirs up from the bottom of your soul leaps momentarily into your eyes, and it'sall over! They see it, and you're caught!” ## 3-brick.md: Mikhail Bulgakov, The Master and Margarita “The brick is neither here nor there,' interrupted the stranger in an imposingfashion, 'it never merely falls on someone's head from out of nowhere. In yourcase, I can assure you that a brick poses no threat whatsoever. You will dieanother kind of death." 'And you know just what that will be?' queried Berlioz with perfectlyunderstandable 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 tomake 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 cutoff!” ## 11-to-live.md: Friedrich Nietzsche > To live is to suffer, to survive is to find some meaning in the suffering. ## footer.md: Copyright [source](https://www.goodreads.com/work/quotes/876183?page=2)
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:
example/simple-test├── 1-file.md├── 100-world.md├── 2-test.md├── 21-hello.md├── footer.md└── index.md
It could be printed in reverse:
const pedantry = 'example/simple-test' reverse: truepedantry
index.md100-world.md21-hello.md2-test.md1-file.mdfooter.md
Events
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.
const pedantry = 'example/simple-test'pedantry
index.md1-file.md2-test.md21-hello.md100-world.mdfooter.md
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.
const pedantry = 'example/simple-test' includeFilename: true addBlankLine: trueconst t = objectMode: true { console }pedantry
{ file: 'example/simple-test/index.md', data: 'index.md\n' }{ file: 'separator', data: '\n\n' }{ file: 'example/simple-test/1-file.md', data: '1-file.md\n' }{ file: 'separator', data: '\n\n' }{ file: 'example/simple-test/2-test.md', data: '2-test.md\n' }{ file: 'separator', data: '\n\n' }{ file: 'example/simple-test/21-hello.md', data: '21-hello.md\n' }{ file: 'separator', data: '\n\n' }{ file: 'example/simple-test/100-world.md', data: '100-world.md\n' }{ file: 'separator', data: '\n\n' }{ file: 'example/simple-test/footer.md', data: 'footer.md' }
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 |
---|---|
|
|
The Output | |
|
Copyright & License
GNU Affero General Public License v3.0
© Art Deco™ 2020 |
---|