-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a461e5b
commit 211d719
Showing
31 changed files
with
5,414 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: CI | ||
on: [push, pull_request] | ||
jobs: | ||
build: | ||
name: Build, test on Node ${{ matrix.node }} and ${{ matrix.os }} | ||
|
||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
node: ['12.x', '14.x', '15.x'] | ||
os: [ubuntu-latest, windows-latest, macOS-latest] | ||
|
||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v2 | ||
|
||
- name: Use Node ${{ matrix.node }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
|
||
- name: Install deps and test (with cache) | ||
uses: bahmutov/npm-install@v1 | ||
|
||
- name: Test | ||
run: yarn cover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Publish | ||
on: | ||
release: | ||
types: [published] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14 | ||
registry-url: https://registry.npmjs.org/ | ||
- run: npm install | ||
- run: npm run test | ||
- run: npm publish --access public | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,85 @@ | ||
# rusultTs | ||
Rust Result Implementation for Typescript, simply. i.e. Modern error handling library. | ||
# `rusultTs` | ||
|
||
Rust **_Result Implementation for Typescript_**, simply. i.e. Modern error handling library. (no dependencies, pure Typescript code about 50 lines) 100% <a href="./coverage/lcov-report/index.html">[coverage]</a> | ||
<br> | ||
<br> | ||
|
||
![Coverage lines](./coverage/badge-lines.svg) | ||
![Coverage functions](./coverage/badge-functions.svg) | ||
![Coverage branches](./coverage/badge-branches.svg) | ||
![Coverage statements](./coverage/badge-statements.svg) | ||
|
||
[![NPM Version][npm-image]][npm-url] | ||
[![NPM Downloads][downloads-image]][downloads-url] | ||
[![CI](https://github.com/just-do-halee/rusultts/actions/workflows/main.yml/badge.svg)](https://github.com/just-do-halee/rusultts/actions/workflows/main.yml) | ||
[![License][license-image]][license-url] | ||
|
||
--- | ||
|
||
## **Installation**<br> | ||
|
||
```js | ||
npm install rusultts | ||
``` | ||
|
||
or | ||
|
||
```js | ||
yarn add rusultts | ||
``` | ||
|
||
## **Examples**<br> | ||
|
||
```ts | ||
function tryParse(token: string): Result<SomeType> { | ||
// ... heavy stuffs | ||
if (somethingWrong) { | ||
return Err.new(`something wrong...`, null); | ||
} | ||
// ... | ||
return Ok.new({ some: 'type', ...stuffs }); | ||
} | ||
|
||
function verify(token: string): boolean { | ||
const someType = tryParse(token).unwrap(); // automatically throw | ||
// ... more some stuffs | ||
const isItGood = tryGetBool(...).unwrap(); | ||
// ... | ||
return isItGood; | ||
} | ||
|
||
const bool = verify(someToken); | ||
``` | ||
|
||
### ResultBox | ||
|
||
```ts | ||
type Result<T> = ResultBox<T, null>; | ||
``` | ||
|
||
```ts | ||
function divide(a: number, b: number): ResultBox<number, number> { | ||
if (b === 0) { | ||
return Err.new(`b cannot be 0.`, b); | ||
} | ||
return Ok.new(a / b); | ||
} | ||
const ok = divide(4, 2).unwrap() === 2; // true | ||
const err = divide(4, 0).isErr; // true | ||
try { | ||
err.unwrap(); | ||
} catch (e) { | ||
const value = Err.eSplit(e)[1]; // "0" | ||
} | ||
``` | ||
|
||
## **License**<br> | ||
|
||
[MIT](LICENSE) | ||
|
||
[npm-image]: https://img.shields.io/npm/v/rusultts.svg | ||
[npm-url]: https://npmjs.org/package/rusultts | ||
[downloads-image]: https://img.shields.io/npm/dm/rusultts.svg | ||
[downloads-url]: https://npmcharts.com/compare/rusultts?minimal=true | ||
[license-url]: https://opensource.org/licenses/MIT | ||
[license-image]: https://img.shields.io/npm/l/rusultts |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<coverage generated="1633368573116" clover="3.2.0"> | ||
<project timestamp="1633368573117" name="All files"> | ||
<metrics statements="49" coveredstatements="49" conditionals="14" coveredconditionals="14" methods="16" coveredmethods="16" elements="79" coveredelements="79" complexity="0" loc="49" ncloc="49" packages="2" files="2" classes="2"/> | ||
<package name="src"> | ||
<metrics statements="18" coveredstatements="18" conditionals="6" coveredconditionals="6" methods="7" coveredmethods="7"/> | ||
<file name="rusultts.ts" path="/Users/hwakyeom/programs/projects/rusultts/src/rusultts.ts"> | ||
<metrics statements="18" coveredstatements="18" conditionals="6" coveredconditionals="6" methods="7" coveredmethods="7"/> | ||
<line num="30" count="1" type="stmt"/> | ||
<line num="33" count="30" type="stmt"/> | ||
<line num="34" count="30" type="stmt"/> | ||
<line num="35" count="30" type="stmt"/> | ||
<line num="38" count="33" type="cond" truecount="2" falsecount="0"/> | ||
<line num="39" count="4" type="stmt"/> | ||
<line num="40" count="4" type="stmt"/> | ||
<line num="42" count="29" type="stmt"/> | ||
<line num="69" count="1" type="stmt"/> | ||
<line num="71" count="25" type="stmt"/> | ||
<line num="74" count="25" type="stmt"/> | ||
<line num="100" count="1" type="stmt"/> | ||
<line num="102" count="5" type="stmt"/> | ||
<line num="105" count="5" type="stmt"/> | ||
<line num="113" count="6" type="stmt"/> | ||
<line num="114" count="6" type="cond" truecount="2" falsecount="0"/> | ||
<line num="115" count="2" type="cond" truecount="2" falsecount="0"/> | ||
<line num="117" count="6" type="stmt"/> | ||
</file> | ||
</package> | ||
<package name="test"> | ||
<metrics statements="31" coveredstatements="31" conditionals="8" coveredconditionals="8" methods="9" coveredmethods="9"/> | ||
<file name="test.types.ts" path="/Users/hwakyeom/programs/projects/rusultts/test/test.types.ts"> | ||
<metrics statements="31" coveredstatements="31" conditionals="8" coveredconditionals="8" methods="9" coveredmethods="9"/> | ||
<line num="1" count="1" type="stmt"/> | ||
<line num="16" count="1" type="stmt"/> | ||
<line num="17" count="3" type="stmt"/> | ||
<line num="18" count="3" type="stmt"/> | ||
<line num="19" count="3" type="stmt"/> | ||
<line num="23" count="1" type="stmt"/> | ||
<line num="26" count="2" type="cond" truecount="2" falsecount="0"/> | ||
<line num="27" count="1" type="stmt"/> | ||
<line num="31" count="4" type="stmt"/> | ||
<line num="35" count="1" type="stmt"/> | ||
<line num="38" count="2" type="stmt"/> | ||
<line num="39" count="2" type="cond" truecount="2" falsecount="0"/> | ||
<line num="40" count="2" type="stmt"/> | ||
<line num="43" count="7" type="cond" truecount="2" falsecount="0"/> | ||
<line num="44" count="1" type="stmt"/> | ||
<line num="46" count="6" type="stmt"/> | ||
<line num="50" count="6" type="stmt"/> | ||
<line num="51" count="6" type="stmt"/> | ||
<line num="54" count="7" type="cond" truecount="2" falsecount="0"/> | ||
<line num="55" count="1" type="stmt"/> | ||
<line num="57" count="6" type="stmt"/> | ||
<line num="58" count="6" type="stmt"/> | ||
<line num="59" count="6" type="stmt"/> | ||
<line num="60" count="6" type="stmt"/> | ||
<line num="63" count="2" type="stmt"/> | ||
<line num="64" count="2" type="stmt"/> | ||
<line num="65" count="2" type="stmt"/> | ||
<line num="66" count="7" type="stmt"/> | ||
<line num="67" count="7" type="stmt"/> | ||
<line num="69" count="2" type="stmt"/> | ||
<line num="70" count="2" type="stmt"/> | ||
</file> | ||
</package> | ||
</project> | ||
</coverage> |
Oops, something went wrong.