Socket
Socket
Sign inDemoInstall

tiny-invariant

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiny-invariant - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0-beta.1

8

dist/tiny-invariant.cjs.js
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
var isProduction = process.env.NODE_ENV === 'production';

@@ -13,4 +12,7 @@ var prefix = 'Invariant failed';

}
throw new Error(prefix + ": " + (message || ''));
var provided = typeof message === 'function' ? message() : message;
var value = provided ? prefix + ": " + provided : prefix;
throw new Error(value);
}
exports.default = invariant;
module.exports = invariant;

@@ -1,1 +0,1 @@

export default function invariant(condition: any, message?: string): asserts condition;
export default function invariant(condition: any, message?: string | (() => string)): asserts condition;

@@ -10,5 +10,7 @@ var isProduction = process.env.NODE_ENV === 'production';

}
throw new Error(prefix + ": " + (message || ''));
var provided = typeof message === 'function' ? message() : message;
var value = provided ? prefix + ": " + provided : prefix;
throw new Error(value);
}
export default invariant;
export { invariant as default };

@@ -1,20 +0,23 @@

(function (factory) {
typeof define === 'function' && define.amd ? define(factory) :
factory();
}((function () { 'use strict';
(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';
Object.defineProperty(exports, "__esModule", { value: true });
var isProduction = process.env.NODE_ENV === 'production';
var prefix = 'Invariant failed';
function invariant(condition, message) {
if (condition) {
return;
}
if (isProduction) {
throw new Error(prefix);
}
throw new Error(prefix + ": " + (message || ''));
}
exports.default = invariant;
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 ? prefix + ": " + provided : prefix;
throw new Error(value);
}
})));
return invariant;
}));

@@ -1,1 +0,1 @@

!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.default=function(e,n){if(!e)throw new Error("Invariant failed")}}));
!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")}}));
{
"name": "tiny-invariant",
"version": "1.1.0",
"version": "1.2.0-beta.1",
"description": "A tiny invariant function",
"keywords": [
"invariant",
"error"
"error",
"assert",
"asserts"
],
"description": "A tiny invariant function",
"author": "Alex Reardon <alexreardon@gmail.com>",
"license": "MIT",
"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",

@@ -17,18 +28,28 @@ "module": "dist/tiny-invariant.esm.js",

],
"author": "Alex Reardon <alexreardon@gmail.com>",
"repository": {
"type": "git",
"url": "https://github.com/alexreardon/tiny-invariant.git"
},
"bugs": {
"url": "https://github.com/alexreardon/tiny-invariant/issues"
},
"license": "MIT",
"size-limit": [
{
"path": "dist/tiny-invariant.min.js",
"limit": "175B"
},
{
"path": "dist/tiny-invariant.js",
"limit": "176B"
},
{
"path": "dist/tiny-invariant.cjs.js",
"limit": "164B"
},
{
"path": "dist/tiny-invariant.esm.js",
"import": "foo",
"limit": "49B"
}
],
"scripts": {
"test": "yarn jest",
"lint": "yarn prettier:check",
"test:size": "yarn build && yarn size-limit",
"prettier:write": "yarn prettier --debug-check src/** test/**",
"prettier:check": "yarn prettier --write src/** test/**",
"typecheck": "yarn tsc --noEmit src/*.ts test/*.ts",
"validate": "yarn lint && yarn typecheck",
"typescript:check": "yarn tsc --noEmit src/*.ts test/*.ts",
"validate": "yarn prettier:check && yarn typescript:check",
"build:clean": "rimraf dist",

@@ -42,15 +63,18 @@ "build:flow": "cp src/tiny-invariant.js.flow dist/tiny-invariant.cjs.js.flow",

"devDependencies": {
"@rollup/plugin-replace": "^2.3.0",
"@rollup/plugin-typescript": "^3.0.0",
"@types/jest": "^25.1.0",
"jest": "^25.1.0",
"prettier": "^1.19.1",
"rimraf": "^3.0.1",
"rollup": "^1.30.1",
"rollup-plugin-terser": "^5.2.0",
"ts-expect": "^1.1.0",
"ts-jest": "^25.0.0",
"tslib": "^1.10.0",
"typescript": "^3.7.5"
"@rollup/plugin-replace": "^3.0.0",
"@rollup/plugin-typescript": "^8.3.0",
"@size-limit/preset-small-lib": "^6.0.3",
"@types/jest": "^27.0.2",
"@types/rollup": "^0.54.0",
"expect-type": "^0.13.0",
"jest": "^27.3.1",
"prettier": "^2.4.1",
"rimraf": "^3.0.2",
"rollup": "^2.58.3",
"rollup-plugin-terser": "^7.0.2",
"size-limit": "^6.0.3",
"ts-jest": "^27.0.7",
"tslib": "^2.3.1",
"typescript": "^4.4.4"
}
}

@@ -38,7 +38,13 @@ # tiny-invariant 🔬💥

## API: `(condition: any, message?: string) => void`
## API: `(condition: any, message?: string | (() => string)) => void`
- `condition` is required and can be anything
- `message` is an optional string
- `message` optional `string` or a function that returns a `string` (`() => string`)
Your `message` can be a function that returns a `string` (`() => string`) for the cases where you want to lazily create your error message, such as when they are expensive to make.
```ts
invariant(value, () => getExpensiveMessage());
```
## Installation

@@ -45,0 +51,0 @@

@@ -7,3 +7,6 @@ // @flow

export default function invariant(condition: mixed, message?: string) {
export default function invariant(
condition: mixed,
message?: string | (() => string),
) {
if (condition) {

@@ -10,0 +13,0 @@ return;

@@ -1,2 +0,1 @@

// @flow
const isProduction: boolean = process.env.NODE_ENV === 'production';

@@ -10,3 +9,5 @@ const prefix: string = 'Invariant failed';

condition: any,
message?: string,
// 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 {

@@ -25,3 +26,11 @@ if (condition) {

// *This block will be removed in production builds*
throw new Error(`${prefix}: ${message || ''}`);
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);
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc