@kensio/smartass 1.9.0 → 1.10.0

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 +77 -9
  2. package/package.json +6 -5
package/README.md CHANGED
@@ -3,6 +3,14 @@
3
3
  TypeScript-first test assertion functions with precise type narrowing via
4
4
  assertion signatures.
5
5
 
6
+ ## Installation
7
+
8
+ ```bash
9
+ npm install @kensio/smartass
10
+ ```
11
+
12
+ ## Type narrowing with assertion signatures
13
+
6
14
  See
7
15
  [TypeScript assertion functions / assertion signatures](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions)
8
16
 
@@ -13,7 +21,7 @@ This library provides assertion functions with assertion signatures so that you
13
21
  can benefit from the extra type information.
14
22
 
15
23
  ```typescript
16
- import { assertNonNullable } from '@kensio/smartass';
24
+ import { assertNonNullable } from "@kensio/smartass";
17
25
 
18
26
  const user: { name: string } | undefined = getUser();
19
27
  assertNonNullable(user);
@@ -23,24 +31,50 @@ const userName = user.name;
23
31
  ```
24
32
 
25
33
  ```typescript
26
- import { assertOneOf } from '@kensio/smartass';
34
+ import { assertOneOf } from "@kensio/smartass";
27
35
 
28
36
  const status = getStatus();
29
- assertOneOf(status, ['pending', 'active', 'completed']);
37
+ assertOneOf(status, ["pending", "active", "completed"]);
30
38
  // TypeScript now knows status is of type 'pending' | 'active' | 'completed'
31
39
  ```
32
40
 
33
- ## Installation
41
+ ## Composable type narrowing matchers
34
42
 
35
- ```bash
36
- npm install @kensio/smartass
43
+ As well as the standalone assertion functions, you can also use type narrowing matcher functions to
44
+ compose an object structure.
45
+
46
+ ```typescript
47
+ import {
48
+ assertObjectMatches,
49
+ arrayIncluding,
50
+ oneOf,
51
+ stringOfLength,
52
+ } from "@kensio/smartass";
53
+
54
+ const user = getUser();
55
+
56
+ assertObjectMatches(user, {
57
+ role: oneOf(["admin", "editor", "viewer"]),
58
+ tags: arrayIncluding("beta"),
59
+ id: stringOfLength(8),
60
+ });
61
+
62
+ // TypeScript knows:
63
+ // user.role is 'admin' | 'editor' | 'viewer'
64
+ // user.tags is an array with at least one string element
65
+ // user.id is a string of length 8 with safe indexing
37
66
  ```
38
67
 
68
+ This applies the same type narrowing effect as the assertion functions but in a composable object
69
+ structure.
70
+
39
71
  ## Assertion functions
40
72
 
73
+ <!-- assertion-functions:start -->
74
+
41
75
  - [assertArrayEquals](src/assert/array-equals/array-equals.assert.ts)
42
- - [assertArrayIncludes](src/assert/array-includes/array-includes.assert.ts)
43
76
  - [assertArrayIncludesAll](src/assert/array-includes-all/array-includes-all.assert.ts)
77
+ - [assertArrayIncludes](src/assert/array-includes/array-includes.assert.ts)
44
78
  - [assertArrayLength](src/assert/array-length/array-length.assert.ts)
45
79
  - [assertArrayMinLength](src/assert/array-min-length/array-min-length.assert.ts)
46
80
  - [assertArrayNotEmpty](src/assert/array-not-empty/array-not-empty.assert.ts)
@@ -60,9 +94,9 @@ npm install @kensio/smartass
60
94
  - [assertStringLength](src/assert/string-length/string-length.assert.ts)
61
95
  - [assertStringNotIncludes](src/assert/string-not-includes/string-not-includes.assert.ts)
62
96
  - [assertStringStartsWith](src/assert/string-starts-with/string-starts-with.assert.ts)
63
- - [assertThrowsError](src/assert/throws-error/throws-error.assert.ts)
64
97
  - [assertThrowsErrorAsync](src/assert/throws-error-async/throws-error-async.assert.ts)
65
98
  - [assertThrowsErrorLike](src/assert/throws-error-like/throws-error-like.assert.ts)
99
+ - [assertThrowsError](src/assert/throws-error/throws-error.assert.ts)
66
100
  - [assertTrue](src/assert/true/true.assert.ts)
67
101
  - [assertTypeBigInt](src/assert/type-bigint/type-bigint.assert.ts)
68
102
  - [assertTypeBoolean](src/assert/type-boolean/type-boolean.assert.ts)
@@ -70,8 +104,42 @@ npm install @kensio/smartass
70
104
  - [assertTypeNumber](src/assert/type-number/type-number.assert.ts)
71
105
  - [assertTypeNumeric](src/assert/type-numeric/type-numeric.assert.ts)
72
106
  - [assertTypeObject](src/assert/type-object/type-object.assert.ts)
73
- - [assertTypeOf](src/assert/typeof/typeof.assert.ts)
74
107
  - [assertTypeString](src/assert/type-string/type-string.assert.ts)
108
+ - [assertTypeSymbol](src/assert/type-symbol/type-symbol.assert.ts)
75
109
  - [assertTypeTypedArray](src/assert/type-typed-array/type-typed-array.assert.ts)
76
110
  - [assertUndefined](src/assert/undefined/undefined.assert.ts)
77
111
  - [assertUuidV4](src/assert/uuid/uuid-v4.assert.ts)
112
+ <!-- assertion-functions:end -->
113
+
114
+ ## Matcher functions
115
+
116
+ <!-- matcher-functions:start -->
117
+
118
+ - [arrayIncludingAll](src/assert/array-includes-all/array-includes-all.match.ts)
119
+ - [arrayIncluding](src/assert/array-includes/array-includes.match.ts)
120
+ - [arrayOfLength](src/assert/array-length/array-length.match.ts)
121
+ - [arrayOfMinLength](src/assert/array-min-length/array-min-length.match.ts)
122
+ - [nonEmptyArray](src/assert/array-not-empty/array-not-empty.match.ts)
123
+ - [bufferEqualTo](src/assert/buffer-equal/buffer-equal.match.ts)
124
+ - [instanceOf](src/assert/instance-of/instance-of.match.ts)
125
+ - [nonNullable](src/assert/non-nullable/non-nullable.match.ts)
126
+ - [numberBetween](src/assert/number-between/number-between.match.ts)
127
+ - [numberToNearest](src/assert/number-to-nearest/number-to-nearest.match.ts)
128
+ - [objectWithProperty](src/assert/object-has-property/object-has-property.match.ts)
129
+ - [oneOf](src/assert/one-of/one-of.match.ts)
130
+ - [stringEndingWith](src/assert/string-ends-with/string-ends-with.match.ts)
131
+ - [stringIncluding](src/assert/string-includes/string-includes.match.ts)
132
+ - [stringOfLength](src/assert/string-length/string-length.match.ts)
133
+ - [stringNotIncluding](src/assert/string-not-includes/string-not-includes.match.ts)
134
+ - [stringStartingWith](src/assert/string-starts-with/string-starts-with.match.ts)
135
+ - [typeBigInt](src/assert/type-bigint/type-bigint.match.ts)
136
+ - [typeBoolean](src/assert/type-boolean/type-boolean.match.ts)
137
+ - [typeFunction](src/assert/type-function/type-function.match.ts)
138
+ - [typeNumber](src/assert/type-number/type-number.match.ts)
139
+ - [typeNumeric](src/assert/type-numeric/type-numeric.match.ts)
140
+ - [typeObject](src/assert/type-object/type-object.match.ts)
141
+ - [typeString](src/assert/type-string/type-string.match.ts)
142
+ - [typeSymbol](src/assert/type-symbol/type-symbol.match.ts)
143
+ - [typeTypedArray](src/assert/type-typed-array/type-typed-array.match.ts)
144
+ - [uuidV4](src/assert/uuid/uuid-v4.match.ts)
145
+ <!-- matcher-functions:end -->
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "url": "https://github.com/KensioSoftware/smartass"
8
8
  },
9
9
  "license": "AGPL-3.0",
10
- "version": "1.9.0",
10
+ "version": "1.10.0",
11
11
  "type": "module",
12
12
  "main": "./dist/index.js",
13
13
  "types": "./dist/index.d.ts",
@@ -41,11 +41,11 @@
41
41
  "@types/node": "^25.9.3",
42
42
  "@vitest/coverage-v8": "^4.1.8",
43
43
  "@vitest/eslint-plugin": "^1.6.20",
44
- "eslint": "^10.4.1",
44
+ "eslint": "^10.5.0",
45
45
  "eslint-config-prettier": "^10.1.8",
46
46
  "eslint-plugin-jsdoc": "^62.9.0",
47
47
  "eslint-plugin-no-secrets": "^2.3.3",
48
- "eslint-plugin-security": "^4.0.0",
48
+ "eslint-plugin-security": "^4.0.1",
49
49
  "eslint-plugin-unicorn": "^64.0.0",
50
50
  "globals": "^17.6.0",
51
51
  "jiti": "^2.7.0",
@@ -58,8 +58,9 @@
58
58
  "build": "tsc -p tsconfig.build.json",
59
59
  "build:check": "tsc -p tsconfig.json --noEmit",
60
60
  "build:index": "bash scripts/build-index.sh",
61
- "fmt": "eslint --fix '{src,test}/**/*.ts' && prettier --write '{src,test}/**/*.{ts,json,md,css,html,yml,yaml}'",
62
- "lint": "eslint '{src,test}/**/*.ts' && prettier --check '{src,test}/**/*.{ts,json,md,css,html,yml,yaml}'",
61
+ "build:readme": "bash scripts/build-readme-lists.sh",
62
+ "fmt": "eslint --fix . && prettier --write .",
63
+ "lint": "eslint . && prettier --check .",
63
64
  "test": "vitest run --typecheck",
64
65
  "test:coverage": "vitest run --typecheck --coverage",
65
66
  "check": "pnpm fmt && pnpm build:check && pnpm test:coverage"