Skip to content

Commit

Permalink
add license + setup build
Browse files Browse the repository at this point in the history
  • Loading branch information
ptbarnum4 committed Aug 16, 2024
1 parent 48f97dc commit 4b97eba
Show file tree
Hide file tree
Showing 13 changed files with 1,782 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
DS_Store
3 changes: 2 additions & 1 deletion .mocharc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/** @type {import('mocha').MochaOptions} */
// process.env.TS_NODE_PROJECT = 'tsconfig.json';
module.exports = {
require: 'ts-node/register',
spec: ['tests/**/*.test.ts'],
'watch-files': ['src/**/*.ts', 'tests/**/*.ts'],
timeout: 10000,
timeout: 10000
};
7 changes: 7 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tests
.github
.vscode
node_modules
tsconfig.json
tsup.config.ts
mocharc.js
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@operationspark.org/ts-assertion:registry=https://npm.pkg.github.com
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cSpell.words": ["tsup"]
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Operation Spark

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
55 changes: 54 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,58 @@ This library provides assertions for testing types
## Installation

```sh
npm install
npm install -D @operationspark.org/ts-assertion
```

## Usage

### `CodeCheckerOptions`

| Name | Description | Optional |
| ------------- | ---------------------------------- | -------- |
| `pathname` | Pathname to input file | true |
| `globalTypes` | string of globally available types | true |

```ts
// Without file
import { CodeChecker } from '@operationspark.org/ts-assertion';

const checker = new CodeChecker();

expect(checker.test('const str: string = "test";')).to.be.true;
expect(checker.test('const str: string = 1;')).to.be.false;

checker.assert('const str: string = "test";').isValid();
checker.assert('const str: string = 1;').isNotValid();
```

```ts
import { CodeChecker } from '@operationspark.org/ts-assertion';

const options: = {
pathname: 'path/to/file.ts',
globalTypes: 'type PrimitiveType = string | number | boolean;',
};
type TypeNames = 'StringType' | 'NumberType' | 'BooleanType' | 'EnumType';
const checker = new CodeChecker<TypeNames>(options);

// file.ts
/*
export type StringType = string;
export type NumberType = number;
export type BooleanType = boolean;
export type EnumType = 'a' | 'b' | 'c';
*/

// Test returns true if the code is valid
expect(checker.test('const str: StringType = "test";')).to.be.true;
expect(checker.test('const str: string = 1;')).to.be.false;

// Assert throws an error if the code is not valid/invalid
checker.assert('const str: StringType = "test";').isValid();
checker.assert('const str: string = 1;').isNotValid();

// Or more specifically, just test the type in the file
expect(checker.test('const str: StringType = "test";'), 'StringType').to.be.true;
checker.assert('const str: StringType = "test";', 'StringType').isValid();
```
Loading

0 comments on commit 4b97eba

Please sign in to comment.