@x-oasis/invariant 0.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # @x-oasis/invariant
2
+
3
+ ## Installation
4
+
5
+ ```bash
6
+ $ npm i @x-oasis/invariant
7
+ ```
8
+
9
+ ## How to use
10
+
11
+ ```typescript
12
+ import invariant from '@x-oasis/invariant'
13
+ ```
14
+
15
+ ## How to run test
16
+
17
+ ```bash
18
+ $ pnpm test
19
+ ```
20
+
21
+ ## Reading More
22
+
23
+ - [Invariant Violation - framesToPop 1 #179](https://github.com/jaredpalmer/after.js/issues/179)
@@ -0,0 +1 @@
1
+ export default function invariant(condition: any, message?: string | (() => string)): asserts condition;
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict'
3
+
4
+ if (process.env.NODE_ENV === 'production') {
5
+ module.exports = require('./invariant.cjs.production.min.js')
6
+ } else {
7
+ module.exports = require('./invariant.cjs.development.js')
8
+ }
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var prefix = 'Invariant failed';
6
+ function invariant(condition, message) {
7
+ if (condition) {
8
+ return;
9
+ }
10
+ var provided = typeof message === 'function' ? message() : message;
11
+ var value = provided ? prefix + ": " + provided : prefix;
12
+ throw new Error(value);
13
+ }
14
+
15
+ exports.default = invariant;
16
+ //# sourceMappingURL=invariant.cjs.development.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invariant.cjs.development.js","sources":["../src/index.ts"],"sourcesContent":["// copy from https://github.com/alexreardon/tiny-invariant\n\nconst isProduction: boolean = process.env.NODE_ENV === 'production';\nconst prefix = 'Invariant failed';\n\n// Throw an error if the condition fails\n// Strip out error messages for production\n// > Not providing an inline default argument for message as the result is smaller\nexport default function invariant(\n condition: any,\n // Can provide a string, or a function that returns a string for cases where\n // the message takes a fair amount of effort to compute\n message?: string | (() => string)\n): asserts condition {\n if (condition) {\n return;\n }\n // Condition not passed\n\n // In production we strip the message but still throw\n if (isProduction) {\n throw new Error(prefix);\n }\n\n // When not in production we allow the message to pass through\n // *This block will be removed in production builds*\n\n const provided: string | undefined =\n typeof message === 'function' ? message() : message;\n\n // Options:\n // 1. message provided: `${prefix}: ${provided}`\n // 2. message not provided: prefix\n const value: string = provided ? `${prefix}: ${provided}` : prefix;\n throw new Error(value);\n}\n"],"names":["prefix","invariant","condition","message","provided","value","Error"],"mappings":";;;;AAGA,IAAMA,MAAM,GAAG,kBAAkB;SAKTC,SAASA,CAC/BC,SAAc,EAGdC,OAAiC;EAEjC,IAAID,SAAS,EAAE;IACb;;EAYF,IAAME,QAAQ,GACZ,OAAOD,OAAO,KAAK,UAAU,GAAGA,OAAO,EAAE,GAAGA,OAAO;EAKrD,IAAME,KAAK,GAAWD,QAAQ,GAAMJ,MAAM,UAAKI,QAAQ,GAAKJ,MAAM;EAClE,MAAM,IAAIM,KAAK,CAACD,KAAK,CAAC;AACxB;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=function(e,r){if(!e)throw new Error("Invariant failed")};
2
+ //# sourceMappingURL=invariant.cjs.production.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invariant.cjs.production.min.js","sources":["../src/index.ts"],"sourcesContent":["// copy from https://github.com/alexreardon/tiny-invariant\n\nconst isProduction: boolean = process.env.NODE_ENV === 'production';\nconst prefix = 'Invariant failed';\n\n// Throw an error if the condition fails\n// Strip out error messages for production\n// > Not providing an inline default argument for message as the result is smaller\nexport default function invariant(\n condition: any,\n // Can provide a string, or a function that returns a string for cases where\n // the message takes a fair amount of effort to compute\n message?: string | (() => string)\n): asserts condition {\n if (condition) {\n return;\n }\n // Condition not passed\n\n // In production we strip the message but still throw\n if (isProduction) {\n throw new Error(prefix);\n }\n\n // When not in production we allow the message to pass through\n // *This block will be removed in production builds*\n\n const provided: string | undefined =\n typeof message === 'function' ? message() : message;\n\n // Options:\n // 1. message provided: `${prefix}: ${provided}`\n // 2. message not provided: prefix\n const value: string = provided ? `${prefix}: ${provided}` : prefix;\n throw new Error(value);\n}\n"],"names":["condition","message","Error"],"mappings":"6FASEA,EAGAC,GAEA,IAAID,EAOF,MAAM,IAAIE,MAlBC"}
@@ -0,0 +1,16 @@
1
+ var isProduction = process.env.NODE_ENV === 'production';
2
+ var prefix = 'Invariant failed';
3
+ function invariant(condition, message) {
4
+ if (condition) {
5
+ return;
6
+ }
7
+ if (isProduction) {
8
+ throw new Error(prefix);
9
+ }
10
+ var provided = typeof message === 'function' ? message() : message;
11
+ var value = provided ? prefix + ": " + provided : prefix;
12
+ throw new Error(value);
13
+ }
14
+
15
+ export default invariant;
16
+ //# sourceMappingURL=invariant.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invariant.esm.js","sources":["../src/index.ts"],"sourcesContent":["// copy from https://github.com/alexreardon/tiny-invariant\n\nconst isProduction: boolean = process.env.NODE_ENV === 'production';\nconst prefix = 'Invariant failed';\n\n// Throw an error if the condition fails\n// Strip out error messages for production\n// > Not providing an inline default argument for message as the result is smaller\nexport default function invariant(\n condition: any,\n // Can provide a string, or a function that returns a string for cases where\n // the message takes a fair amount of effort to compute\n message?: string | (() => string)\n): asserts condition {\n if (condition) {\n return;\n }\n // Condition not passed\n\n // In production we strip the message but still throw\n if (isProduction) {\n throw new Error(prefix);\n }\n\n // When not in production we allow the message to pass through\n // *This block will be removed in production builds*\n\n const provided: string | undefined =\n typeof message === 'function' ? message() : message;\n\n // Options:\n // 1. message provided: `${prefix}: ${provided}`\n // 2. message not provided: prefix\n const value: string = provided ? `${prefix}: ${provided}` : prefix;\n throw new Error(value);\n}\n"],"names":["isProduction","process","env","NODE_ENV","prefix","invariant","condition","message","Error","provided","value"],"mappings":"AAEA,IAAMA,YAAY,GAAYC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY;AACnE,IAAMC,MAAM,GAAG,kBAAkB;SAKTC,SAASA,CAC/BC,SAAc,EAGdC,OAAiC;EAEjC,IAAID,SAAS,EAAE;IACb;;EAKF,IAAIN,YAAY,EAAE;IAChB,MAAM,IAAIQ,KAAK,CAACJ,MAAM,CAAC;;EAMzB,IAAMK,QAAQ,GACZ,OAAOF,OAAO,KAAK,UAAU,GAAGA,OAAO,EAAE,GAAGA,OAAO;EAKrD,IAAMG,KAAK,GAAWD,QAAQ,GAAML,MAAM,UAAKK,QAAQ,GAAKL,MAAM;EAClE,MAAM,IAAII,KAAK,CAACE,KAAK,CAAC;AACxB;;;;"}
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@x-oasis/invariant",
3
+ "version": "0.1.20",
4
+ "description": "invariant function",
5
+ "main": "dist/index.js",
6
+ "typings": "dist/index.d.ts",
7
+ "module": "dist/invariant.esm.js",
8
+ "author": "",
9
+ "license": "ISC",
10
+ "devDependencies": {
11
+ "tsdx": "^0.14.1"
12
+ },
13
+ "scripts": {
14
+ "build": "tsdx build --tsconfig tsconfig.build.json",
15
+ "clean": "rimraf ./dist",
16
+ "test": "vitest",
17
+ "compile": "tsc -p tsconfig.build.json"
18
+ }
19
+ }
package/src/index.ts ADDED
@@ -0,0 +1,36 @@
1
+ // copy from https://github.com/alexreardon/tiny-invariant
2
+
3
+ const isProduction: boolean = process.env.NODE_ENV === 'production';
4
+ const prefix = 'Invariant failed';
5
+
6
+ // Throw an error if the condition fails
7
+ // Strip out error messages for production
8
+ // > Not providing an inline default argument for message as the result is smaller
9
+ export default function invariant(
10
+ condition: any,
11
+ // Can provide a string, or a function that returns a string for cases where
12
+ // the message takes a fair amount of effort to compute
13
+ message?: string | (() => string)
14
+ ): asserts condition {
15
+ if (condition) {
16
+ return;
17
+ }
18
+ // Condition not passed
19
+
20
+ // In production we strip the message but still throw
21
+ if (isProduction) {
22
+ throw new Error(prefix);
23
+ }
24
+
25
+ // When not in production we allow the message to pass through
26
+ // *This block will be removed in production builds*
27
+
28
+ const provided: string | undefined =
29
+ typeof message === 'function' ? message() : message;
30
+
31
+ // Options:
32
+ // 1. message provided: `${prefix}: ${provided}`
33
+ // 2. message not provided: prefix
34
+ const value: string = provided ? `${prefix}: ${provided}` : prefix;
35
+ throw new Error(value);
36
+ }
@@ -0,0 +1,8 @@
1
+ import { expect, test } from 'vitest';
2
+ import invariant from '../src';
3
+
4
+ test('vitest', async () => {
5
+ expect(() => invariant(false, 'my message')).toThrowError(
6
+ 'Invariant failed: my message'
7
+ );
8
+ });
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../../tsconfig.build.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "esModuleInterop": true
6
+ },
7
+
8
+ "include": [
9
+ "src/**/*"
10
+ ]
11
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "jsx": "react",
5
+ "esModuleInterop": true
6
+ }
7
+ }