<commit_before># Hermes

Client-side messaging channel for sending data from one browser tab to another with the same origin. Think of it as a PubSub module that can send messages across multiple browser tabs.

To see a demo of Hermes in action, open the included `index.html` file in multiple browser tabs.


## Usage

Get a copy of `hermes.js` and include it in your code:

```html
<script src="/path/to/hermes.js"></script>
```

Hermes also supports AMD, so it can also be included this way:

```js
require(['path/to/hermes'], function(hermes) { });
```

Hermes exposes an object named `hermes` which contains the API methods.


## API

- **`send(name, data)`**: Send data to other browser tabs subscribed to a specified topic.
  - `name`: The name of the topic in which the data will be sent to.
  - `data`: The data to be sent. This needs to be a JSON-serializable object.

  ```js
  hermes.send('some-topic', 'hello world');
  hermes.send('some-topic', { title: 'awesome' });
  ```

- **`on(name, callback)`**: Add a callback function for a specified topic.
  - `name`: The name of the topic to subscribe to.
  - `callback`: The callback function, which accepts a single argument representing the data that was sent originally.

  ```js<commit_msg>add includeSelf parameter details for send function in readme<commit_after># Hermes

Client-side messaging channel for sending data from one browser tab to another with the same origin. Think of it as a PubSub module that can send messages across multiple browser tabs.

To see a demo of Hermes in action, open the included `index.html` file in multiple browser tabs.


## Usage

Get a copy of `hermes.js` and include it in your code:

```html
<script src="/path/to/hermes.js"></script>
```

Hermes also supports AMD, so it can also be included this way:

```js
require(['path/to/hermes'], function(hermes) { });
```

Hermes exposes an object named `hermes` which contains the API methods.


## API

- **`send(name, data, [includeSelf=false])`**: Send data to other browser tabs subscribed to a specified topic.
  - `name`: The name of the topic in which the data will be sent to.
  - `data`: The data to be sent. This needs to be a JSON-serializable object.
  - `includeSelf` (optional, default=false): A boolean indicating whether the data should also be sent to the current tab.

  ```js
  hermes.send('some-topic', 'hello world');
  hermes.send('some-topic', { title: 'awesome' });
  hermes.send('some-topic', { title: 'awesome' }, true);
  ```

- **`on(name, callback)`**: Add a callback function for a specified topic.
  - `name`: The name of the topic to subscribe to.
  - `callback`: The callback function, which accepts a single argument representing the data that was sent originally.

  ```js
{'fraction_non_alphanumeric': 0.112803772216177, 'fraction_numerical': 0.0, 'mean_word_length': 4.014545454545455, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1236704', 'n_tokens_mistral': 821, 'n_tokens_neox': 782, 'n_words': 379}