Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fault

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fault - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

18

index.d.ts

@@ -14,8 +14,8 @@ /**

): {
(format?: string, ...values: unknown[]): Fault
(format?: string | null | undefined, ...values: unknown[]): Fault
/** @type {string} */
displayName: string
}
export var fault: {
(format?: string, ...values: unknown[]): Error
export const fault: {
(format?: string | null | undefined, ...values: unknown[]): Error
/** @type {string} */

@@ -25,3 +25,3 @@ displayName: string

eval: {
(format?: string, ...values: unknown[]): Error
(format?: string | null | undefined, ...values: unknown[]): Error
/** @type {string} */

@@ -31,3 +31,3 @@ displayName: string

range: {
(format?: string, ...values: unknown[]): Error
(format?: string | null | undefined, ...values: unknown[]): Error
/** @type {string} */

@@ -37,3 +37,3 @@ displayName: string

reference: {
(format?: string, ...values: unknown[]): Error
(format?: string | null | undefined, ...values: unknown[]): Error
/** @type {string} */

@@ -43,3 +43,3 @@ displayName: string

syntax: {
(format?: string, ...values: unknown[]): Error
(format?: string | null | undefined, ...values: unknown[]): Error
/** @type {string} */

@@ -49,3 +49,3 @@ displayName: string

type: {
(format?: string, ...values: unknown[]): Error
(format?: string | null | undefined, ...values: unknown[]): Error
/** @type {string} */

@@ -55,3 +55,3 @@ displayName: string

uri: {
(format?: string, ...values: unknown[]): Error
(format?: string | null | undefined, ...values: unknown[]): Error
/** @type {string} */

@@ -58,0 +58,0 @@ displayName: string

@@ -1,5 +0,5 @@

// @ts-ignore
// @ts-expect-error
import formatter from 'format'
export var fault = Object.assign(create(Error), {
export const fault = Object.assign(create(Error), {
eval: create(EvalError),

@@ -22,3 +22,3 @@ range: create(RangeError),

/** @type {string} */
// @ts-ignore
// @ts-expect-error
FormattedError.displayName = Constructor.displayName || Constructor.name

@@ -29,4 +29,8 @@

/**
* @param {string} [format]
* Create an error with a printf-like formatted message.
*
* @param {string|null} [format]
* Template string.
* @param {...unknown} values
* Values to render in `format`.
* @returns {Fault}

@@ -36,5 +40,5 @@ */

/** @type {string} */
var reason = format ? formatter(format, ...values) : format
const reason = format ? formatter(format, ...values) : format
return new Constructor(reason)
}
}
{
"name": "fault",
"version": "2.0.0",
"version": "2.0.1",
"description": "Functional errors with formatted output",

@@ -40,4 +40,4 @@ "license": "MIT",

"prettier": "^2.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"remark-cli": "^10.0.0",
"remark-preset-wooorm": "^9.0.0",
"rimraf": "^3.0.0",

@@ -47,11 +47,11 @@ "tape": "^5.0.0",

"typescript": "^4.0.0",
"xo": "^0.38.0"
"xo": "^0.46.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"prepublishOnly": "npm run build && npm run format",
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
"test": "npm run format && npm run test-coverage"
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},

@@ -67,8 +67,3 @@ "prettier": {

"xo": {
"prettier": true,
"rules": {
"import/no-mutable-exports": "off",
"no-var": "off",
"prefer-arrow-callback": "off"
}
"prettier": true
},

@@ -83,4 +78,5 @@ "remarkConfig": {

"detail": true,
"strict": true
"strict": true,
"ignoreCatch": true
}
}

@@ -10,9 +10,31 @@ # fault

## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`fault(format?[, values…])`](#faultformat-values)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package adds printf-like interpolation to errors.
## When should I use this?
This package useful when you frequently display parameters in error messages
and manual string concatenation is becoming verbose.
## Install
This package is ESM only: Node 12+ is needed to use it and it must be `import`ed
instead of `require`d.
This package is [ESM only][esm].
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
[npm][]:
```sh

@@ -22,6 +44,20 @@ npm install fault

In Deno with [Skypack][]:
```js
import {fault} from 'https://cdn.skypack.dev/fault@2?dts'
```
In browsers with [Skypack][]:
```html
<script type="module">
import {fault} from 'https://cdn.skypack.dev/fault@2?min'
</script>
```
## Use
```js
import fault from 'fault'
import {fault} from 'fault'

@@ -43,5 +79,5 @@ throw fault('Hello %s!', 'Eric')

```js
import fault from 'fault'
import {fault} from 'fault'
throw fault.type('Who doesn’t like %f? \uD83C\uDF70', Math.PI)
throw fault.type('Who doesn’t like %f? 🍰', Math.PI)
```

@@ -59,3 +95,3 @@

This package exports the following identifiers: `fault`, `create`.
This package exports the following identifiers: `fault` and `create`.
There is no default export.

@@ -70,14 +106,22 @@

* `format` (`string`, optional)
— template string
* `values` (`*`, optional)
— values to render in `format`
###### Returns
An [`Error`][error] instance.
###### Formatters
* `%s` — String
* `%b` — Binary
* `%c` — Character
* `%d` — Decimal
* `%f` — Floating point
* `%o` — Octal
* `%x` — Lowercase hexadecimal
* `%X` — Uppercase hexadecimal
The following formatters are supported in `format`:
* `%s` — string
* `%b` — binary
* `%c` — character
* `%d` — decimal
* `%f` — floating point
* `%o` — octal
* `%x` — lowercase hexadecimal
* `%X` — uppercase hexadecimal
* `%` followed by any other character, prints that character

@@ -87,6 +131,2 @@

###### Returns
An instance of [`Error`][error].
###### Other errors

@@ -104,6 +144,31 @@

Factory to create instances of `ErrorConstructor` with support for formatting.
Used internally to wrap the global error constructors, exposed for custom
Used internally to wrap the global error constructors and exposed for custom
errors.
Returns a function just like `fault`.
## Types
This package is fully typed with [TypeScript][].
There are no extra exported types.
## Compatibility
This package is at least compatible with all maintained versions of Node.js.
As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
It also works in Deno and modern browsers.
## Security
This package is safe.
## Related
* [`wooorm/bail`](https://github.com/wooorm/bail)
— throw if given an error
## Contribute
Yes please!
See [How to Contribute to Open Source][contribute].
## License

@@ -133,2 +198,4 @@

[skypack]: https://www.skypack.dev
[license]: license

@@ -138,2 +205,8 @@

[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[typescript]: https://www.typescriptlang.org
[contribute]: https://opensource.guide/how-to-contribute/
[fmt]: https://github.com/samsonjs/format

@@ -140,0 +213,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc