tiny-invariant
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -5,3 +5,2 @@ 'use strict'; | ||
var prefix = 'Invariant failed'; | ||
var index = (function (condition, message) { | ||
@@ -12,7 +11,6 @@ if (condition) { | ||
if (isProduction) { | ||
throw new Error(prefix); | ||
} else { | ||
throw new Error(prefix + ': ' + (message || '')); | ||
throw new Error(prefix + ": " + (message || '')); | ||
} | ||
@@ -19,0 +17,0 @@ }); |
var isProduction = process.env.NODE_ENV === 'production'; | ||
var prefix = 'Invariant failed'; | ||
var index = (function (condition, message) { | ||
@@ -9,7 +8,6 @@ if (condition) { | ||
if (isProduction) { | ||
throw new Error(prefix); | ||
} else { | ||
throw new Error(prefix + ': ' + (message || '')); | ||
throw new Error(prefix + ": " + (message || '')); | ||
} | ||
@@ -16,0 +14,0 @@ }); |
@@ -8,3 +8,2 @@ (function (global, factory) { | ||
var prefix = 'Invariant failed'; | ||
var index = (function (condition, message) { | ||
@@ -15,5 +14,4 @@ if (condition) { | ||
{ | ||
throw new Error(prefix + ': ' + (message || '')); | ||
throw new Error(prefix + ": " + (message || '')); | ||
} | ||
@@ -20,0 +18,0 @@ }); |
{ | ||
"name": "tiny-invariant", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"keywords": [ | ||
@@ -30,16 +30,16 @@ "invariant", | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-core": "^6.26.3", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2", | ||
"babel-preset-env": "^1.7.0", | ||
"babel-preset-flow": "^6.23.0", | ||
"flow-bin": "^0.78.0", | ||
"jest": "^23.5.0", | ||
"prettier": "^1.14.2", | ||
"@babel/core": "^7.1.2", | ||
"@babel/preset-env": "^7.1.0", | ||
"@babel/preset-flow": "^7.0.0", | ||
"babel-core": "7.0.0-bridge.0", | ||
"babel-jest": "^23.6.0", | ||
"flow-bin": "^0.82.0", | ||
"jest": "^23.6.0", | ||
"prettier": "^1.14.3", | ||
"rimraf": "^2.6.2", | ||
"rollup": "^0.64.1", | ||
"rollup-plugin-babel": "^3.0.7", | ||
"rollup": "^0.66.2", | ||
"rollup-plugin-babel": "^4.0.3", | ||
"rollup-plugin-replace": "^2.0.0", | ||
"rollup-plugin-uglify": "^4.0.0" | ||
"rollup-plugin-uglify": "^6.0.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# Tiny invariant 😎 | ||
# `tiny-invariant` 🔬💥 | ||
@@ -10,7 +10,5 @@ [![Build Status](https://travis-ci.org/alexreardon/tiny-invariant.svg?branch=master)](https://travis-ci.org/alexreardon/tiny-invariant) | ||
* The second argument for `invariant` is a `message`. `invariant` supports passing in messages in a sprintf style. It has internal logic to execute the sprintf substitutions. We have dropped all of this logic. We simply simply allow you to pass a string. 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. You can just do this: `invariant(condition, 'Hello, ${name} - how are you today?')` | ||
* We support a es module build for deduplication | ||
* Full [flowtype](https://flowtype.org) support | ||
## What is `invariant`? | ||
## Usage | ||
An `invariant` function tasks 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. | ||
@@ -26,7 +24,11 @@ ```js | ||
## API: `(value: mixed, message?: string) => void` | ||
## Why `tiny-invariant`? | ||
* `value` is required and can be anything | ||
* `message` is an optional string | ||
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?')` | ||
## API: `(condition: mixed, message?: string) => void` | ||
- `condition` is required and can be anything | ||
- `message` is an optional string | ||
## Installation | ||
@@ -49,6 +51,6 @@ | ||
```js | ||
invariant(condition, message); | ||
invariant(condition, 'My cool message that takes up a lot of kbs'); | ||
``` | ||
into this | ||
Into this | ||
@@ -58,3 +60,3 @@ ```js | ||
if ('production' !== process.env.NODE_ENV) { | ||
invariant(false, argument, argument); | ||
invariant(false, 'My cool message that takes up a lot of kbs'); | ||
} else { | ||
@@ -76,13 +78,16 @@ invariant(false); | ||
> [webpack instructions](https://webpack.js.org/guides/production/#specify-the-mode) | ||
> 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 expect `process.env.NODE_ENV` to be available at module compilation. We cache this value | ||
* We have a `umd` (Universal module definition) build in case you needed it | ||
- 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! | ||
🤘 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7131
89