@jblib/should 0.0.1 → 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/LICENSE +21 -0
- package/README.md +13 -0
- package/package.json +21 -22
- package/src/index.ts +3 -3
- package/src/should-be-false.spec.ts +26 -0
- package/src/should-be-false.ts +15 -0
- package/src/should-be-true.spec.ts +15 -11
- package/src/should-be-true.ts +13 -1
- package/src/should-never.spec.ts +9 -0
- package/src/should-never.ts +12 -0
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -3
- package/dist/should-be-true.d.ts +0 -5
- package/dist/should-be-true.d.ts.map +0 -1
- package/dist/should-be-true.js +0 -6
- package/dist/should-be-true.js.map +0 -1
- package/eslint.config.ts +0 -6
- package/tsconfig.json +0 -8
- package/tsdown.config.ts +0 -23
- package/vitest.config.ts +0 -11
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Joseph Beck
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/package.json
CHANGED
|
@@ -1,42 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jblib/should",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "should",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "should, assertions that throw errors when conditions aren't met",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build": "tsdown",
|
|
8
|
-
"test": "vitest",
|
|
9
|
-
"lint": "eslint .",
|
|
10
|
-
"lint:fix": "eslint . --fix"
|
|
11
|
-
},
|
|
12
6
|
"devDependencies": {
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
7
|
+
"prettier": "^3.8.3",
|
|
8
|
+
"tsdown": "^0.21.10",
|
|
9
|
+
"typescript": "^6.0.3",
|
|
10
|
+
"vitest": "^4.1.5",
|
|
11
|
+
"@jblib/eslint": "0.0.3"
|
|
18
12
|
},
|
|
19
13
|
"keywords": [
|
|
20
|
-
"should"
|
|
14
|
+
"should",
|
|
15
|
+
"assert"
|
|
21
16
|
],
|
|
22
17
|
"author": {
|
|
23
18
|
"name": "Joseph Beck"
|
|
24
19
|
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"src"
|
|
23
|
+
],
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
25
|
"repository": {
|
|
26
26
|
"type": "git",
|
|
27
27
|
"url": "git+https://github.com/joseph-beck/jblib.git",
|
|
28
28
|
"directory": "packages/should"
|
|
29
29
|
},
|
|
30
30
|
"license": "MIT",
|
|
31
|
-
"packageManager": "pnpm@10.33.0",
|
|
32
31
|
"exports": {
|
|
33
|
-
".": "./
|
|
32
|
+
".": "./dist/index.js",
|
|
34
33
|
"./package.json": "./package.json"
|
|
35
34
|
},
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsdown",
|
|
37
|
+
"test": "vitest",
|
|
38
|
+
"lint": "eslint .",
|
|
39
|
+
"lint:fix": "eslint . --fix"
|
|
41
40
|
}
|
|
42
|
-
}
|
|
41
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export {
|
|
1
|
+
export { shouldBeFalse } from './should-be-false.js'
|
|
2
|
+
export { shouldBeTrue } from './should-be-true.js'
|
|
3
|
+
export { shouldNever } from './should-never.js'
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { shouldBeFalse } from './should-be-false.js'
|
|
4
|
+
|
|
5
|
+
describe('should be false', () => {
|
|
6
|
+
it('should not throw for false', () => {
|
|
7
|
+
expect(() => shouldBeFalse(false)).not.toThrow()
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('should throw for true', () => {
|
|
11
|
+
expect(() => shouldBeFalse(true)).toThrow('should be false, but got true')
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('should throw for non-false values', () => {
|
|
15
|
+
expect(() => shouldBeFalse(123)).toThrow('should be false, but got 123')
|
|
16
|
+
expect(() => shouldBeFalse('hello')).toThrow('should be false, but got hello')
|
|
17
|
+
expect(() => shouldBeFalse({})).toThrow('should be false, but got [object Object]')
|
|
18
|
+
expect(() => shouldBeFalse([])).toThrow('should be false, but got ')
|
|
19
|
+
expect(() => shouldBeFalse(null)).toThrow('should be false, but got null')
|
|
20
|
+
expect(() => shouldBeFalse(undefined)).toThrow('should be false, but got undefined')
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('should use custom message if provided', () => {
|
|
24
|
+
expect(() => shouldBeFalse(true, 'custom error message')).toThrow('custom error message')
|
|
25
|
+
})
|
|
26
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
*/
|
|
9
|
+
const shouldBeFalse = (v: unknown, message?: string): void => {
|
|
10
|
+
if (v !== false) {
|
|
11
|
+
throw new Error(message ?? `should be false, but got ${String(v)}`)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { shouldBeFalse }
|
|
@@ -3,20 +3,24 @@ import { describe, expect, it } from 'vitest'
|
|
|
3
3
|
import { shouldBeTrue } from './should-be-true.js'
|
|
4
4
|
|
|
5
5
|
describe('should be true', () => {
|
|
6
|
-
it('should
|
|
7
|
-
expect(shouldBeTrue(true)).
|
|
6
|
+
it('should not throw for true', () => {
|
|
7
|
+
expect(() => shouldBeTrue(true)).not.toThrow()
|
|
8
8
|
})
|
|
9
9
|
|
|
10
|
-
it('should
|
|
11
|
-
expect(shouldBeTrue(false)).
|
|
10
|
+
it('should throw for false', () => {
|
|
11
|
+
expect(() => shouldBeTrue(false)).toThrow('should be true, but got false')
|
|
12
12
|
})
|
|
13
13
|
|
|
14
|
-
it('should
|
|
15
|
-
expect(shouldBeTrue(123)).
|
|
16
|
-
expect(shouldBeTrue('hello')).
|
|
17
|
-
expect(shouldBeTrue({})).
|
|
18
|
-
expect(shouldBeTrue([])).
|
|
19
|
-
expect(shouldBeTrue(null)).
|
|
20
|
-
expect(shouldBeTrue(undefined)).
|
|
14
|
+
it('should throw for non-true values', () => {
|
|
15
|
+
expect(() => shouldBeTrue(123)).toThrow('should be true, but got 123')
|
|
16
|
+
expect(() => shouldBeTrue('hello')).toThrow('should be true, but got hello')
|
|
17
|
+
expect(() => shouldBeTrue({})).toThrow('should be true, but got [object Object]')
|
|
18
|
+
expect(() => shouldBeTrue([])).toThrow('should be true, but got ')
|
|
19
|
+
expect(() => shouldBeTrue(null)).toThrow('should be true, but got null')
|
|
20
|
+
expect(() => shouldBeTrue(undefined)).toThrow('should be true, but got undefined')
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('should use custom message if provided', () => {
|
|
24
|
+
expect(() => shouldBeTrue(false, 'custom error message')).toThrow('custom error message')
|
|
21
25
|
})
|
|
22
26
|
})
|
package/src/should-be-true.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
|
|
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
|
+
*/
|
|
9
|
+
const shouldBeTrue = (v: unknown, message?: string): void => {
|
|
10
|
+
if (v !== true) {
|
|
11
|
+
throw new Error(message ?? `should be true, but got ${String(v)}`)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
2
14
|
|
|
3
15
|
export { shouldBeTrue }
|
|
@@ -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
package/dist/index.js
DELETED
package/dist/should-be-true.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"should-be-true.d.ts","names":[],"sources":["../src/should-be-true.ts"],"mappings":";cAAM,YAAA,GAAgB,CAAA"}
|
package/dist/should-be-true.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"should-be-true.js","names":[],"sources":["../src/should-be-true.ts"],"sourcesContent":["const shouldBeTrue = (v: unknown): boolean => v === true\n\nexport { shouldBeTrue }\n"],"mappings":";AAAA,MAAM,gBAAgB,MAAwB,MAAM"}
|
package/eslint.config.ts
DELETED
package/tsconfig.json
DELETED
package/tsdown.config.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'tsdown'
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
entry: ['./src/index.ts'],
|
|
5
|
-
format: ['esm'],
|
|
6
|
-
platform: 'node',
|
|
7
|
-
unbundle: true,
|
|
8
|
-
dts: true,
|
|
9
|
-
sourcemap: true,
|
|
10
|
-
clean: true,
|
|
11
|
-
minify: false,
|
|
12
|
-
fixedExtension: false,
|
|
13
|
-
exports: {
|
|
14
|
-
devExports: true,
|
|
15
|
-
},
|
|
16
|
-
publint: {
|
|
17
|
-
strict: true,
|
|
18
|
-
},
|
|
19
|
-
attw: {
|
|
20
|
-
profile: 'esm-only',
|
|
21
|
-
level: 'error',
|
|
22
|
-
},
|
|
23
|
-
})
|