npm package: @likcheung/shared
Description: licheung shared
Author: licheung228
Latest version: 0.0.16

# Lik Shared

module plz

```js
import {
  poll,
  Mitter,
  transOptionsFromMap,
  transClassifyFromList,
  once,
  deviceDetect,
  u_setStyle,
  u_stopPropagation,
} from '@likcheung/shared'
```

## Array

### splitArray

split array by arguments

**ex:**

```js
splitArray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3, 3, 4)
/*
 [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9, 10],
  ]
*/
```

### splitArrayAuto

split array by arguments,
if total of arguments equal or greater than array length, result same as splitArray,
else will split by the last arguments value.

**ex:**

```js
splitArrayAuto([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3, 3)
/*
[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]
*/
```

## Trans

### transOptionsFromMap

transform a map or enum to a universal opition list

**ex:**

```ts
transOptionsFromMap({ value: 'label' })

/*
	{ label: 'label', value: 'value' }
*/
```

### transClassifyFromList

transfrom a list to a classify map

**params:**

- list --- a list
- key --- the classify dependent key

**ex:**

```ts
const params: [Record<string, any>[], string] = [
  [
    { id: 1, value: 'one', label: '一' },
    { id: 2, value: 'two', label: '二' },
    { id: 11, value: 'one', label: '一/一' },
  ],
  'value',
]

transClassifyFromList(...params)

/*
	{
    one: [
      { id: 1, value: 'one', label: '一' },
      { id: 11, value: 'one', label: '一/一' },
    ],
    two: [{ id: 2, value: 'two', label: '二' }],
	}
*/
```

### transOptionsFromList

transform a basic map list to a universal option list

**params:**

- map list --- `BasicMap[]`
- label key and value key --- `[string | symbol | number, string | symbol | number]`

**ex:**

```ts
transOptionsFromList([{ v: 'value', l: 'label' }], 'l', 'v')
/*
	[{ label: 'label', value: 'value' }]
*/
```

### transMapFromList

transform a basic map list to a map by specify key and value

**parmas:**

- map list --- `BasicMap[]`
- key of key and key of value

**ex:**

```ts
transMapFromList(
  [
    {
      type: 0,
      desc: '待生效',
    },
  ],
  ['type', 'desc'],
)

/*
	{ [0]: '待生效' }
*/
```

## Utils

### Poll

for polling

#### args

**PollFunction**

function, U can use the `options.successCondition` or `options.failureCondition` check the return value

**PollOptions**

polling configure, object

**property**

- **interval** the interval of polling
- **timeout** the time limit of polling
- **maxAttempts** maximum of attempts times
- **successCondition** check the pollFun return
- **failureCondition** check the pollFun return
- **onInterval** callback of every polling

### example

...wait

### once

input a function, return a object, excute return.run to run this function.

**params**

function
target function

**return**
run
exec funciton
reset
reset once

## Web

some utils only runs in the browser environment

### deviceDetect

- `is`
- `isInWechatMP`
- `isWeixin`
- `isMobile`
- `isIos`
- `isAndroid`
- `isIphone`
- `isIpad`

### Utils

#### u_setStyle

set style to Element

**params**

1. el
   the target element
2. key
   the style key
3. value
   the style value

#### u_stopPropagation

set a event stop propagation

**params**

1. Event
   Event

## Type Utils

### Reducer

ActionMapFromActionCreator
ActionTypeFromActionMap
ActionTypeFromActionCreator

## Mitter

...wait