@jblib/should 0.0.2 → 0.0.4

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,13 @@
1
+ # jblib should
2
+
3
+ helpful assertions and conditions for typescript.
4
+
5
+ ```ts
6
+ import { shouldNever } from '@jblib/should'
7
+
8
+ const obj = {
9
+ field: in?.thing ?? shouldNever()
10
+ }
11
+ ```
12
+
13
+ fail loudly in conditions that should never be met!
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
+ import { shouldBeFalse } from "./should-be-false.js";
1
2
  import { shouldBeTrue } from "./should-be-true.js";
2
- export { shouldBeTrue };
3
+ import { shouldNever } from "./should-never.js";
4
+ export { shouldBeFalse, shouldBeTrue, shouldNever };
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { shouldBeFalse } from "./should-be-false.js";
1
2
  import { shouldBeTrue } from "./should-be-true.js";
3
+ import { shouldNever } from "./should-never.js";
2
4
 
3
- export { shouldBeTrue };
5
+ export { shouldBeFalse, shouldBeTrue, shouldNever };
@@ -0,0 +1,13 @@
1
+ //#region src/should-be-false.d.ts
2
+ /**
3
+ * shouldBeFalse checks if the provided value is strictly false.
4
+ * If it is not, it throws an error.
5
+ *
6
+ * @param v value that should always be false
7
+ * @param message custom error message to throw if the value is not false
8
+ * @throws {Error} if the value is not false
9
+ */
10
+ declare const shouldBeFalse: (v: unknown, message?: string) => void;
11
+ //#endregion
12
+ export { shouldBeFalse };
13
+ //# sourceMappingURL=should-be-false.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"should-be-false.d.ts","names":[],"sources":["../src/should-be-false.ts"],"mappings":";;;;;;;;;cAQM,aAAA,GAAiB,CAAA,WAAY,OAAA"}
@@ -0,0 +1,16 @@
1
+ //#region src/should-be-false.ts
2
+ /**
3
+ * shouldBeFalse checks if the provided value is strictly false.
4
+ * If it is not, it throws an error.
5
+ *
6
+ * @param v value that should always be false
7
+ * @param message custom error message to throw if the value is not false
8
+ * @throws {Error} if the value is not false
9
+ */
10
+ const shouldBeFalse = (v, message) => {
11
+ if (v !== false) throw new Error(message ?? `should be false, but got ${String(v)}`);
12
+ };
13
+
14
+ //#endregion
15
+ export { shouldBeFalse };
16
+ //# sourceMappingURL=should-be-false.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"should-be-false.js","names":[],"sources":["../src/should-be-false.ts"],"sourcesContent":["/**\n * shouldBeFalse checks if the provided value is strictly false.\n * If it is not, it throws an error.\n *\n * @param v value that should always be false\n * @param message custom error message to throw if the value is not false\n * @throws {Error} if the value is not false\n */\nconst shouldBeFalse = (v: unknown, message?: string): void => {\n if (v !== false) {\n throw new Error(message ?? `should be false, but got ${String(v)}`)\n }\n}\n\nexport { shouldBeFalse }\n"],"mappings":";;;;;;;;;AAQA,MAAM,iBAAiB,GAAY,YAA2B;AAC5D,KAAI,MAAM,MACR,OAAM,IAAI,MAAM,WAAW,4BAA4B,OAAO,EAAE,GAAG"}
@@ -1,4 +1,12 @@
1
1
  //#region src/should-be-true.d.ts
2
+ /**
3
+ * shouldBeTrue checks if the provided value is strictly true.
4
+ * If it is not, it throws an error.
5
+ *
6
+ * @param v value that should always be true
7
+ * @param message custom error message to throw if the value is not true
8
+ * @throws {Error} if the value is not true
9
+ */
2
10
  declare const shouldBeTrue: (v: unknown, message?: string) => void;
3
11
  //#endregion
4
12
  export { shouldBeTrue };
@@ -1 +1 @@
1
- {"version":3,"file":"should-be-true.d.ts","names":[],"sources":["../src/should-be-true.ts"],"mappings":";cAAM,YAAA,GAAgB,CAAA,WAAY,OAAA"}
1
+ {"version":3,"file":"should-be-true.d.ts","names":[],"sources":["../src/should-be-true.ts"],"mappings":";;;;;;;;;cAQM,YAAA,GAAgB,CAAA,WAAY,OAAA"}
@@ -1,4 +1,12 @@
1
1
  //#region src/should-be-true.ts
2
+ /**
3
+ * shouldBeTrue checks if the provided value is strictly true.
4
+ * If it is not, it throws an error.
5
+ *
6
+ * @param v value that should always be true
7
+ * @param message custom error message to throw if the value is not true
8
+ * @throws {Error} if the value is not true
9
+ */
2
10
  const shouldBeTrue = (v, message) => {
3
11
  if (v !== true) throw new Error(message ?? `should be true, but got ${String(v)}`);
4
12
  };
@@ -1 +1 @@
1
- {"version":3,"file":"should-be-true.js","names":[],"sources":["../src/should-be-true.ts"],"sourcesContent":["const shouldBeTrue = (v: unknown, message?: string): void => {\n if (v !== true) {\n throw new Error(message ?? `should be true, but got ${String(v)}`)\n }\n}\n\nexport { shouldBeTrue }\n"],"mappings":";AAAA,MAAM,gBAAgB,GAAY,YAA2B;AAC3D,KAAI,MAAM,KACR,OAAM,IAAI,MAAM,WAAW,2BAA2B,OAAO,EAAE,GAAG"}
1
+ {"version":3,"file":"should-be-true.js","names":[],"sources":["../src/should-be-true.ts"],"sourcesContent":["/**\n * shouldBeTrue checks if the provided value is strictly true.\n * If it is not, it throws an error.\n *\n * @param v value that should always be true\n * @param message custom error message to throw if the value is not true\n * @throws {Error} if the value is not true\n */\nconst shouldBeTrue = (v: unknown, message?: string): void => {\n if (v !== true) {\n throw new Error(message ?? `should be true, but got ${String(v)}`)\n }\n}\n\nexport { shouldBeTrue }\n"],"mappings":";;;;;;;;;AAQA,MAAM,gBAAgB,GAAY,YAA2B;AAC3D,KAAI,MAAM,KACR,OAAM,IAAI,MAAM,WAAW,2BAA2B,OAAO,EAAE,GAAG"}
@@ -0,0 +1,12 @@
1
+ //#region src/should-never.d.ts
2
+ /**
3
+ * shouldNever always throws an error when called.
4
+ * This is useful for failing in areas that should never be reached.
5
+ *
6
+ * @param message custom error message to throw if the value is called
7
+ * @throws {Error} if the value is called
8
+ */
9
+ declare const shouldNever: (message?: string) => never;
10
+ //#endregion
11
+ export { shouldNever };
12
+ //# sourceMappingURL=should-never.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"should-never.d.ts","names":[],"sources":["../src/should-never.ts"],"mappings":";;;;;;;;cAOM,WAAA,GAAe,OAAA"}
@@ -0,0 +1,15 @@
1
+ //#region src/should-never.ts
2
+ /**
3
+ * shouldNever always throws an error when called.
4
+ * This is useful for failing in areas that should never be reached.
5
+ *
6
+ * @param message custom error message to throw if the value is called
7
+ * @throws {Error} if the value is called
8
+ */
9
+ const shouldNever = (message) => {
10
+ throw new Error(message ?? "should never be called");
11
+ };
12
+
13
+ //#endregion
14
+ export { shouldNever };
15
+ //# sourceMappingURL=should-never.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"should-never.js","names":[],"sources":["../src/should-never.ts"],"sourcesContent":["/**\n * shouldNever always throws an error when called.\n * This is useful for failing in areas that should never be reached.\n *\n * @param message custom error message to throw if the value is called\n * @throws {Error} if the value is called\n */\nconst shouldNever = (message?: string): never => {\n throw new Error(message ?? 'should never be called')\n}\n\nexport { shouldNever }\n"],"mappings":";;;;;;;;AAOA,MAAM,eAAe,YAA4B;AAC/C,OAAM,IAAI,MAAM,WAAW,yBAAyB"}
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@jblib/should",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "should, assertions that throw errors when conditions aren't met",
5
5
  "type": "module",
6
6
  "devDependencies": {
7
- "vitest": "^4.1.5",
8
- "typescript": "^6.0.3",
9
7
  "prettier": "^3.8.3",
10
8
  "tsdown": "^0.21.10",
11
- "@jblib/eslint": "0.0.1"
9
+ "typescript": "^6.0.3",
10
+ "vitest": "^4.1.5",
11
+ "@jblib/eslint": "0.0.4"
12
12
  },
13
13
  "keywords": [
14
14
  "should",
package/src/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { shouldBeTrue } from './should-be-true.js'
2
-
3
- export { shouldBeTrue }
1
+ export { shouldBeFalse } from './should-be-false.js'
2
+ export { shouldBeTrue } from './should-be-true.js'
3
+ export { shouldNever } from './should-never.js'
@@ -1,3 +1,11 @@
1
+ /**
2
+ * shouldBeFalse checks if the provided value is strictly false.
3
+ * If it is not, it throws an error.
4
+ *
5
+ * @param v value that should always be false
6
+ * @param message custom error message to throw if the value is not false
7
+ * @throws {Error} if the value is not false
8
+ */
1
9
  const shouldBeFalse = (v: unknown, message?: string): void => {
2
10
  if (v !== false) {
3
11
  throw new Error(message ?? `should be false, but got ${String(v)}`)
@@ -1,3 +1,11 @@
1
+ /**
2
+ * shouldBeTrue checks if the provided value is strictly true.
3
+ * If it is not, it throws an error.
4
+ *
5
+ * @param v value that should always be true
6
+ * @param message custom error message to throw if the value is not true
7
+ * @throws {Error} if the value is not true
8
+ */
1
9
  const shouldBeTrue = (v: unknown, message?: string): void => {
2
10
  if (v !== true) {
3
11
  throw new Error(message ?? `should be true, but got ${String(v)}`)
@@ -0,0 +1,9 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import { shouldNever } from './should-never.js'
4
+
5
+ describe('should never', () => {
6
+ it('should always throw', () => {
7
+ expect(() => shouldNever()).toThrow()
8
+ })
9
+ })
@@ -0,0 +1,12 @@
1
+ /**
2
+ * shouldNever always throws an error when called.
3
+ * This is useful for failing in areas that should never be reached.
4
+ *
5
+ * @param message custom error message to throw if the value is called
6
+ * @throws {Error} if the value is called
7
+ */
8
+ const shouldNever = (message?: string): never => {
9
+ throw new Error(message ?? 'should never be called')
10
+ }
11
+
12
+ export { shouldNever }