This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

53
node_modules/fault/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,53 @@
/**
* Create a new `EConstructor`, with the formatted `format` as a first argument.
*
* @template {Error} Fault
* @template {new (reason: string) => Fault} Class
* @param {Class} Constructor
*/
export function create<
Fault extends Error,
Class extends new (reason: string) => Fault
>(
Constructor: Class
): {
(format?: string | null | undefined, ...values: unknown[]): Fault
/** @type {string} */
displayName: string
}
export const fault: {
(format?: string | null | undefined, ...values: unknown[]): Error
/** @type {string} */
displayName: string
} & {
eval: {
(format?: string | null | undefined, ...values: unknown[]): Error
/** @type {string} */
displayName: string
}
range: {
(format?: string | null | undefined, ...values: unknown[]): Error
/** @type {string} */
displayName: string
}
reference: {
(format?: string | null | undefined, ...values: unknown[]): Error
/** @type {string} */
displayName: string
}
syntax: {
(format?: string | null | undefined, ...values: unknown[]): Error
/** @type {string} */
displayName: string
}
type: {
(format?: string | null | undefined, ...values: unknown[]): Error
/** @type {string} */
displayName: string
}
uri: {
(format?: string | null | undefined, ...values: unknown[]): Error
/** @type {string} */
displayName: string
}
}

41
node_modules/fault/index.js generated vendored Normal file
View File

@@ -0,0 +1,41 @@
// @ts-expect-error
import formatter from 'format'
export const fault = Object.assign(create(Error), {
eval: create(EvalError),
range: create(RangeError),
reference: create(ReferenceError),
syntax: create(SyntaxError),
type: create(TypeError),
uri: create(URIError)
})
/**
* Create a new `EConstructor`, with the formatted `format` as a first argument.
*
* @template {Error} Fault
* @template {new (reason: string) => Fault} Class
* @param {Class} Constructor
*/
export function create(Constructor) {
/** @type {string} */
// @ts-expect-error
FormattedError.displayName = Constructor.displayName || Constructor.name
return FormattedError
/**
* 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}
*/
function FormattedError(format, ...values) {
/** @type {string} */
const reason = format ? formatter(format, ...values) : format
return new Constructor(reason)
}
}

22
node_modules/fault/license generated vendored Normal file
View File

@@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2015 Titus Wormer <tituswormer@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

78
node_modules/fault/package.json generated vendored Normal file
View File

@@ -0,0 +1,78 @@
{
"name": "fault",
"version": "2.0.1",
"description": "Functional errors with formatted output",
"license": "MIT",
"keywords": [
"error",
"exception",
"printf",
"sprintf",
"vsprintf",
"format",
"string"
],
"repository": "wooorm/fault",
"bugs": "https://github.com/wooorm/fault/issues",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/wooorm"
},
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"dependencies": {
"format": "^0.2.0"
},
"devDependencies": {
"@types/tape": "^4.0.0",
"c8": "^7.0.0",
"prettier": "^2.0.0",
"remark-cli": "^10.0.0",
"remark-preset-wooorm": "^9.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.46.0"
},
"scripts": {
"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 --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"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"prettier": true
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}

217
node_modules/fault/readme.md generated vendored Normal file
View File

@@ -0,0 +1,217 @@
# fault
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
Functional errors with formatted output.
## 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][esm].
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
```sh
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'
throw fault('Hello %s!', 'Eric')
```
Yields:
```text
Error: Hello Eric!
at FormattedError (~/node_modules/fault/index.js:30:12)
at Object.<anonymous> (~/example.js:3:7)
```
Or, format a float in a type error:
```js
import {fault} from 'fault'
throw fault.type('Who doesnt like %f? 🍰', Math.PI)
```
Yields:
```text
TypeError: Who doesnt like 3.141593? 🍰
at Function.FormattedError [as type] (~/node_modules/fault/index.js:30:12)
at Object.<anonymous> (~/example.js:3:7)
```
## API
This package exports the following identifiers: `fault` and `create`.
There is no default export.
### `fault(format?[, values…])`
Create an error with a printf-like formatted message.
###### Parameters
* `format` (`string`, optional)
— template string
* `values` (`*`, optional)
— values to render in `format`
###### Returns
An [`Error`][error] instance.
###### Formatters
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
See [`samsonjs/format`][fmt] for argument parsing.
###### Other errors
* `fault.eval(format?[, values…])` — [EvalError][]
* `fault.range(format?[, values…])` — [RangeError][]
* `fault.reference(format?[, values…])` — [ReferenceError][]
* `fault.syntax(format?[, values…])` — [SyntaxError][]
* `fault.type(format?[, values…])` — [TypeError][]
* `fault.uri(format?[, values…])` — [URIError][]
#### `create(Constructor)`
Factory to create instances of `ErrorConstructor` with support for formatting.
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
[MIT][license] © [Titus Wormer][author]
<!-- Definitions -->
[build-badge]: https://github.com/wooorm/fault/workflows/main/badge.svg
[build]: https://github.com/wooorm/fault/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/fault.svg
[coverage]: https://codecov.io/github/wooorm/fault
[downloads-badge]: https://img.shields.io/npm/dm/fault.svg
[downloads]: https://www.npmjs.com/package/fault
[size-badge]: https://img.shields.io/bundlephobia/minzip/fault.svg
[size]: https://bundlephobia.com/result?p=fault
[npm]: https://docs.npmjs.com/cli/install
[skypack]: https://www.skypack.dev
[license]: license
[author]: https://wooorm.com
[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
[error]: https://developer.mozilla.org/JavaScript/Reference/Global_Objects/Error
[evalerror]: https://developer.mozilla.org/JavaScript/Reference/Global_Objects/EvalError
[rangeerror]: https://developer.mozilla.org/JavaScript/Reference/Global_Objects/RangeError
[referenceerror]: https://developer.mozilla.org/JavaScript/Reference/Global_Objects/ReferenceError
[syntaxerror]: https://developer.mozilla.org/JavaScript/Reference/Global_Objects/SyntaxError
[typeerror]: https://developer.mozilla.org/JavaScript/Reference/Global_Objects/TypeError
[urierror]: https://developer.mozilla.org/JavaScript/Reference/Global_Objects/URIError.