Skip to content

Commit 2c76749

Browse files
authored
Merge pull request #24 from Coder-Spirit/issue-10-deno-support
Denopkg support
2 parents d06d801 + 9ac1a2e commit 2c76749

23 files changed

+343
-59
lines changed

.hooks/pre-commit

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
#!/bin/sh
22

3-
yarn lint && yarn test
3+
yarn clean:deno && \
4+
yarn build:deno && \
5+
git add ./nominal/deno && \
6+
yarn lint && \
7+
yarn test

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ zero runtime overhead.
3737
npm install @coderspirit/nominal
3838
3939
# Or with Yarn:
40-
yarn install @coderspirit/nominal
40+
yarn add @coderspirit/nominal
4141
```
4242

4343
### Deno
4444

45-
Pending explanation.
45+
`Nominal` is served through different CDNs
46+
```typescript
47+
import { ... } from 'https://denopkg.com/Coder-Spirit/nominal@[VERSION]/nominal/deno/index.ts'
48+
```
4649

4750
## Brands
4851

nominal/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = {
3737
quotes: ['error', 'single', { avoidEscape: true }],
3838
'sort-imports': 'error',
3939
},
40-
ignorePatterns: ['*.js', 'tsconfig.json', 'dist/**/*'],
40+
ignorePatterns: ['*.js', 'tsconfig.json', 'dist/**/*', 'deno/**/*'],
4141
overrides: [
4242
{
4343
files: ['**/__tests__/**/*.test.ts'],

nominal/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ zero runtime overhead.
3737
npm install @coderspirit/nominal
3838
3939
# Or with Yarn:
40-
yarn install @coderspirit/nominal
40+
yarn add @coderspirit/nominal
4141
```
4242

4343
### Deno
4444

45-
Pending explanation.
45+
`Nominal` is served through different CDNs
46+
```typescript
47+
import { ... } from 'https://denopkg.com/Coder-Spirit/nominal@[VERSION]/nominal/deno/index.ts'
48+
```
4649

4750
## Brands
4851

nominal/deno/GenericTainted.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { SimpleTypeTag } from './internal/UtilTypes.ts';
2+
import { TagsMarker } from './internal/TagsMarker.ts';
3+
import { WithTag } from './WithTag.ts';
4+
5+
export type GenericTainted<
6+
BaseType,
7+
TaintTag extends string | symbol
8+
> = BaseType extends TagsMarker<infer BaseType0, infer TypeTags0>
9+
? // eslint-disable-next-line @typescript-eslint/no-unused-vars
10+
BaseType0 extends Partial<Record<infer _K, infer _V>>
11+
? BaseType0 extends
12+
| undefined
13+
| null
14+
| boolean
15+
| number
16+
| bigint
17+
| string
18+
| symbol
19+
| Date
20+
? BaseType0 & TagsMarker<BaseType0, TypeTags0 & SimpleTypeTag<TaintTag>>
21+
: { [P in keyof BaseType0]: GenericTainted<BaseType0[P], TaintTag> } &
22+
TagsMarker<
23+
{
24+
[P in keyof BaseType0]: GenericTainted<BaseType0[P], TaintTag>
25+
},
26+
TypeTags0 & SimpleTypeTag<TaintTag>
27+
>
28+
: BaseType0 & TagsMarker<BaseType0, TypeTags0 & SimpleTypeTag<TaintTag>>
29+
: // eslint-disable-next-line @typescript-eslint/no-unused-vars
30+
BaseType extends Partial<Record<infer _K, infer _V>>
31+
? BaseType extends
32+
| undefined
33+
| null
34+
| boolean
35+
| number
36+
| bigint
37+
| string
38+
| symbol
39+
| Date
40+
? WithTag<BaseType, TaintTag>
41+
: WithTag<
42+
{ [P in keyof BaseType]: GenericTainted<BaseType[P], TaintTag> },
43+
TaintTag
44+
>
45+
: WithTag<BaseType, TaintTag>

nominal/deno/GenericUntainted.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { GenericTainted } from './GenericTainted.ts';
2+
import { NegateTag } from './NegateTag.ts';
3+
import { TagsMarker } from './internal/TagsMarker.ts';
4+
5+
export type GenericUntainted<
6+
BaseType,
7+
TaintTag extends string | symbol
8+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
9+
> = BaseType extends GenericTainted<infer _Irrelevant, TaintTag>
10+
? BaseType extends TagsMarker<infer BaseType0, infer TypeTags0>
11+
? // eslint-disable-next-line @typescript-eslint/no-unused-vars
12+
BaseType0 extends Partial<Record<infer _K, infer _V>>
13+
? BaseType0 extends
14+
| undefined
15+
| null
16+
| boolean
17+
| number
18+
| bigint
19+
| string
20+
| symbol
21+
| Date
22+
? NegateTag<BaseType0 & TagsMarker<BaseType0, TypeTags0>, TaintTag>
23+
: NegateTag<
24+
{
25+
[P in keyof BaseType0]: GenericUntainted<BaseType0[P], TaintTag>
26+
} &
27+
TagsMarker<
28+
{
29+
[P in keyof BaseType0]: GenericUntainted<
30+
BaseType0[P],
31+
TaintTag
32+
>
33+
},
34+
TypeTags0
35+
>,
36+
TaintTag
37+
>
38+
: NegateTag<BaseType0 & TagsMarker<BaseType0, TypeTags0>, TaintTag>
39+
: // eslint-disable-next-line @typescript-eslint/no-unused-vars
40+
BaseType extends Partial<Record<infer _K, infer _V>>
41+
? BaseType extends
42+
| undefined
43+
| null
44+
| boolean
45+
| number
46+
| bigint
47+
| string
48+
| symbol
49+
| Date
50+
? NegateTag<BaseType, TaintTag>
51+
: NegateTag<
52+
{ [P in keyof BaseType]: GenericUntainted<BaseType[P], TaintTag> },
53+
TaintTag
54+
>
55+
: NegateTag<BaseType, TaintTag>
56+
: BaseType

nominal/deno/NegateTag.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { SimpleTypeNegation, SimpleTypeTag } from './internal/UtilTypes.ts';
2+
import { TagsMarker } from './internal/TagsMarker.ts';
3+
4+
export type NegateTag<
5+
BaseType,
6+
TypeTag extends string | symbol
7+
> = BaseType extends TagsMarker<infer BaseType0, infer TypeTags0>
8+
? BaseType0 &
9+
(TagsMarker<BaseType0, SimpleTypeTag<TypeTag>> extends TagsMarker<
10+
BaseType0,
11+
TypeTags0
12+
>
13+
? Partial<
14+
TagsMarker<
15+
BaseType0,
16+
TypeTags0 extends SimpleTypeTag<TypeTag> & infer RestTypeTags
17+
? RestTypeTags & SimpleTypeNegation<TypeTag>
18+
: Omit<TypeTags0, TypeTag> & SimpleTypeNegation<TypeTag>
19+
>
20+
>
21+
: TagsMarker<
22+
BaseType0,
23+
TypeTags0 extends SimpleTypeTag<TypeTag> & infer RestTypeTags
24+
? RestTypeTags & SimpleTypeNegation<TypeTag>
25+
: Omit<TypeTags0, TypeTag> & SimpleTypeNegation<TypeTag>
26+
>)
27+
: BaseType & Partial<TagsMarker<BaseType, SimpleTypeNegation<TypeTag>>>

nominal/deno/Tainted.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { GenericTainted } from './GenericTainted.ts';
2+
import { TaintSymbolType } from './internal/Symbols.ts';
3+
4+
export type Tainted<BaseType> = GenericTainted<BaseType, TaintSymbolType>

nominal/deno/Untainted.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { GenericUntainted } from './GenericUntainted.ts';
2+
import { TaintSymbolType } from './internal/Symbols.ts';
3+
4+
export type Untainted<BaseType> = GenericUntainted<BaseType, TaintSymbolType>

nominal/deno/WithTag.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { SimpleTypeTag } from './internal/UtilTypes.ts';
2+
import { TagsMarker } from './internal/TagsMarker.ts';
3+
4+
export type WithTag<
5+
BaseType,
6+
TypeTag extends string | symbol
7+
> = BaseType extends TagsMarker<infer BaseType0, infer TypeTags0>
8+
? BaseType0 & TagsMarker<BaseType0, TypeTags0 & SimpleTypeTag<TypeTag>>
9+
: BaseType & TagsMarker<BaseType, SimpleTypeTag<TypeTag>>

0 commit comments

Comments
 (0)