open-draft / outvariant Goto Github PK
View Code? Open in Web Editor NEWType-safe implementation of invariant with positionals.
Home Page: https://npm.im/outvariant
License: MIT License
Type-safe implementation of invariant with positionals.
Home Page: https://npm.im/outvariant
License: MIT License
invariant(false, 'Error message')
at Object.invariant (/Users/kettanaito/Projects/universal-path/url-pattern/node_modules/outvariant/lib/invariant.js:54:15)
36 |
37 | if (char === '*' || char === '+' || char === '?') {
> 38 | invariant(false, 'Error message')
| ^
39 |
40 | tokens.push({ type: 'Modifier', index: i, value: str[i++] })
41 | continue
An exception is thrown with the "Error message" as the error message.
It'd be great for the invariant
to support a custom error class to use instead of the InvariantError
:
Line 25 in 6f4006a
The @mswjs/data library utilizes different error types to distinguish between operational and other exceptions. It cannot use invariant
because it always throws the same error class.
class MyError extends Error {}
invariant.as(MyError, 'Failed to execute "%s" on "%s"', operationName, modelName)
Internally, invariant will throw a new instance of MyError
with the resolved error message passed to its constructor.
invariant(false, 'First part. %s. Second part.`, 'hello')
"First path. hello. Second part."
formatMessage(`
One
Two
Three
`)
The actual output will be:
One
Two
Three
No new lines are present.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.