📦
unwrapit
  • 👋Welcome to unwrapit
  • Intro
    • 💡Why use it?
    • ✨Getting Started
  • APIs
    • 🔨wrap
    • 🔨unwrap
    • 🔨unwrapOr
    • 🔨unwrapOrElse
    • 🔨expect
    • 🔨mapErr
    • 🔨defineWrapConfig
    • 🔨ok
    • 🔨err
  • Type
    • 🔧Result
    • 🔧WrapConfig
    • 🔧WrapOption
    • 🔧Panic
  • Recipe
    • 🎨Export Wrapped Functions
    • 🎨Return Result Without `wrap` it
Powered by GitBook
On this page
  1. APIs

unwrap

PreviouswrapNextunwrapOr

Last updated 1 year ago

<T>(opt?: WrapOption) => T | never

Try to get the value, will panic when the wrapped value is an error.

const wrapper = await wrap(Promise.resolve(1))
const json = wrapper.unwrap() // 1

In Node.js, you can specify {panic: true} to let the program exit instead of throwing an error.

// this will exit the program in Node.js
(await wrap(Promise.reject(1))).unwrap({panic: true})

If you want to enable panic always in Node.js, you can specify the panic option in .

Exit code

If you need to specify an exit code in Node.js, you can pass the exitCode to unwrap method.

(await wrap(Promise.reject(1))).unwrap({panic: true, exitCode: 2})
🔨
WrapConfig