# omi-tools

> Auxiliary tools for omi

Latest version **1.0.35** (published 2022-07-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install omi-tools
pnpm add omi-tools
yarn add omi-tools
bun add omi-tools
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.35 |
| Published | 2022-07-02 |
| First published | 2021-07-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 31.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | w-xuefeng |
| Maintainers | w-xuefeng |
| Keywords | omi, tools |

## Links

- npm: https://www.npmjs.com/package/omi-tools
- Repository: https://github.com/w-xuefeng/omi-tools
- Homepage: https://github.com/w-xuefeng/omi-tools#readme
- Issues: https://github.com/w-xuefeng/omi-tools/issues
- npm.io page: https://npm.io/package/omi-tools

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 1.0.35 (latest) — 2022-07-02
- 1.0.34 — 2021-08-25
- 1.0.33 — 2021-08-21
- 1.0.32 — 2021-08-20
- 1.0.31 — 2021-08-20
- 1.0.30 — 2021-08-19
- 1.0.29 — 2021-08-15
- 1.0.28 — 2021-08-15
- 1.0.27 — 2021-08-13
- 1.0.26 — 2021-08-13
- 1.0.25 — 2021-08-12
- 1.0.24 — 2021-08-12
- 1.0.23 — 2021-08-12
- 1.0.22 — 2021-08-12
- 1.0.21 — 2021-08-12
- … 21 more at https://npm.io/package/omi-tools/versions

## README

# omi-tools

Auxiliary tools for omi

[![NPM version](https://img.shields.io/npm/v/omi-tools?color=%23007acc&style=flat-square)](https://npmjs.org/package/omi-tools)
[![NPM downloads](https://img.shields.io/npm/dt/omi-tools?style=flat-square)](https://npmjs.org/package/omi-tools)

| tools                                 | params                                                                                                                                                                            | returns                                                                                                 | desc                                                                               |
| ------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| [rmIEFP](#rmIEFP)                     | props: object                                                                                                                                                                     | props(without internal events):object                                                                   | remove internal events from props                                                  |
| [HF.camel2kebab](#HF.camel2kebab)     | name(camelCase/PascalCase): string                                                                                                                                                | name(kebabCase): string                                                                                 | convert camelCase or PascalCase to kebabCase                                       |
| [OC.makeFC](#OC.makeFC)               | `tagName`: `string`,<br>`render`: `(props: Omi.OmiProps<Props>, store: Store) => JSX.Element`,<br>`lifeTimes?`: `Partial<IOmiLifetimes<Props, Store>>`,<br>`extraStore?`: `Store` | `FunctionComponent`: `FCConstructor<Props, Store>`                                                      | generate a component or element in the form of render-function declaration         |
| [OC.reactive](#OC.reactive)           | `data`: `object`                                                                                                                                                                  | `hooks`: `Function`                                                                                     | generate some reactive data                                                        |
| [OC.createContext](#OC.createContext) | `defaultValue`: any                                                                                                                                                               | `IOmiContext<T>`: {<br>`Provider`: `ProviderConstructor<T>`, <br>`Consumer`: `ConsumerConstructor`<br>} | generate Provider/Consumer ComponentConstructor                                    |
| [OC.useContext](#OC.useContext)       | `context`: {<br>`Provider`: `ProviderConstructor<T>`, <br>`Consumer`: `ConsumerConstructor`<br>}                                                                                  | `value`: T                                                                                              | Context Consumer Hooks                                                             |
| [OH.useMemo](#OH.useMemo)             | `callback`: `() => T`,<br>`deps`: `any[]`,<br>`shouldUpdated?`: `(prevDeps: any[], nextDeps: any[]) => boolean`<br>`context?`: `WeElement Context`                                | `computedData`: `T`                                                                                     | computed and memorize result at same dependencies                                  |
| [OH.useEffect](#OH.useEffect)         | `callback`: `() => T`,<br>`deps`: `any[]`,<br>`context?`: `WeElement Context`                                                                                                     | void                                                                                                    | It is similar to React.useEffect, but the `context` needs to be passed in manually |

# Explanation

<h2 id="rmIEFP">rmIEFP</h2>

- desc: remove internal events like `onClick` from props to avoid multiple binding times
- usecase:

  ```tsx
  import { Component, h, tag } from 'omi'
  import { rmIEFP } from 'omi-tools'
  import css from '_style.less'

  const tagName = 'o-title'

  interface ITitleProps {
    className?: string
    style?: string
    title: string
    onClick?: (e: MouseEvent) => void
  }

  declare global {
    namespace JSX {
      interface IntrinsicElements {
        [tagName]: Omi.Props & Partial<ITitleProps>
      }
    }
  }

  @tag(tagName)
  export default class Title extends Component<ITitleProps> {
    static css = css
    render(props: Omi.OmiProps<ITitleProps>) {
      return <h1 {...rmIEFP(props)}>{props.title}</h1>
    }
  }
  ```

<h2 id="HF.camel2kebab">HF.camel2kebab</h2>

- desc: convert variable name from camelCase or PascalCase form to kebabCase form
- usecase:

  ```ts
  import { HF } from 'omi-tools'
  const tagName = HF.camel2kebab('MyCustomElementName');
  // > tagName: `my-custom-element-name`
  ```

<h2 id="OC.makeFC">OC.makeFC</h2>

- desc: generate a component or element in the form of render-function declaration
- usecase:

  ```tsx
  import { OC, rmIEFP } from 'omi-tools'
  import css from '_style.less'

  const tagName = 'o-h1-title'

  interface ITitleProps {
    className?: string
    style?: string
    title: string
    onClick?: (e: MouseEvent) => void
  }

  declare global {
    namespace JSX {
      interface IntrinsicElements {
        [tagName]: Omi.Props & Partial<ITitleProps>
      }
    }
  }

  const Title = OC.makeFC<ITitleProps>(
    tagName,
    props => <h1 {...rmIEFP(props)}>{props.title}</h1>,
    { staticCss: css }
  )

  export default Title
  ```


<h2 id="OC.reactive">OC.reactive</h2>

- desc: generate some reactive data
- usecase: [https://codepen.io/w-xuefeng/pen/ZEKNyLm](https://codepen.io/w-xuefeng/pen/ZEKNyLm?editors=001)
- preview: [https://codepen.io/w-xuefeng/full/ZEKNyLm](https://codepen.io/w-xuefeng/full/ZEKNyLm)

<h2 id="OC.createContext">OC.createContext</h2>

- desc: generate Provider/Consumer ComponentConstructor
- usecase: [https://codepen.io/w-xuefeng/pen/LYyxqLo](https://codepen.io/w-xuefeng/pen/LYyxqLo?editors=001)
- preview: [https://codepen.io/w-xuefeng/full/LYyxqLo](https://codepen.io/w-xuefeng/full/LYyxqLo)

<h2 id="OC.useContext">OC.useContext</h2>

- desc: context Consumer Hooks
- usecase: [https://codepen.io/w-xuefeng/pen/LYyxqLo](https://codepen.io/w-xuefeng/pen/LYyxqLo?editors=001)
- preview: [https://codepen.io/w-xuefeng/full/LYyxqLo](https://codepen.io/w-xuefeng/full/LYyxqLo)

<h2 id="OH.useMemo">OH.useMemo</h2>

- desc: computed and memorize result at same dependencies
- usecase: [https://codepen.io/w-xuefeng/pen/mdmZJQb](https://codepen.io/w-xuefeng/pen/mdmZJQb?editors=001)
- preview: [https://codepen.io/w-xuefeng/full/mdmZJQb](https://codepen.io/w-xuefeng/full/mdmZJQb)

<h2 id="OH.useEffect">OH.useEffect</h2>

- desc: It is similar to React.useEffect, but the `context` needs to be passed in manually
- usecase: [https://codepen.io/w-xuefeng/pen/KKmjJJa](https://codepen.io/w-xuefeng/pen/KKmjJJa?editors=001)
- preview: [https://codepen.io/w-xuefeng/full/KKmjJJa](https://codepen.io/w-xuefeng/full/KKmjJJa)

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