# @xuguo/sku

> a sku helper

Latest version **1.1.5** (published 2020-08-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install @xuguo/sku
pnpm add @xuguo/sku
yarn add @xuguo/sku
bun add @xuguo/sku
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.5 |
| Published | 2020-08-21 |
| First published | 2020-08-10 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 51.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | xuguo |
| Maintainers | xuguo |
| Keywords | sku, spu, combine |

## Links

- npm: https://www.npmjs.com/package/@xuguo/sku
- npm.io page: https://npm.io/package/@xuguo/sku

## Dependencies (1)

- [@xuguo/toolbox](https://npm.io/package/@xuguo/toolbox.md) ^1.2.0

## Recent versions

- 1.1.5 (latest) — 2020-08-21
- 1.1.4 — 2020-08-21
- 1.1.3 — 2020-08-21
- 1.1.2 — 2020-08-12
- 1.1.1 — 2020-08-12
- 1.1.0 — 2020-08-10

## README

### sku算法库
主要实现前端 sku规格切换的逻辑层

### 使用情况
该库让使用者不再关心逻辑，暂时对外仅提供一个接口`createSkuSelector`:  
希望您的数据结构符合如下：
```js
spu: {
  // ...spuAttrs
  skuList: [
    {
      // ...skuAttrs,
      skuIdKey: val,
      specsLsit: [
        {
          specId: val,
          specName: name,
          specValue: val,
          specValueId: id,
          // ...otherAttrs
        }
        // ...
      ]
    }
    // ...
  ]
}
```
本库仅对数据结构有如上要求，可通过`spuOps`来定义如何获取相应数据
> 1. 初始化
```js
import { createSkuSelector } from '@xuguo/sku'
let judger = createSkuSelector(spulist, spuOps)
```

> 2. 如何得到数据
```js
judger.specLines[index].specs[index]
```

> 3. 如何处理规格点击事件
```js
judger.specTap(spec)
```

> 4. 规格对象的状态
规格状态来自下面的枚举类，状态在内部完成修改
```ts
enum SpecStatus {
  PENDING = 'pending',
  DISABLED = 'disabled',
  SELECTED = 'selected',
}
// judger.specLines[row].specs[col].status
```

> 5. 如何得到skuId和specsId
`onSkuCombined`的回调时机在，点击勾选规格完成后构成一个sku的时候
```js
judger.onSkuCombined((skuId, specsIdJoin) => {
  // Do something
})
```

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