https://github.com/op-engineering/toolkit
https://github.com/op-engineering/toolkit
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/op-engineering/toolkit
- Owner: OP-Engineering
- Created: 2023-10-14T09:55:41.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-01T10:12:57.000Z (almost 2 years ago)
- Last Synced: 2025-03-19T03:18:37.101Z (about 1 year ago)
- Language: TypeScript
- Size: 128 KB
- Stars: 13
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# OSP Toolkit
In every project I work I end up needing the same bunch of functions. This is just a repo which contains them so I can easily install them and import them.
```bash
yarn add osp-toolkit
```
## Constants
Some shorthand costants for React Native.
```ts
import { isIOS, isAndroid, ANDROID_VERSION, IOS_VERSION } from "osp-toolkit";
```
## Hooks
Although hooks are not my favorite, sometimes there are useful patterns.
```tsx
import { useBoolean } from "osp-toolkit";
function myComponent() {
const [isFoo, fooOn, fooOff] = useBoolean();
}
```
## Invariant checks
Invariant checks allow to assure the state of your app, by default they crash on releases so you better have error tracking via Sentry or similar set up.
```ts
import { invariant, nullthrows } from "osp-toolkit";
invariant(myVar === "foo", "myVar does not match, this crashes");
nullthrows(myVar, "myVar is null, this is crashes");
```
## Sleep
A simple sleep function for async contexts
```ts
import { sleep } from "osp-toolkit";
async function foo() {
await sleep(500);
}
```
## Debugging
I love logging to console, so there are a couple utilities inserted on the global namespace that make your logs a little easier to visually parse
```ts
marker(`1`) // Outputs 🔷🔷🔷🔷🔷🔷🔷🔷🔷🔷🔷🔷 MARK ${i} 🔷🔷🔷🔷🔷🔷🔷🔷🔷🔷🔷🔷🔷🔷 to console
const myObj = {
...
// some complex obj
}
debug(myObj) // Will pretty print an object to the RN console
```