@jblib/should 0.0.2 → 0.0.3

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/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@jblib/should",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
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.3"
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 }
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { shouldBeTrue } from "./should-be-true.js";
2
- export { shouldBeTrue };
package/dist/index.js DELETED
@@ -1,3 +0,0 @@
1
- import { shouldBeTrue } from "./should-be-true.js";
2
-
3
- export { shouldBeTrue };
@@ -1,5 +0,0 @@
1
- //#region src/should-be-true.d.ts
2
- declare const shouldBeTrue: (v: unknown, message?: string) => void;
3
- //#endregion
4
- export { shouldBeTrue };
5
- //# sourceMappingURL=should-be-true.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"should-be-true.d.ts","names":[],"sources":["../src/should-be-true.ts"],"mappings":";cAAM,YAAA,GAAgB,CAAA,WAAY,OAAA"}
@@ -1,8 +0,0 @@
1
- //#region src/should-be-true.ts
2
- const shouldBeTrue = (v, message) => {
3
- if (v !== true) throw new Error(message ?? `should be true, but got ${String(v)}`);
4
- };
5
-
6
- //#endregion
7
- export { shouldBeTrue };
8
- //# sourceMappingURL=should-be-true.js.map
@@ -1 +0,0 @@
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"}