# Introduction

## nodejs-notebook

[![npm version](https://badge.fury.io/js/nodejs-notebook.svg)](https://badge.fury.io/js/nodejs-notebook) [![npm](https://img.shields.io/npm/dt/nodejs-notebook)](https://npmjs.com/package/nodejs-notebook) [![GitHub](https://img.shields.io/github/license/gamercoder215/nodejs-notebook.svg)](https://github.com/GamerCoder215/nodejs-notebook) [![GitHub last commit](https://img.shields.io/github/last-commit/gamercoder215/nodejs-notebook.svg)](https://github.com/GamerCoder215/nodejs-notebook/commit/master) ![GitHub issues](https://img.shields.io/github/issues/gamercoder215/nodejs-notebook.svg)

## About

Nodebook (nodejs-notebook) is a multi-use module that allows you to edit, manage, and fetch external files, like different, **notebooks.**

## Installation

`npm install nodejs-notebook`

## Dependencies

* Minimum: node v10.0.0
* [js-yaml](https://www.npmjs.com/package/js-yaml) 4.0.0 or above
* [fs](https://www.npmjs.com/package/fs) (File System) 0.0.1-security or above


# Methods

## Contents

* [clearLog() -> void](/functions#clearlog)

## clearlog()

Resets `.booklog.txt`

*Reset will be logged in the file itself, you can manually remove if you want to.*

`index.js`

```javascript
Nodebook.clearLog();
```

`.booklog.txt`

```
# Beginning of Nodebook Log
[Nodebook  1617894945853] - Reset Logs
```


# Nodebook

These are the default methods for the class "Nodebook."

## Usage

### Nodebook

{% hint style="info" %}
Nodebook has a default class in case you want to edit files that do not have their own custom formatting.
{% endhint %}

#### Setup

```javascript
const Nodebook = require('node-notebook');

const myNotebook = new Nodebook.Nodebook('file name', 'txt');
```

**fileName(options)**

object `options`:

* `options.lower` - Whether or not the name should be turned to lower case.

**Return**: The file name.

```javascript
myNotebook.fileName({ lower: false });
// returns "file_name.txt"
```

**resetFile()**

Resets the file.

```javascript
myNotebook.resetFile();
// resets file_name.txt
```

**deleteFile(delay)**

Deletes the file

number `delay`: Sets how many **seconds** before deleting the file.

```javascript
myNotebook.deleteFile();
// Deletes the file instantly

myNotebook.deleteFile(3);
// Deletes the file in 3 seconds
```

**fetchLine(line)**

Fetches an existing line's content.

number `line`: The line number to get the information from.

```javascript
myNootebook.fetchLine(1);
// fetches the first line

myNotebook.fetchLine(5);
// fetches the fifth line
```

**Return**: The line content.

**deleteLine(line)**

Sets an existing line in the file to empty.

number `line`: The line number to make empty.

```javascript
myNotebook.deleteLine(1);
// sets the first line empty
```

**editLine(line, key)**

Replaces an existing line with a new string.

number `line`: The line number to set it to.

string `key`: The string that will replace the line.

```javascript
myNotebook.editLine(1, 'Welcome!');
// sets the first line to 'Welcome!'
```

**addLine(key)**

Adds a string at the next available line in the file.

string `key`: The string to add at the next available line.

```javascript
myNotebook.addLine('Yippi Ki Yay!');
// adds 'Yippi Ki Yay!' to the next line
```

**content()**

Returns the file's content into a string.

```javascript
console.log(myNotebook.content());
// should log the file's content
```


# JSONotebook

extends Nodebook

"JSONotebook" is a customized class used for JSON (JavaScript Object Notation) files.

## Usage

### Setup

```javascript
const Nodebook = require('nodejs-notebook');

const config = new Nodebook.JSONotebook('config');
```

**note(key, value)**

Properly notes a key and a value into JSON data. Can also replace existing values.

`key`:\
Represents the key to fetch the `value`. Can be anything.

`value`:\
The value that `key` is tied to. Can be anything.

```javascript
config.note('name', 'Alex');
// Sets "name" to "Alex"

config.note('name', 'Alexander');
// Name isn't "Alex" anymore, it is "Alexander"
```

**push(key, newkey)**

Pushes a value into an array.

&#x20;`key`:\
The key that represents the array.

{% hint style="warning" %}
The value tied to the key must be an **existing** array or it will not work
{% endhint %}

`newkey`:\
The value to push into the array. Can be anything.

```javascript
config.push('favorite_colors', 'blue');
// Adds "blue" to array "favorite_colors"
```

**fetch(key)**

Fetches a value based on the key.

`key`:\
The key that represents the value you want to get.

```javascript
const myname = config.fetch('name');
console.log(myname);
// logs "Alexander"
```

**erase(key)**

Erases an existing value from the JSON file.

`key`:\
The key that represents the value you want erased.

```javascript
config.erase('hate_letters');
// Array "hate_letters" does not exist anymore

config.erase('middlename');
// String "middlename" does not exist anymore
```

**toYML()**

Converts the JSON data to YML data.

```javascript
let yml = config.toYML();
console.log(yml.toString());
// logs the JSON data as YML data
```


# JSNotebook

extends Nodebook

"JSNotebook" is used for `.js` (JavaScript) files.

## Usage

### Setup

```javascript
const Nodebook = require('nodejs-notebook');

const status = new Nodebook.JSNotebook('status');
```

**note(value)**

Similar to `addLine(value)` but it does not automatically indent to the new line.

string`value`:\
The value to code in.

```javascript
status.note('console.log(\'Hello World\'');
// Writes down 'console.log('Hello World');
```

**run()**

Runs the JS file using `node <file>`.

```javascript
status.run()

// Logs 'Hello World'
```

**comment(value)**

Inserts a comment.

string `value`:\
The value to comment.

```javascript
let latency = Date.now() - timestamp;

status.comment(`Runtime: ${latency}`);
// Comments 'Runtime: <latency>'
```


# TSNotebook

extends JSNotebook


# JavaNotebook

extends Nodebook

"JavaNotebook" is used for `.java` files.

{% hint style="danger" %}
**JavaNotebook** will not run correctly unless you install [JDK](https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html). It is also in heavy development, so please report bugs on our GitHub page.
{% endhint %}

## Usage

### Setup

```javascript
const Nodebook = require('nodejs-notebook');

const main = new Nodebook.JavaNotebook('Main');
```

{% hint style="info" %}
Nodebook will automatically capitalize lowercase files. Please do your own research if you are wondering why.
{% endhint %}

{% hint style="warning" %}
Classes are **not automatically created**. We may change this in the future.
{% endhint %}

**note(code)**

Insert some code.

```javascript
```


# CPPNotebook

extends Nodebook

"CPPNotebook" is a customized class for C++ (`.cpp`) files.

## Usage

### Setup

```javascript
const Nodebook = require('nodejs-notebook');

const main = new Nodebook.CPPNotebook('main');
```

**note(code)**

Similar to `addLine()` but it does not automatically add an indent.

string `code`:\
The C++ code to add.

```javascript
main.note('#include <iostream>\n\nusing namespace std;\nint main() {\n\ncout << "hello world"\n}'
// Inserts this long line of code that should output "hello world"
```

**comment(comment)**

Insert a C++ Comment.

string `comment`:\
The comment message to add.

```javascript
main.comment('This needs editing, Franchis!');
// Inserts "/* This needs editing , Franchis! */"
```

**compile()**

Attempts to compile the C++ file.

```javascript
main.compile();
// Will output if there were any errors in the console.
```

**include(module)**

Inserts `#include <>` at the top with the module provided.

```javascript
main.include('iostream');
// Inserts "#include <iostream>"
```


# CNotebook

extends Nodebook

"CNotebook" is used for `.c` files.

## Usage

### Setup

```javascript
const Nodebook = require('nodejs-notebook');

const index = new Nodebook.CNotebook('index');
```

**note(code)**

Similar to `addLine()` but it does not automatically add an indent.

string `code`:\
The C code to add.

```javascript
main.note('using namespace std;\nint main() {printf("hello world");\nreturn 0;\n}'
// Inserts this long line of code that should output "hello world"
```

**comment(comment)**

Insert a C Comment.

string `comment`:\
The comment message to add.

```javascript
main.comment('This needs editing, Franchis!');
// Inserts "/* Over here Michael! */"
```

**compile()**

Attempts to compile the C file.

```javascript
main.compile();
// Will output if there were any errors in the terminal.
```

**include(module)**

Inserts `#include <>` with the module name at the top.

```javascript
main.include('stdio.h');
// Inserts "#include <stdio.h>"
```


# HeaderNotebook

extends Nodebook

"HeaderNotebook" is used for `.h` or `.hpp` files.

## Usage

### Setup

```javascript
const Nodebook = require('nodejs-notebook');

const cheader = new Nodebook.HeaderNotebook('kihei');
const cheaderClone = new Nodebook.HeaderNotebook('kihei2', 'c');
// Creates a .h used for C and C++ files

const cppheader = new Nodebook.HeaderNotebook('maloi', 'c++');
// Creates a .hpp used for C++ files

/*
Header defaults to .h when not provided or is not a 
valid language
*/
```

**include(module)**

string `module`:\
The module to include.

```javascript
cheader.include('stdio.h');

cppheader.include('iostream');
```


# TXTNotebook

extends Nodebook

"TXTNotebook" is a customized class used for `.txt` files.

## Usage

### TXTNotebook Setup

```javascript
const Nodebook = require('nodejs-notebook');

const textbook = new Nodebook.TXTNotebook('studies');
```

**note(value)**

Similar to `addLine()` but it does not automatically go to the next line.

string `value`:\
The value to add to the file.

```javascript
textbook.note('Rome wasn\'t built in a day.\nScience is hard.');
```

**erase(value, options)**

Erase word(s) from the `.txt` file.

string `value`:\
The string to erase it from.

object `options`:

* `options.flag`: The flag to delete in RegExp.

```javascript
textbook.erase('R');
// Erases the first instance of 'R'

textbook.erase('.', { flag: 'g' });
// Erases all instances of '.'
```


# MDNotebook

extends Nodebook

"MDNotebook" is a special class used for `.md` (Markdown) files.

## Usage

### Setup

```javascript
const Nodebook = require('nodejs-notebook');

const readme = new Nodebook.MDNotebook('README');
```

**note(value)**

Similar to `addLine()` but it does not automatically create an indent.

`value`:\
The value to add in the markdown file. Can be anything. *Required*

```javascript
readme.note('Welcome to Project!');
```

**createHeader(value, options)**

Creates a header inside the file.

string `value`:\
The value that the header will be. *Required*

object `options`:

* &#x20;`options.type`: The type of header to add. Defaults to h1.

```javascript
readme.createHeader('Installation');
// Adds a h1 called "Installation"

readme.createHeader('Usage', { type: '2'});
// Adds a h2 called "Usage"

readme.createHeader('About Us', { type: 3 });
// Adds a h3 called "About Us"

// Notice how both numbers and number strings are supported...
```

**createLink(url, text)**

Creates a link inside the markdown file.

string `url`:\
The URL that the link points to. *Required*

`text`:\
The text that, when clicked redirects to the URL. Optional.

```javascript
readme.createLink('https://docs.myproject.com');
// Creates a link that redirects to that URL with that URL showing.

readme.createLink('https://docs.myproject.com', 'Docs');
// Creates a link that redirects to that URL with 'Docs' showing.
```

**createList(list, options)**

Creates a list inside the markdown file.

array `list`:\
An array of items to be added to the list.

object `options`:

* `options.type`: The type of list. If `unordered`, list starts with a • . If `ordered`, list goes up numerically. Defaults to `unordered`.

```javascript
readme.createList(['Head Author: Alex', 'Co-Author: James'], { type: 'unordered'})
// Creates an unordered list with the array contents

readme.createList(['Usage', 'Introduction', 'Installation'], { type: 'ordered'});
// Creates an ordered list with the array contents
```


# PlainNotebook

"PlainNotebook" is used for managing files **without** file extensions (such as `.env`, `.gitignore`, etc.)

{% hint style="danger" %}
We are **not** liable for anything you edit or manage maliciously. Be careful when editing certain files such as `.env`.&#x20;
{% endhint %}

## Usage

### Setup

```javascript
const Nodebook = require('nodejs-notebook');

const gitignore = new Nodebook.PlainNotebook('.gitignore');
```

{% hint style="info" %}
A lot of these methods are simiar to [Nodebook](/default-classes/default), even though it is not extended by it.
{% endhint %}

**fileName(options)**

object `options`:

* `options.lower` - Whether or not the name should be turned to lower case.

**Return**: The file name.

```javascript
gitignore.fileName({ lower: false });
// returns ".gitignore"
```

**resetFile()**

Resets the file.

```javascript
gitignore.resetFile();
// resets .gitignore
```

**deleteFile(delay)**

Deletes the file

number `delay`: Sets how many **seconds** before deleting the file.

```javascript
gitignore.deleteFile();
// Deletes the file instantly

gitignore.deleteFile(10);
// Deletes the file in 10 seconds
```

**fetchLine(line)**

Fetches an existing line's content.

number `line`: The line number to get the information from.

```javascript
gitignore.fetchLine(3);
// fetches the third line

gitignore.fetchLine(10);
// fetches the tenth line
```

**Return**: The line content.

**deleteLine(line)**

Sets an existing line in the file to empty.

number `line`: The line number to make empty.

```javascript
gitignore.deleteLine(15);
// sets the fifteenth line empty
```

**editLine(line, key)**

Replaces an existing line with a new string.

number `line`: The line number to set it to.

string `key`: The string that will replace the line.

```javascript
gitignore.editLine(1, 'node_modules/');
// sets the first line to 'node_modules/'
```

**addLine(key)**

Adds a string at the next available line in the file.

string `key`: The string to add at the next available line.

```javascript
gitignore.addLine('package-lock.json');
// adds 'Yippi Ki Yay!' to the next line
```

**content()**

Returns the file's content into a string.

```javascript
console.log(gitignore.content());
// should log the file's content
```


# HTMLNotebook

extends Nodebook

"HTMLNotebook" is used for `.html` files.

## Usage

### Setup

```javascript
const Nodebook = require('nodejs-notebook');

const index = new Nodebook.HTMLNotebook('index');
```

**setTitle(title)**

Sets the `<title>` keyword in `<head>`.

string `title`: The value for the `<title>` element.

```javascript
index.setTitle('My Blog'); // <title> now has the value 'My Blog'
```

**setMeta(property, content)**

Adds/Sets a Metadata (`<meta>`)property to a content

string `property`: The property of the `<meta>`.\
string `content`: The content of the `<meta>`.

```javascript
index.setMeta('ogp:title', 'The Blog of the Century');
```

**setLink(rel, href)**

Adds/Sets a Link (`<link>`)'s relationship (rel) to a value (href)

string `rel`: The relationship of the link to the href.\
string `href`: The href (value) of the link.

```javascript
index.setLink('stylesheet', 'styles/main.css');
```

**addElement(element, value, inBody, selfClose, style, styleclass, styleid, spaces)**

Creates an element, with provided options.

string `element`: The element name. Will be shown between the `<>`.\
string `value`: The element's value. Will be between the starting and finish element. If `selfClose` is set to true, this will be the `href`.\
`optional` boolean `inBody`: Whether or not to put the element inside the `<body>`element. If false, will be put after the `</body>`. Defaults to `true`.\
`optional` boolean `selfClose`: Whether or not the element will self close. If true, an element will not have the `/` closing version and the `value` will be set as the `href`. Defaults to `false`.\
`optional` string `style`: Style parameter for the element. Set to `null` or leave blank for no style.\
`optional` string `styleclass`: The Class the element is in. Set to `null` or leave blank for no class.\
`optional` string `styleid`: The ID the element has. Set to `null` or leave blank for no ID.\
`optional` integer `spaces`: The amount of spaces the element will put in before typing.

```javascript
index.addElement('p', 'This morning I had some coffee!');
index.addElement('p', 'What did you have this morning?', true, false, 'font-weight: bold;');
index.addElement('img', 'https://welovecatsandkittens.com/wp-content/uploads/2017/03/likes.jpg', true, true);
index.addElement('h4', 'My favorite kitten picture', true, false, 'color: light_gray;', 'image-footer', null, 6);
```


# CSSNotebook

extends Nodebook

"CSSNotebook" is used for basic stylesheets or `.css` files. `.scss` is not supported at the moment.

## Usage

### Setup

```javascript
const Nodebook = require('nodejs-notebook');

let styles = new Nodebook.CSSNotebook('styles');
```

**create(type, name)**

Creates a style bracket. I

string `type`: The type of bracket. Must be `class` (classes), `id` (IDs), or `element` (global elements).\
string `name`: The name of the representing bracket.

**Returns:** A CSSStyle with Data. If exists, will return existing CSSStyle.

```javascript
let imageFooter = styles.create('class', 'image-footer');
```


# CSSStyle

"CSSSTyle" represents a style bracket in a `.css` file.&#x20;

## Usage

### Setup

```javascript
const Nodebook = require('nodejs-notebook');

let styles = new Nodebook.CSSNotebook('styles');

let imageFooter = styles.create('class', 'image-footer');
```

### Properties

```javascript
imageFooter.type; // Type of style bracket (class, id, or element)
imageFooter.prefix; // Prefix used in the style bracket ("." for classes, "#' for IDs and "" for elements)
imageFooter.name; // Style Bracket name
imageFooter.file.name; // File Name
imageFooter.file.type; // File Type (css)
```

**newStyle(style, content)**

Creates a new Style inside of the bracket.

string `style`: The style property to add.\
string `content`: The value of the style property.

```javascript
imageFooter.newStyle('opacity', '50%');
imageFooter.newStyle('height', 'auto');
```


# YMLNotebook

extends Nodebook

"YMLNotebook" is used for `.yml` (YAML) files.

## Usage

### Setup

```javascript
const Nodebook = require('nodejs-notebook');

const main = new Nodebook.YMLNotebook('main');
```

**note(key, value)**

Sets the value in a YML file.

string `key`:\
The key to represent the value. Must be a string.

`value`:\
The value that `key` represents. Can be anything.

```javascript
main.note('InJSON', true);
// Records "InJSON: true"

main.note('Message', 'Hello!');
// Records "Message: Hello!
```

**toJSON()**

Converts the file to a JSON file.

**Returns**: An Object representing the JSON file.

```javascript
let mainJSON = main.toJSON();

console.log(mainJSON.InJSON);
// Should log "true"
```

**getValue(key)**

Fetch the value in a YML file.

string `key`:\
The key that represents the value.

**Returns**: The YML Value.

```javascript
console.log(main.getValue('Message'));
// Logs "hello!"
```


# BashNotebook

extends Nodebook

"BashNotebook" is used for `.sh` (Bash/Shell) files.

## Usage

### Setup

```javascript
const Nodebook = require('nodejs-notebook');

const main = new Nodebook.BashNotebook('main');
```

**note(code)**

Similar to `addLine()` but it does not automatically make an indent.

string `code`:\
The code to put in.

```javascript
main.note('echo Hi!');
// Adds 'echo Hi!'
```

**runFile()**

Executes the file.

```javascript
main.runFile();
// Should output "Hi!"
```

**runCMD(command)**

Execute a bash command.

string `command`:\
The command to execute.

```javascript
main.runCMD('git status');
// Runs 'git status'
```


# PYNotebook

extends Nodebook

"PYNotebook" is used for `.py`files.

## Usage

### Setup

```javascript
const Nodebook = require('nodejs-notebook');

let main = new Nodebook.PYNotebook('main');
```

**note(code)**

Similar to `addLine()` but it does not automatically add an indent.

string `code`:\
The Python code to add.

```javascript
main.note('print("hello world"');
// Inserts this long line of code that should output "hello world"
```

**comment(comment)**

Insert a Python Comment.

string `comment`:\
The comment message to add.

```javascript
main.comment('This needs editing, Franchis!');
// Inserts '""" Look over here, Patricia! """'
```

**run()**

Attempts to run the python file.

```javascript
main.run();
// Will output if there were any errors in the console.
```

**import(module)**

Inserts `import ()` at the top with the module provided.

```javascript
main.import("json");
// Inserts "import json"
```


