@kensio/smartass 0.0.1 → 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.
Files changed (2) hide show
  1. package/README.md +48 -2
  2. package/package.json +6 -3
package/README.md CHANGED
@@ -1,3 +1,49 @@
1
- # smartass
1
+ # @kensio/smartass
2
2
 
3
- TypeScript-first test assertion functions with precise type narrowing.
3
+ TypeScript-first test assertion functions with precise type narrowing via
4
+ assertion signatures.
5
+
6
+ See
7
+ [TypeScript assertion functions / assertion signatures](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions)
8
+
9
+ The fluent `expect().toBe()` interface in Jest and Vitest is readable, but is
10
+ unable to provide type information to TypeScript and IntelliSense.
11
+
12
+ This library provides assertion functions with assertion signatures so that you
13
+ can benefit from the extra type information.
14
+
15
+ ```typescript
16
+ import { assertNonNullable } from '@kensio/smartass';
17
+
18
+ const user: { name: string } | undefined = getUser();
19
+ assertNonNullable(user);
20
+ // TypeScript now knows user is neither null nor undefined,
21
+ // so no need for ? or ! operators.
22
+ const userName = user.name;
23
+ ```
24
+
25
+ ```typescript
26
+ import { assertOneOf } from '@kensio/smartass';
27
+
28
+ const status = getStatus();
29
+ assertOneOf(status, ['pending', 'active', 'completed']);
30
+ // TypeScript now knows status is of type 'pending' | 'active' | 'completed'
31
+ ```
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ npm install @kensio/smartass
37
+ ```
38
+
39
+ ## Assertion functions
40
+
41
+ - [assertNonNullable](src/assert/non-nullable/non-nullable.assert.ts)
42
+ - [assertNotEmpty](src/assert/not-empty/not-empty.assert.ts)
43
+ - [assertOneOf](src/assert/one-of/one-of.assert.ts)
44
+ - [assertTypeBigInt](src/assert/type-bigint/type-bigint.assert.ts)
45
+ - [assertTypeBoolean](src/assert/type-boolean/type-boolean.assert.ts)
46
+ - [assertTypeFunction](src/assert/type-function/type-function.assert.ts)
47
+ - [assertTypeNumber](src/assert/type-number/type-number.assert.ts)
48
+ - [assertTypeObject](src/assert/type-object/type-object.assert.ts)
49
+ - [assertTypeString](src/assert/type-string/type-string.assert.ts)
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "author": "Kensio Software",
5
5
  "repository": "https://github.com/KensioSoftware/smartass",
6
6
  "license": "AGPL-3.0",
7
- "version": "0.0.1",
7
+ "version": "0.0.4",
8
8
  "type": "module",
9
9
  "main": "./dist/index.js",
10
10
  "types": "./dist/index.d.ts",
@@ -21,6 +21,9 @@
21
21
  "access": "public"
22
22
  },
23
23
  "sideEffects": false,
24
+ "engines": {
25
+ "node": ">=24.14.0"
26
+ },
24
27
  "keywords": [
25
28
  "test",
26
29
  "assertion",
@@ -48,8 +51,8 @@
48
51
  },
49
52
  "scripts": {
50
53
  "build": "tsc -p tsconfig.build.json",
51
- "fmt": "eslint --fix '{src,test}/**/*.{ts,js}' && prettier --write '{src,test}/**/*.{ts,js,json,md,css,html,yml,yaml}'",
52
- "lint": "eslint '{src,test}/**/*.{ts,js}' && prettier --check '{src,test}/**/*.{ts,js,json,md,css,html,yml,yaml}'",
54
+ "fmt": "eslint --fix '{src,test}/**/*.ts' && prettier --write '{src,test}/**/*.{ts,json,md,css,html,yml,yaml}'",
55
+ "lint": "eslint '{src,test}/**/*.ts' && prettier --check '{src,test}/**/*.{ts,json,md,css,html,yml,yaml}'",
53
56
  "test": "vitest run",
54
57
  "test:coverage": "vitest run --coverage"
55
58
  }