# mishotek-toolbox

> Collection of useful typescriplt/javascript utilities

Latest version **1.0.0** (published 2021-10-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install mishotek-toolbox
pnpm add mishotek-toolbox
yarn add mishotek-toolbox
bun add mishotek-toolbox
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-10-10 |
| First published | 2021-10-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Misho Tektumanidze |
| Maintainers | mishotek |
| Keywords | javascript, typescript, utility, storage, endpoints, http |

## Links

- npm: https://www.npmjs.com/package/mishotek-toolbox
- Repository: https://github.com/mishotek/mishotek-toolbox
- Homepage: https://github.com/mishotek/mishotek-toolbox#readme
- Issues: https://github.com/mishotek/mishotek-toolbox/issues
- npm.io page: https://npm.io/package/mishotek-toolbox

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2021-10-10
- 0.0.1 — 2021-10-10

## README

# mishotek-toolbox
Collection for useful typescript utilities

## Storage
### PersistentDecoratorFactory
Lets you persist properties even after the page refresh. Ideal for storing settings and configs, like selected language.

Usage:
```TypeScript
const persistence = PersistentDecoratorFactory();

class LanguageService {

  @persistence
  language: string;

  // Some other code...
}

const languageService = LanguageService();

// Stores 'FR' in the localStorage
languageService.language = 'FR';

// Reads value from the localStorage
const currLanguage = languageService.language;
```

Now, when you set ```storage.language``` it will be stored in the localStorage and when you try to get value, property will be read from the localStorage. This means that, this variable's  value will persist even after the refresh.

By default, localStorage key will be ```'APP.' + property name```. For example, in LanguageService case, ```language``` will be stored as ```APP.language```. However, you can change prefix, by passing custom bucket name to the PersistentDecoratorFactory:

```TypeScript
const persistence = PersistentDecoratorFactory('MY_BUCKET');

class LanguageService {

  @persistence
  language: string;

  // Some other code...
}

const languageService = LanguageService();

// Stores 'FR' with key 'MY_BUCKET.language'
languageService.language = 'FR';
```

## HTTP
### endpointDecoratorFactory
Lets you elegantly configure your endpoints.

Usage:
```TypeScript
const apiEndpoint = endpointDecoratorFactory('https://jsonplaceholder.typicode.com/');

class Endpoints {

  @apiEndpoint
  static posts(): string {
    return 'posts';
  }

  @apiEndpoint
  static post(postId: string): string {
    return `posts/${postId}`;
  }
  
  // Some more endpoints...
}

// Get all posts
// Endpoints.posts() will return https://jsonplaceholder.typicode.com/posts
fetch(Endpoints.posts())
  .then(() => { /* Do stuff... */ })

// Get particular post
// Endpoints.posts() will return https://jsonplaceholder.typicode.com/posts/123
fetch(Endpoints.post('123'))
  .then(() => { /* Do stuff... */ })
```

You could handle multiple APIs too:
```TypeScript
const jsonplaceholderEndpoint = endpointDecoratorFactory('https://jsonplaceholder.typicode.com/');
const unsplashEndpoint = endpointDecoratorFactory('https://unsplash.com/');

class Endpoints {

  @jsonplaceholderEndpoint
  static posts(): string {
    return 'posts';
  }

  @jsonplaceholderEndpoint
  static post(postId: string): string {
    return `posts/${postId}`;
  }
  
  @unsplashEndpoint
  static image(imageId: string): string {
    return `${imageId}`;
  }
  
  // Some more endpoints...
}

```

---
_Source: https://npm.io/package/mishotek-toolbox · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
