Skip to content

Commit

Permalink
add screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
mhkeller committed Mar 25, 2023
1 parent 53928b0 commit 03e0303
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.eslintrc
.editorconfig
screenshots/
assets/
tests/
104 changes: 103 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,110 @@ npm install --save @mhkeller/notify

## Usage

Pass an object to the `notify` function with the following options:

* `m` {String} The message.
* `v` {String} The value.
* `d` {String|String[]|Object} Display options. The most common usage of this is to supply one or more [chalk styles](https://github.com/chalk/chalk). See [advanced styling](#advanced-styling) below for more options.
* `k` {Boolean} [false] Whether to show a desktop notification using [node-notifier](https://github.com/mikaelbr/node-notifier)
* `error` {Error} Pass an error object to get printed out with `console.error` for reference.

All of these are optional. If you omit either the message or the value, that part of the notification won't appear. If you omit a display, it will use the default which bolds the value portion.

![](./assets/default.png)

```js
import notify from '@mhkeller/notify'

notify({ m: 'A notification...', v: 'hello', d: ['blue', 'bold'] });
notify({ m: 'A notification...', v: 'hello', d: 'magenta' });
```

![](./assets/magenta.png)

## Built-in displays

The [chalk styles](https://github.com/chalk/chalk) passed to `d` can be a single string, an array of strings or the name of one of the built-in display styles:

```json
// String
notify({ m: 'A notification...', v: 'hello', d: 'cyan' });

// Array of strings
notify({ m: 'A notification...', v: 'hello', d: ['magenta', 'bold', 'italic', 'underline'] });

// Display name
notify({ m: 'A notification...', v: 'hello', d: 'header' });
```

![](./assets/cyan.png)

![](./assets/magenta-options.png)

![](./assets/header.png)

Here's the full list:

```js
{
header: ['blue', 'bold'],
group: ['magenta', 'bold'],
task: ['cyan', 'bold'],
note: ['gray', 'italic'],
error: {
messageStyle: 'red',
desktop: true,
level: 'error'
},
warn: {
messageStyle: ['yellow', 'bold'],
level: 'warn'
},
change: {
preString: '\n',
messageStyle: 'cyan'
},
success: ['green', 'bold']
}
```

![](./assets/header.png)

![](./assets/group.png)

![](./assets/task.png)

![](./assets/note.png)

![](./assets/error.png)

![](./assets/warn.png)

![](./assets/change.png)

![](./assets/success.png)


## Advanced styling

You can also pass an object to the `d` key. Here are the defalt options:

```js
{
messageStyle: '',
valueStyle: 'bold',
preString: '', // A string that goes before the timestamp. Useful if you want to put a line break character '\n'
postString: '', // Same as pre-string but it gets added to the end
skipPrefix: false, // Skip the bracketed timestamp + project name portion, called the prefix
prefixStyle: { // Styling for the prefix
open: '[',
close: ']',
sep: '|',
timestampStyle: 'gray',
projectNameStyle: ['blue', 'bold']
},
projectName: null, // By default, this is the name of your project directory but you can manually set it to something else here
time: null, // By default, this is the current time, but you can manually set it to something else here
desktop: false, // Show a desktop notification
level: 'log' // Can be 'log', 'warn' or 'error'. Whether the notification gets called through `console.log`, `console.warn` or `console.error`.
}
```
Binary file added assets/change.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cyan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/group.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/magenta-options.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/magenta.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/note.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/task.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/warn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function notify (notification, dflts = {}) {
*/
const defaults = { ...notifyDefaults, ...dflts };

const { m = '', v = '', d = '', error = false, k } = notification;
const { m = '', v = '', d = '', k, error } = notification;

/**
* Configure the display object
Expand All @@ -42,7 +42,7 @@ export default function notify (notification, dflts = {}) {
*/
const mNormal = normalize(m);
const vNormal = normalize(v);
const errorNormal = error ? '\n' + cS(error.stack, { pretty: true }) : '';
const errorNormal = isObject(error) ? '\n' + cS(error.stack, { pretty: true }) : '';

const prefix = constructPrefix(defaults, display);

Expand Down
15 changes: 15 additions & 0 deletions test/notify.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ const tests = [
expected:
'[\x1B[90m12:00:00.10\x1B[39m | \x1B[1m\x1B[34mnotify\x1B[39m\x1B[22m] \x1B[1m\x1B[34mhello\x1B[39m\x1B[22m \x1B[1mvalue\x1B[22m'
},
{
args: [
{ m: 'hello', v: 'value', d: { messageStyle: ['blue', 'bold'], skipPrefix: true } },
{ time: '12:00:00.10' }
],
expected: '\x1B[1m\x1B[34mhello\x1B[39m\x1B[22m \x1B[1mvalue\x1B[22m'
},
{
args: [
{ m: 'hello', v: 'value', d: { messageStyle: ['blue', 'bold'], postString: '\n' } },
{ time: '12:00:00.10' }
],
expected:
'[\x1B[90m12:00:00.10\x1B[39m | \x1B[1m\x1B[34mnotify\x1B[39m\x1B[22m] \x1B[1m\x1B[34mhello\x1B[39m\x1B[22m \x1B[1mvalue\x1B[22m\n'
},
{
args: [
{ m: 'hello', v: 'value', d: ['red', 'bold', 'underline', 'italic'] },
Expand Down

0 comments on commit 03e0303

Please sign in to comment.