All Projects → wooorm → fault

wooorm / fault

Licence: MIT License
Functional errors with formatted output

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to fault

PageStatusTransformer
A low invasive state management on Android
Stars: ✭ 12 (-25%)
Mutual labels:  error
python-yamlable
A thin wrapper of PyYaml to convert Python objects to YAML and back
Stars: ✭ 28 (+75%)
Mutual labels:  format
yii2-number
A number format mask control and input for Yii2 Framework
Stars: ✭ 22 (+37.5%)
Mutual labels:  format
ember-dayjs-helpers
Ember Template helpers based on day.js
Stars: ✭ 19 (+18.75%)
Mutual labels:  format
ErrorLayout
Simple layout to show custom error toast with animation
Stars: ✭ 13 (-18.75%)
Mutual labels:  error
Format.cmake
💅 Stylize your code! Automatic clang-format and cmake-format targets for CMake.
Stars: ✭ 94 (+487.5%)
Mutual labels:  format
ignition
A beautiful error page for PHP apps
Stars: ✭ 171 (+968.75%)
Mutual labels:  error
Simple-YAML
A Java API that provides an easy-to-use way to store data using the YAML format.
Stars: ✭ 68 (+325%)
Mutual labels:  format
pydecker
Simple development tool that simplifies a pythonist's daily tasks.
Stars: ✭ 18 (+12.5%)
Mutual labels:  format
ignition-tinker-tab
An Ignition tab to tinker with your Laravel app
Stars: ✭ 30 (+87.5%)
Mutual labels:  error
micell
A collection of functions for front-end development
Stars: ✭ 16 (+0%)
Mutual labels:  format
FancyTrack
FancyTrack - JavaScript Error Tracking library from @FancyGrid
Stars: ✭ 83 (+418.75%)
Mutual labels:  error
date-php
这是一个Javascript模仿PHP日期时间格式化函数,使用方法和PHP非常类似,有丰富的模板字符,并在原来的基础上增加了一些模板字符。 This is a date function that implement PHP in Javascript. It is very similar to PHP, has rich template characters, and enhances some template characters on the basis of the original.
Stars: ✭ 24 (+50%)
Mutual labels:  format
wrapcheck
A Go linter to check that errors from external packages are wrapped
Stars: ✭ 141 (+781.25%)
Mutual labels:  error
pretty-remarkable
Plugin for prettifying markdown with https://github.com/jonschlinkert/remarkable using custom renderer rules.
Stars: ✭ 22 (+37.5%)
Mutual labels:  format
AutoFormatInputWatcher
This repository contains input watcher for auto formatting digits in edit text
Stars: ✭ 15 (-6.25%)
Mutual labels:  format
ignition-self-diagnosis
Perform self diagnosis checks right on your Ignition error page
Stars: ✭ 19 (+18.75%)
Mutual labels:  error
go-errors
Flexible, general-purpose error handling for Go.
Stars: ✭ 17 (+6.25%)
Mutual labels:  error
ignition-code-editor
Add inline code editing to your ignition page
Stars: ✭ 44 (+175%)
Mutual labels:  error
rust-error-handle
detail rust error handle
Stars: ✭ 47 (+193.75%)
Mutual labels:  error

fault

Build Coverage Downloads Size

Functional errors with formatted output.

Contents

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. In Node.js (version 12.20+, 14.14+, or 16.0+), install with npm:

npm install fault

In Deno with Skypack:

import {fault} from 'https://cdn.skypack.dev/fault@2?dts'

In browsers with Skypack:

<script type="module">
  import {fault} from 'https://cdn.skypack.dev/fault@2?min'
</script>

Use

import {fault} from 'fault'

throw fault('Hello %s!', 'Eric')

Yields:

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:

import {fault} from 'fault'

throw fault.type('Who doesn’t like %f? 🍰', Math.PI)

Yields:

TypeError: Who doesn’t 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 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 for argument parsing.

Other errors

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

Contribute

Yes please! See How to Contribute to Open Source.

License

MIT © Titus Wormer

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].