This commit is contained in:
21
node_modules/tiny-warning/LICENSE
generated
vendored
Normal file
21
node_modules/tiny-warning/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.
|
||||
68
node_modules/tiny-warning/README.md
generated
vendored
Normal file
68
node_modules/tiny-warning/README.md
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
# tiny-warning 🔬⚠️
|
||||
|
||||
[](https://travis-ci.org/alexreardon/tiny-warning)
|
||||
[](https://www.npmjs.com/package/tiny-warning) [](https://www.npmjs.com/package/tiny-warning) [](https://david-dm.org/alexreardon/tiny-warning)
|
||||
[](https://www.npmjs.com/package/tiny-warning)
|
||||
[](https://www.npmjs.com/package/tiny-warning)
|
||||
|
||||
A tiny [`warning`](https://www.npmjs.com/package/warning) alternative.
|
||||
|
||||
```js
|
||||
import warning from 'tiny-warning';
|
||||
|
||||
warning(truthyValue, 'This should not log a warning');
|
||||
|
||||
warning(falsyValue, 'This should log a warning');
|
||||
// console.warn('Warning: This should log a warning');
|
||||
```
|
||||
|
||||
## API: `(condition: mixed, message: string) => void`
|
||||
|
||||
- `condition` is required and can be anything
|
||||
- `message` is an required string that will be passed onto `console.warn`
|
||||
|
||||
## Why `tiny-warning`?
|
||||
|
||||
The [`library: warning`](https://www.npmjs.com/package/warning) supports passing in arguments to the `warning` function in a sprintf style `(condition, format, a, b, c, d, e, f)`. It has internal logic to execute the sprintf substitutions. `tiny-warning` has dropped all of the sprintf logic. `tiny-warning` 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: `warning(condition, 'Hello, ${name} - how are you today?')`
|
||||
|
||||
## Dropping your `warning` for kb savings!
|
||||
|
||||
We recommend using [`babel-plugin-dev-expression`](https://www.npmjs.com/package/babel-plugin-dev-expression) to remove `warning` calls from your production build. This saves you kb's as well as avoids logging warnings to the console for production.
|
||||
|
||||
What it does it turn your code that looks like this:
|
||||
|
||||
```js
|
||||
warning(condition, 'My cool message that takes up a lot of kbs');
|
||||
```
|
||||
|
||||
Into this
|
||||
|
||||
```js
|
||||
if ('production' !== process.env.NODE_ENV) {
|
||||
warning(condition, 'My cool message that takes up a lot of kbs');
|
||||
}
|
||||
```
|
||||
|
||||
Your bundler can then drop the code in the `"production" !== process.env.NODE_ENV` block for your production builds
|
||||
|
||||
Final result:
|
||||
|
||||
```js
|
||||
// nothing to see here! 👍
|
||||
```
|
||||
|
||||
> For `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 (because you _know_ you want to deduplicate this super heavy library)
|
||||
- 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!
|
||||
|
||||
🤘
|
||||
22
node_modules/tiny-warning/dist/tiny-warning.cjs.js
generated
vendored
Normal file
22
node_modules/tiny-warning/dist/tiny-warning.cjs.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
var isProduction = process.env.NODE_ENV === 'production';
|
||||
function warning(condition, message) {
|
||||
if (!isProduction) {
|
||||
if (condition) {
|
||||
return;
|
||||
}
|
||||
|
||||
var text = "Warning: " + message;
|
||||
|
||||
if (typeof console !== 'undefined') {
|
||||
console.warn(text);
|
||||
}
|
||||
|
||||
try {
|
||||
throw Error(text);
|
||||
} catch (x) {}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = warning;
|
||||
3
node_modules/tiny-warning/dist/tiny-warning.cjs.js.flow
generated
vendored
Normal file
3
node_modules/tiny-warning/dist/tiny-warning.cjs.js.flow
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
// @flow
|
||||
|
||||
export * from '../src';
|
||||
20
node_modules/tiny-warning/dist/tiny-warning.esm.js
generated
vendored
Normal file
20
node_modules/tiny-warning/dist/tiny-warning.esm.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
var isProduction = process.env.NODE_ENV === 'production';
|
||||
function warning(condition, message) {
|
||||
if (!isProduction) {
|
||||
if (condition) {
|
||||
return;
|
||||
}
|
||||
|
||||
var text = "Warning: " + message;
|
||||
|
||||
if (typeof console !== 'undefined') {
|
||||
console.warn(text);
|
||||
}
|
||||
|
||||
try {
|
||||
throw Error(text);
|
||||
} catch (x) {}
|
||||
}
|
||||
}
|
||||
|
||||
export default warning;
|
||||
27
node_modules/tiny-warning/dist/tiny-warning.js
generated
vendored
Normal file
27
node_modules/tiny-warning/dist/tiny-warning.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global = global || self, global.warning = factory());
|
||||
}(this, function () { 'use strict';
|
||||
|
||||
function warning(condition, message) {
|
||||
{
|
||||
if (condition) {
|
||||
return;
|
||||
}
|
||||
|
||||
var text = "Warning: " + message;
|
||||
|
||||
if (typeof console !== 'undefined') {
|
||||
console.warn(text);
|
||||
}
|
||||
|
||||
try {
|
||||
throw Error(text);
|
||||
} catch (x) {}
|
||||
}
|
||||
}
|
||||
|
||||
return warning;
|
||||
|
||||
}));
|
||||
1
node_modules/tiny-warning/dist/tiny-warning.min.js
generated
vendored
Normal file
1
node_modules/tiny-warning/dist/tiny-warning.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=e||self).warning=n()}(this,function(){"use strict";return function(e,n){}});
|
||||
53
node_modules/tiny-warning/package.json
generated
vendored
Normal file
53
node_modules/tiny-warning/package.json
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"name": "tiny-warning",
|
||||
"version": "1.0.3",
|
||||
"keywords": [
|
||||
"warning",
|
||||
"warn"
|
||||
],
|
||||
"description": "A tiny warning function",
|
||||
"main": "dist/tiny-warning.cjs.js",
|
||||
"module": "dist/tiny-warning.esm.js",
|
||||
"types": "src/index.d.ts",
|
||||
"sideEffects": false,
|
||||
"files": [
|
||||
"/dist",
|
||||
"/src"
|
||||
],
|
||||
"author": "Alex Reardon <alexreardon@gmail.com>",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/alexreardon/tiny-warning.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/alexreardon/tiny-warning/issues"
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "yarn jest",
|
||||
"lint": "yarn prettier --debug-check src/** test/**",
|
||||
"typecheck": "yarn flow",
|
||||
"validate": "yarn lint && yarn flow",
|
||||
"build:clean": "rimraf dist",
|
||||
"build:flow": "echo \"// @flow\n\nexport * from '../src';\" > dist/tiny-warning.cjs.js.flow",
|
||||
"build:dist": "yarn rollup --config rollup.config.js",
|
||||
"build": "yarn build:clean && yarn build:dist && yarn build:flow",
|
||||
"prepublishOnly": "yarn build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.5.0",
|
||||
"@babel/preset-env": "^7.5.0",
|
||||
"@babel/preset-flow": "^7.0.0",
|
||||
"babel-core": "7.0.0-bridge.0",
|
||||
"babel-jest": "^24.8.0",
|
||||
"flow-bin": "0.102.0",
|
||||
"jest": "^24.8.0",
|
||||
"prettier": "1.18.2",
|
||||
"regenerator-runtime": "^0.13.2",
|
||||
"rimraf": "^2.6.3",
|
||||
"rollup": "^1.16.6",
|
||||
"rollup-plugin-babel": "^4.3.3",
|
||||
"rollup-plugin-replace": "^2.2.0",
|
||||
"rollup-plugin-uglify": "^6.0.2"
|
||||
}
|
||||
}
|
||||
1
node_modules/tiny-warning/src/index.d.ts
generated
vendored
Normal file
1
node_modules/tiny-warning/src/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export default function warning(condition: any, message: string): void
|
||||
30
node_modules/tiny-warning/src/index.js
generated
vendored
Normal file
30
node_modules/tiny-warning/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
// @flow
|
||||
const isProduction: boolean = process.env.NODE_ENV === 'production';
|
||||
|
||||
export default function warning(condition: mixed, message: string): void {
|
||||
// don't do anything in production
|
||||
// wrapping in production check for better dead code elimination
|
||||
if (!isProduction) {
|
||||
// condition passed: do not log
|
||||
if (condition) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Condition not passed
|
||||
const text: string = `Warning: ${message}`;
|
||||
|
||||
// check console for IE9 support which provides console
|
||||
// only with open devtools
|
||||
if (typeof console !== 'undefined') {
|
||||
console.warn(text);
|
||||
}
|
||||
|
||||
// Throwing an error and catching it immediately
|
||||
// to improve debugging
|
||||
// A consumer can use 'pause on caught exceptions'
|
||||
// https://github.com/facebook/react/issues/4216
|
||||
try {
|
||||
throw Error(text);
|
||||
} catch (x) {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user