Skip to content
This repository was archived by the owner on Jun 10, 2025. It is now read-only.

Commit 2b8a350

Browse files
committed
Adding positive, bumping npms, exporting utility types.
1 parent a56097d commit 2b8a350

File tree

5 files changed

+57
-17
lines changed

5 files changed

+57
-17
lines changed

.vscode/settings.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"files.exclude": {
3-
"*.js": true,
4-
"helpers/*.js": true,
5-
"test/*.js": true
6-
},
7-
"typescript.tsdk": "node_modules/typescript/lib",
8-
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": true
3+
"**/*.js": {
4+
"when": "$(basename).ts"
5+
}
6+
}
97
}

index.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import object from './object'
3030
import ok from './ok'
3131
import oneOf from './one-of'
3232
import or from './or'
33+
import positive from './positive'
3334
import predicate from './predicate'
3435
import regexp from './regexp'
3536
import rethrow from './rethrow'
@@ -39,6 +40,16 @@ import shape from './shape'
3940
import strftime from './strftime'
4041
import string from './string'
4142
import tuple from './tuple'
43+
import type Alias from './types/alias'
44+
import type Assert from './types/assert'
45+
import type AsyncReturnType from './types/async-return-type'
46+
import type Awaited from './types/awaited'
47+
import type Keyed from './types/keyed'
48+
import type Maybe from './types/maybe'
49+
import type NilOr from './types/nil-or'
50+
import type NullOr from './types/null-or'
51+
import type Predicate from './types/predicate'
52+
import type UndefinedOr from './types/undefined-or'
4253
import undefined_ from './undefined'
4354
import undefinedOr from './undefined-or'
4455
import unique from './unique'
@@ -77,6 +88,7 @@ export {
7788
ok,
7889
oneOf,
7990
or,
91+
positive,
8092
predicate,
8193
regexp,
8294
rethrow,
@@ -89,7 +101,17 @@ export {
89101
undefined_ as undefined,
90102
undefinedOr,
91103
unique,
92-
unknown
104+
unknown,
105+
Alias,
106+
Assert,
107+
AsyncReturnType,
108+
Awaited,
109+
Keyed,
110+
Maybe,
111+
NilOr,
112+
NullOr,
113+
Predicate,
114+
UndefinedOr
93115
}
94116

95117
export default {
@@ -125,6 +147,7 @@ export default {
125147
ok,
126148
oneOf,
127149
or,
150+
positive,
128151
predicate,
129152
regexp,
130153
rethrow,

package.json

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
"@appliedblockchain/changelog": "1.2.0",
1717
"@appliedblockchain/eslint-config": "2.6.0",
1818
"@tsconfig/node12": "1.0.7",
19-
"@types/jest": "26.0.14",
20-
"@typescript-eslint/eslint-plugin": "4.3.0",
21-
"@typescript-eslint/parser": "4.3.0",
22-
"eslint": "7.10.0",
23-
"eslint-plugin-jest": "24.0.2",
24-
"jest": "26.4.2",
19+
"@types/jest": "26.0.20",
20+
"@typescript-eslint/eslint-plugin": "4.16.1",
21+
"@typescript-eslint/parser": "4.16.1",
22+
"eslint": "7.21.0",
23+
"eslint-plugin-jest": "24.1.5",
24+
"jest": "26.6.3",
2525
"npm-check": "5.9.2",
26-
"ts-jest": "26.4.1",
27-
"typescript": "4.0.3"
26+
"ts-jest": "26.5.3",
27+
"typescript": "4.2.3"
2828
},
2929
"jest": {
3030
"preset": "ts-jest",
@@ -46,7 +46,11 @@
4646
"extends": [
4747
"plugin:@typescript-eslint/recommended",
4848
"@appliedblockchain"
49-
]
49+
],
50+
"rules": {
51+
"no-unused-vars": "off",
52+
"@typescript-eslint/no-unused-vars": "error"
53+
}
5054
},
5155
"eslintIgnore": [
5256
"wip/*",

positive.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { inspect } from 'util'
2+
import type Assert from './types/assert'
3+
4+
export const positive: Assert<number> =
5+
value => {
6+
if (typeof value !== 'number') {
7+
throw new TypeError(`Expected number, got ${inspect(value)}.`)
8+
}
9+
if (value <= 0) {
10+
throw new TypeError(`Expected positive number, got ${inspect(value)}.`)
11+
}
12+
return value
13+
}
14+
15+
export default positive

test/strftime.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ test('simple', () => {
1111
expect(() => $.strftime('%Y-%m-%d')('2000-13-01')).toThrow(
1212
'Expected \'%Y-%m-%d\' strftime format, got \'2000-13-01\', failed at index 5, unrecognised part \'13-01\'.'
1313
)
14-
let d = new Date().toISOString()
14+
const d = new Date().toISOString()
1515
expect($.strftime('%FT%T.%sZ')(d)).toEqual(d)
1616
})

0 commit comments

Comments
 (0)