Skip to content

Commit

Permalink
fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Eomm committed Dec 12, 2023
1 parent 6ede6dc commit 02aa9a3
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ const {
createDeprecation
} = require('process-warning')

const warning = createWarning('FastifyWarning', 'FSTWRN001', 'Hello %s', { unlimited: true })
const warning = createWarning({
name: 'FastifyWarning',
code: 'FSTWRN001',
message: 'Hello %s',
unlimited: true
})
warning.emit('world')
```

#### Methods

##### `createWarning(name, code, message[, options])`
##### `createWarning({ name, code, message[, unlimited] })`

- `name` (`string`, required) - The error name, you can access it later with
`error.name`. For consistency, we recommend prefixing module error names
Expand All @@ -47,7 +52,7 @@ properties:
once? Defaults to `false`.


##### `createDeprecation(code, message[, options])`
##### `createDeprecation({code, message[, options]})`

This is a wrapper for `warning.create`. It is equivalent to invoking
`warning.create` with the `name` parameter set to "DeprecationWarning".
Expand All @@ -65,21 +70,21 @@ A warning is guaranteed to be emitted at least once.

```js
const { createWarning } = require('process-warning')
const FST_ERROR_CODE = createWarning('FastifyWarning', 'FST_ERROR_CODE', 'message')
const FST_ERROR_CODE = createWarning({ name: 'FastifyWarning', code: 'FST_ERROR_CODE', message: 'message' })
FST_ERROR_CODE.emit()
```

How to use an interpolated string:
```js
const { createWarning } = require('process-warning')
const FST_ERROR_CODE = createWarning('FastifyWarning', 'FST_ERROR_CODE', 'Hello %s')
const FST_ERROR_CODE = createWarning({ name: 'FastifyWarning', code: 'FST_ERROR_CODE', message: 'Hello %s'})
FST_ERROR_CODE.emit('world')
```

The `warning` object has methods and properties for managing the warning's state. Useful for testing.
```js
const { createWarning } = require('process-warning')
const FST_ERROR_CODE = createWarning('FastifyWarning', 'FST_ERROR_CODE', 'Hello %s')
const FST_ERROR_CODE = createWarning({ name: 'FastifyWarning', code: 'FST_ERROR_CODE', message: 'Hello %s'})
console.log(FST_ERROR_CODE.emitted) // false
FST_ERROR_CODE.emit('world')
console.log(FST_ERROR_CODE.emitted) // true
Expand All @@ -92,7 +97,7 @@ FST_ERROR_CODE_2.emit('world') // will not be emitted
How to use an unlimited warning:
```js
const { createWarning } = require('process-warning')
const FST_ERROR_CODE = createWarning('FastifyWarning', 'FST_ERROR_CODE', 'Hello %s', { unlimited: true })
const FST_ERROR_CODE = createWarning({ name: 'FastifyWarning', code: 'FST_ERROR_CODE', message: 'Hello %s', unlimited: true })
FST_ERROR_CODE.emit('world') // will be emitted
FST_ERROR_CODE.emit('world') // will be emitted again
```
Expand Down

0 comments on commit 02aa9a3

Please sign in to comment.