initial commit
This commit is contained in:
21
node_modules/tiny-invariant/LICENSE
generated
vendored
Normal file
21
node_modules/tiny-invariant/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Alexander Reardon
|
||||
|
||||
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.
|
||||
105
node_modules/tiny-invariant/README.md
generated
vendored
Normal file
105
node_modules/tiny-invariant/README.md
generated
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
# tiny-invariant 🔬💥
|
||||
|
||||
[](https://travis-ci.org/alexreardon/tiny-invariant)
|
||||
[](https://www.npmjs.com/package/tiny-invariant) [](https://david-dm.org/alexreardon/tiny-invariant)
|
||||

|
||||
[](https://www.npmjs.com/package/tiny-invariant)
|
||||
[](https://www.npmjs.com/package/tiny-invariant)
|
||||
|
||||
A tiny [`invariant`](https://www.npmjs.com/package/invariant) alternative.
|
||||
|
||||
## What is `invariant`?
|
||||
|
||||
An `invariant` function takes a value, and if the value is [falsy](https://github.com/getify/You-Dont-Know-JS/blob/bdbe570600d4e1107d0b131787903ca1c9ec8140/up%20%26%20going/ch2.md#truthy--falsy) then the `invariant` function will throw. If the value is [truthy](https://github.com/getify/You-Dont-Know-JS/blob/bdbe570600d4e1107d0b131787903ca1c9ec8140/up%20%26%20going/ch2.md#truthy--falsy), then the function will not throw.
|
||||
|
||||
```js
|
||||
import invariant from 'tiny-invariant';
|
||||
|
||||
invariant(truthyValue, 'This should not throw!');
|
||||
|
||||
invariant(falsyValue, 'This will throw!');
|
||||
// Error('Invariant violation: This will throw!');
|
||||
```
|
||||
|
||||
You can also provide a function to generate your message, for when your message is expensive to create
|
||||
|
||||
```js
|
||||
import invariant from 'tiny-invariant';
|
||||
|
||||
invariant(value, () => getExpensiveMessage());
|
||||
```
|
||||
|
||||
## Why `tiny-invariant`?
|
||||
|
||||
The [`library: invariant`](https://www.npmjs.com/package/invariant) supports passing in arguments to the `invariant` function in a sprintf style `(condition, format, a, b, c, d, e, f)`. It has internal logic to execute the sprintf substitutions. The sprintf logic is not removed in production builds. `tiny-invariant` has dropped all of the sprintf logic. `tiny-invariant` allows you to pass a single string message. With [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) there is really no need for a custom message formatter to be built into the library. If you need a multi part message you can just do this: `invariant(condition, 'Hello, ${name} - how are you today?')`
|
||||
|
||||
## Type narrowing
|
||||
|
||||
`tiny-invariant` is useful for correctly narrowing types for `flow` and `typescript`
|
||||
|
||||
```ts
|
||||
const value: Person | null = { name: 'Alex' }; // type of value == 'Person | null'
|
||||
invariant(value, 'Expected value to be a person');
|
||||
// type of value has been narrowed to 'Person'
|
||||
```
|
||||
|
||||
## API: `(condition: any, message?: string | (() => string)) => void`
|
||||
|
||||
- `condition` is required and can be anything
|
||||
- `message` optional `string` or a function that returns a `string` (`() => string`)
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
# yarn
|
||||
yarn add tiny-invariant
|
||||
|
||||
# npm
|
||||
npm install tiny-invariant --save
|
||||
```
|
||||
|
||||
## Dropping your `message` for kb savings!
|
||||
|
||||
Big idea: you will want your compiler to convert this code:
|
||||
|
||||
```js
|
||||
invariant(condition, 'My cool message that takes up a lot of kbs');
|
||||
```
|
||||
|
||||
Into this:
|
||||
|
||||
```js
|
||||
if (!condition) {
|
||||
if ('production' !== process.env.NODE_ENV) {
|
||||
invariant(false, 'My cool message that takes up a lot of kbs');
|
||||
} else {
|
||||
invariant(false);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- **Babel**: recommend [`babel-plugin-dev-expression`](https://www.npmjs.com/package/babel-plugin-dev-expression)
|
||||
- **TypeScript**: recommend [`tsdx`](https://github.com/jaredpalmer/tsdx#invariant) (or you can run `babel-plugin-dev-expression` after TypeScript compiling)
|
||||
|
||||
Your bundler can then drop the code in the `"production" !== process.env.NODE_ENV` block for your production builds to end up with this:
|
||||
|
||||
```js
|
||||
if (!condition) {
|
||||
invariant(false);
|
||||
}
|
||||
```
|
||||
|
||||
- rollup: use [rollup-plugin-replace](https://github.com/rollup/rollup-plugin-replace) and set `NODE_ENV` to `production` and then `rollup` will treeshake out the unused code
|
||||
- Webpack: [instructions](https://webpack.js.org/guides/production/#specify-the-mode)
|
||||
|
||||
## Builds
|
||||
|
||||
- We have a `es` (EcmaScript module) build
|
||||
- We have a `cjs` (CommonJS) build
|
||||
- We have a `umd` (Universal module definition) build in case you needed it
|
||||
|
||||
We expect `process.env.NODE_ENV` to be available at module compilation. We cache this value
|
||||
|
||||
## That's it!
|
||||
|
||||
🤘
|
||||
1
node_modules/tiny-invariant/dist/esm/package.json
generated
vendored
Normal file
1
node_modules/tiny-invariant/dist/esm/package.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{ "type": "module" }
|
||||
1
node_modules/tiny-invariant/dist/esm/tiny-invariant.d.ts
generated
vendored
Normal file
1
node_modules/tiny-invariant/dist/esm/tiny-invariant.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export default function invariant(condition: any, message?: string | (() => string)): asserts condition;
|
||||
15
node_modules/tiny-invariant/dist/esm/tiny-invariant.js
generated
vendored
Normal file
15
node_modules/tiny-invariant/dist/esm/tiny-invariant.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
var isProduction = process.env.NODE_ENV === 'production';
|
||||
var prefix = 'Invariant failed';
|
||||
function invariant(condition, message) {
|
||||
if (condition) {
|
||||
return;
|
||||
}
|
||||
if (isProduction) {
|
||||
throw new Error(prefix);
|
||||
}
|
||||
var provided = typeof message === 'function' ? message() : message;
|
||||
var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
|
||||
throw new Error(value);
|
||||
}
|
||||
|
||||
export { invariant as default };
|
||||
17
node_modules/tiny-invariant/dist/tiny-invariant.cjs.js
generated
vendored
Normal file
17
node_modules/tiny-invariant/dist/tiny-invariant.cjs.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
var isProduction = process.env.NODE_ENV === 'production';
|
||||
var prefix = 'Invariant failed';
|
||||
function invariant(condition, message) {
|
||||
if (condition) {
|
||||
return;
|
||||
}
|
||||
if (isProduction) {
|
||||
throw new Error(prefix);
|
||||
}
|
||||
var provided = typeof message === 'function' ? message() : message;
|
||||
var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
|
||||
throw new Error(value);
|
||||
}
|
||||
|
||||
module.exports = invariant;
|
||||
1
node_modules/tiny-invariant/dist/tiny-invariant.d.ts
generated
vendored
Normal file
1
node_modules/tiny-invariant/dist/tiny-invariant.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export default function invariant(condition: any, message?: string | (() => string)): asserts condition;
|
||||
15
node_modules/tiny-invariant/dist/tiny-invariant.esm.js
generated
vendored
Normal file
15
node_modules/tiny-invariant/dist/tiny-invariant.esm.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
var isProduction = process.env.NODE_ENV === 'production';
|
||||
var prefix = 'Invariant failed';
|
||||
function invariant(condition, message) {
|
||||
if (condition) {
|
||||
return;
|
||||
}
|
||||
if (isProduction) {
|
||||
throw new Error(prefix);
|
||||
}
|
||||
var provided = typeof message === 'function' ? message() : message;
|
||||
var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
|
||||
throw new Error(value);
|
||||
}
|
||||
|
||||
export { invariant as default };
|
||||
23
node_modules/tiny-invariant/dist/tiny-invariant.js
generated
vendored
Normal file
23
node_modules/tiny-invariant/dist/tiny-invariant.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.invariant = factory());
|
||||
})(this, (function () { 'use strict';
|
||||
|
||||
var isProduction = process.env.NODE_ENV === 'production';
|
||||
var prefix = 'Invariant failed';
|
||||
function invariant(condition, message) {
|
||||
if (condition) {
|
||||
return;
|
||||
}
|
||||
if (isProduction) {
|
||||
throw new Error(prefix);
|
||||
}
|
||||
var provided = typeof message === 'function' ? message() : message;
|
||||
var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
|
||||
throw new Error(value);
|
||||
}
|
||||
|
||||
return invariant;
|
||||
|
||||
}));
|
||||
1
node_modules/tiny-invariant/dist/tiny-invariant.min.js
generated
vendored
Normal file
1
node_modules/tiny-invariant/dist/tiny-invariant.min.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).invariant=n()}(this,(function(){"use strict";return function(e,n){if(!e)throw new Error("Invariant failed")}}));
|
||||
88
node_modules/tiny-invariant/package.json
generated
vendored
Normal file
88
node_modules/tiny-invariant/package.json
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
{
|
||||
"name": "tiny-invariant",
|
||||
"version": "1.3.1",
|
||||
"description": "A tiny invariant function",
|
||||
"author": "Alex Reardon <alexreardon@gmail.com>",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"invariant",
|
||||
"error",
|
||||
"assert",
|
||||
"asserts"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/alexreardon/tiny-invariant.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/alexreardon/tiny-invariant/issues"
|
||||
},
|
||||
"main": "dist/tiny-invariant.cjs.js",
|
||||
"module": "dist/tiny-invariant.esm.js",
|
||||
"types": "dist/tiny-invariant.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/esm/tiny-invariant.js",
|
||||
"default": {
|
||||
"types": "./dist/tiny-invariant.d.ts",
|
||||
"default": "./dist/tiny-invariant.cjs.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"sideEffects": false,
|
||||
"files": [
|
||||
"/dist",
|
||||
"/src"
|
||||
],
|
||||
"size-limit": [
|
||||
{
|
||||
"path": "dist/tiny-invariant.min.js",
|
||||
"limit": "217B"
|
||||
},
|
||||
{
|
||||
"path": "dist/tiny-invariant.js",
|
||||
"limit": "267B"
|
||||
},
|
||||
{
|
||||
"path": "dist/tiny-invariant.cjs.js",
|
||||
"limit": "171B"
|
||||
},
|
||||
{
|
||||
"path": "dist/tiny-invariant.esm.js",
|
||||
"import": "foo",
|
||||
"limit": "112B"
|
||||
}
|
||||
],
|
||||
"scripts": {
|
||||
"test": "yarn jest",
|
||||
"test:size": "yarn build && yarn size-limit",
|
||||
"prettier:write": "yarn prettier --debug-check src/** test/**",
|
||||
"prettier:check": "yarn prettier --write src/** test/**",
|
||||
"typescript:check": "yarn tsc --noEmit src/*.ts test/*.ts",
|
||||
"validate": "yarn prettier:check && yarn typescript:check",
|
||||
"build:clean": "rimraf dist",
|
||||
"build:flow": "cp src/tiny-invariant.js.flow dist/tiny-invariant.cjs.js.flow",
|
||||
"build:typescript": "tsc ./src/tiny-invariant.ts --emitDeclarationOnly --declaration --outDir ./dist",
|
||||
"build:typescript:esm": "tsc ./src/tiny-invariant.ts --emitDeclarationOnly --declaration --outDir ./dist/esm",
|
||||
"build:dist": "yarn rollup --config rollup.config.js",
|
||||
"build": "yarn build:clean && yarn build:dist && yarn build:typescript && yarn build:typescript:esm",
|
||||
"prepublishOnly": "yarn build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-replace": "^4.0.0",
|
||||
"@rollup/plugin-typescript": "^8.5.0",
|
||||
"@size-limit/preset-small-lib": "^8.1.0",
|
||||
"@types/jest": "^29.0.3",
|
||||
"@types/rollup": "^0.54.0",
|
||||
"expect-type": "^0.14.2",
|
||||
"jest": "^29.0.3",
|
||||
"prettier": "^2.7.1",
|
||||
"rimraf": "^3.0.2",
|
||||
"rollup": "^2.79.1",
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
"size-limit": "^8.1.0",
|
||||
"ts-jest": "^29.0.2",
|
||||
"tslib": "^2.4.0",
|
||||
"typescript": "^4.8.4"
|
||||
}
|
||||
}
|
||||
12
node_modules/tiny-invariant/src/tiny-invariant.flow.js
generated
vendored
Normal file
12
node_modules/tiny-invariant/src/tiny-invariant.flow.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
// @flow
|
||||
// This file is not actually executed
|
||||
// It is just used by flow for typing
|
||||
|
||||
const prefix: string = 'Invariant failed';
|
||||
|
||||
export default function invariant(condition: mixed, message?: string | (() => string)) {
|
||||
if (condition) {
|
||||
return;
|
||||
}
|
||||
throw new Error(`${prefix}: ${message || ''}`);
|
||||
}
|
||||
33
node_modules/tiny-invariant/src/tiny-invariant.ts
generated
vendored
Normal file
33
node_modules/tiny-invariant/src/tiny-invariant.ts
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
const isProduction: boolean = process.env.NODE_ENV === 'production';
|
||||
const prefix: string = 'Invariant failed';
|
||||
|
||||
// Throw an error if the condition fails
|
||||
// Strip out error messages for production
|
||||
// > Not providing an inline default argument for message as the result is smaller
|
||||
export default function invariant(
|
||||
condition: any,
|
||||
// Can provide a string, or a function that returns a string for cases where
|
||||
// the message takes a fair amount of effort to compute
|
||||
message?: string | (() => string),
|
||||
): asserts condition {
|
||||
if (condition) {
|
||||
return;
|
||||
}
|
||||
// Condition not passed
|
||||
|
||||
// In production we strip the message but still throw
|
||||
if (isProduction) {
|
||||
throw new Error(prefix);
|
||||
}
|
||||
|
||||
// When not in production we allow the message to pass through
|
||||
// *This block will be removed in production builds*
|
||||
|
||||
const provided: string | undefined = typeof message === 'function' ? message() : message;
|
||||
|
||||
// Options:
|
||||
// 1. message provided: `${prefix}: ${provided}`
|
||||
// 2. message not provided: prefix
|
||||
const value: string = provided ? `${prefix}: ${provided}` : prefix;
|
||||
throw new Error(value);
|
||||
}
|
||||
Reference in New Issue
Block a user