<commit_before># bash-emulator

[on npm](https://www.npmjs.com/package/bash-emulator)


## Usage

[Example usage](/index.html)

The module exports one function that can be required from another module.
Please use a tool like [webpack](https://webpack.github.io/) or [browserify](http://browserify.org/)
for bundling and minification in your own workflow.

`bashEmulator()`
  - Returns an `emulator` object

### `emulator`

- `run(command)`
  - `command` a bash command as string
  - Returns a `Promise` that resolves with an output string
- `getDir()`
  - Returns a Promise that resolves with the current working directory
- `changeDir(path)`
  - `path` relative path to set working directory to
  - Returns a Promise that resolves when change is done
- `read(filePath)`
  - `filePath` relative path of file to read
  - Returns a Promise that resolves with the content of the file
- `readDir(path)`
  - `path` optional, relative path of directory to read. Defaults to current directory.
  - Returns a Promise that resolves with an array listing all content of the directory
- `getStats(path)`
  - `path` optional path of file or directory. Defaults to current directory.
  - Returns a Promise that resolves with a stats object. For now, only property is `lastEdited`.
- `createDir(path)`
  - `path` relative, non-existed path for new directory
  - Returns a Promise that resolves when directory is created
- `write(filePath)`
  - If file isn't empty, content is appended to it.
  - `filePath` path of file that should be written to. File doesn't have to exist.
  - Returns a Promise that resolves when writing is done
- `remove(path)`
  - `path` path of file or directory to be deleting
  - Returns a Promise that resolves when deleting is done
- `getHistory()`
  - Returns a Promise that resolves with a array containing all commands from the past
- `clearScreen()`
  - Returns a Promise that resolves when clearing is done
- `getDimensions()`
  - Returns a Promise with an dimensions object `{ x, y }`
- `commands`
  - An object with all commands that the emulator knows of
- `state`
  - `history`
  - `fileSystem`
  - `workingDirectory`


### Storing state in `localStorage`

``` js
var state = JSON.parse(localStorage.bashEmulator || 'null')
var emulator = bashEmulator()
if (state) {
  emulator.state = state
}
function saveState () {
  localStorage.bashEmulator = JSON.stringify(emulator.state)
}
emulator.run().then(saveState)
```

### Writing your own commands

You can modify the `commands` object of your emulator instance
to your liking.

To add a new command you need to implement the following API:<commit_msg>API - add return types<commit_after># bash-emulator

[on npm](https://www.npmjs.com/package/bash-emulator)


## Usage

[Example usage](/index.html)

The module exports one function that can be required from another module.
Please use a tool like [webpack](https://webpack.github.io/) or [browserify](http://browserify.org/)
for bundling and minification in your own workflow.

`bashEmulator() -> emulator`
  - Returns an `emulator` object

### `emulator`

- `run(command) -> Promise(output)`
  - `command` a bash command as string
  - Returns a `Promise` that resolves with an output string
- `getDir() -> Promise(path)`
  - Returns a Promise that resolves with the current working directory
- `changeDir(path) -> Promise`
  - `path` relative path to set working directory to
  - Returns a Promise that resolves when change is done
- `read(filePath) -> Promise(content)`
  - `filePath` relative path of file to read
  - Returns a Promise that resolves with the content of the file
- `readDir(path) -> Promise([files])`
  - `path` optional, relative path of directory to read. Defaults to current directory.
  - Returns a Promise that resolves with an array listing all content of the directory
- `getStats(path) -> Promise(stats)`
  - `path` optional path of file or directory. Defaults to current directory.
  - Returns a Promise that resolves with a stats object. For now, only property is `lastEdited`.
- `createDir(path) -> Promise`
  - `path` relative, non-existed path for new directory
  - Returns a Promise that resolves when directory is created
- `write(filePath) -> Promise`
  - If file isn't empty, content is appended to it.
  - `filePath` path of file that should be written to. File doesn't have to exist.
  - Returns a Promise that resolves when writing is done
- `remove(path) -> Promise`
  - `path` path of file or directory to be deleting
  - Returns a Promise that resolves when deleting is done
- `getHistory() -> Promise([commands])`
  - Returns a Promise that resolves with a array containing all commands from the past
- `clearScreen() -> Promise`
  - Returns a Promise that resolves when clearing is done
- `getDimensions() -> Promise(dimensions)`
  - Returns a Promise with an dimensions object `{ x, y }`
- `commands`
  - An object with all commands that the emulator knows of
- `state`
  - `history`
  - `fileSystem`
  - `workingDirectory`


### Storing state in `localStorage`

``` js
var state = JSON.parse(localStorage.bashEmulator || 'null')
var emulator = bashEmulator()
if (state) {
  emulator.state = state
}
function saveState () {
  localStorage.bashEmulator = JSON.stringify(emulator.state)
}
emulator.run().then(saveState)
```

### Writing your own commands

You can modify the `commands` object of your emulator instance
to your liking.

To add a new command you need to implement the following API:
{'fraction_non_alphanumeric': 0.09904796777737093, 'fraction_numerical': 0.0, 'mean_word_length': 3.8995515695067264, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '34840', 'n_tokens_mistral': 1588, 'n_tokens_neox': 1538, 'n_words': 671}