Skip to content

Commit

Permalink
docs: add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
crimx committed Oct 17, 2023
1 parent 92ea9bd commit 8de5dc6
Show file tree
Hide file tree
Showing 7 changed files with 1,146 additions and 4 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,23 @@ jobs:

- name: Build 🔧
run: pnpm run build

- name: Test 🧪
run: pnpm run coverage

- name: Upload Coverage 📊
uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
with:
coverageLocations: ${{github.workspace}}/coverage/clover.xml:clover

- name: Build Docs 📖
run: |
pnpm run docs
- name: Deploy 🚀
uses: JamesIves/[email protected]
with:
branch: gh-pages
folder: docs
3 changes: 3 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ jobs:

- name: Build 🔧
run: pnpm run build

- name: Test 🧪
run: pnpm run coverage
84 changes: 82 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# tsur
# [tsur](https://github.com/crimx/tsur)

[![Docs](https://www.paka.dev/badges/v0/cute.svg)](https://www.paka.dev/npm/tsur)
<p align="center">
<img width="200" src="https://raw.githubusercontent.com/crimx/tsur/main/assets/tsur.svg">
</p>

[![Docs](https://img.shields.io/badge/Docs-read-%23fdf9f5)](https://crimx.github.io/tsur)
[![Build Status](https://img.shields.io/github/actions/workflow/status/crimx/tsur/build.yml)](https://github.com/crimx/tsur/actions/workflows/build.yml)
[![npm-version](https://img.shields.io/npm/v/tsur.svg)](https://www.npmjs.com/package/tsur)
[![Coverage Status](https://img.shields.io/coveralls/github/crimx/tsur/main)](https://coveralls.io/github/crimx/tsur?branch=main)

TypeScript goodies inspired by Rust.

Expand All @@ -10,6 +17,79 @@ TypeScript goodies inspired by Rust.
npm add tsur
```

## Usage

### Option

```ts
import { Option, Some, None } from "tsur";

const maybeNumber = Option.Some(42);

if (maybeNumber.isSome()) {
console.log(maybeNumber.unwrap()); // 42
} else {
console.log("There is no number");
}

const maybeString = Option.None;

if (maybeString.isSome()) {
console.log(maybeString.unwrap());
} else {
console.log("There is no string"); // "There is no string"
}
```

### Result

```ts
import { Result, Ok, Err } from "tsur";

function divide(a: number, b: number): Result<number, string> {
if (b === 0) {
return Err("Cannot divide by zero");
}
return Ok(a / b);
}

const result = divide(10, 2);

if (result.isOk()) {
console.log(result.unwrap()); // 5
} else {
console.log(result.unwrapErr()); // "Cannot divide by zero"
}
```

### Array

Many useful array methods are added:

```ts
import { filterMap, Some, None } from "tsur";

const arr = [1, 2, 3, 4, 5];

const result = filterMap(arr, x => (x % 2 === 0 ? Some(x * 2) : None));

console.log(result); // [4, 8]
```

Or you can patch them to the native array:

```ts
import "tsur/patches/array";

const arr = [1, 2, 3, 4, 5];

const result = arr.filterMap(x => (x % 2 === 0 ? Some(x * 2) : None));

console.log(result); // [4, 8]
```

See [docs](https://crimx.github.io/tsur) for more details.

## License

MIT @ [CRIMX](https://github.com/crimx)
18 changes: 18 additions & 0 deletions assets/tsur.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
"scripts": {
"prepublishOnly": "pnpm run build && echo 'Run the npm publish command inside `dist`.' && exit 1",
"build": "rimraf dist && tsc && node ./scripts/package.js",
"docs": "typedoc --options typedoc.json",
"test": "vitest",
"coverage": "vitest run --coverage",
"lint": "eslint --ext .ts,.tsx,.js,.mjs . && prettier --check .",
"lint:fix": "eslint --ext .ts,.tsx,.js,.mjs . --fix && prettier -w ."
"lint:fix": "eslint --ext .ts,.tsx,.js,.mjs . --fix && prettier -w .",
"release": "standard-version"
},
"keywords": [
"typescript",
Expand All @@ -39,6 +42,7 @@
"eslint-plugin-import": "^2.27.5",
"prettier": "^2.8.8",
"rimraf": "^5.0.0",
"standard-version": "^9.5.0",
"typedoc": "^0.24.8",
"typescript": "^5.1.6",
"vitest": "^0.34.2"
Expand Down
Loading

0 comments on commit 8de5dc6

Please sign in to comment.