# tw-invoice-awards

> 將 台灣統一發票中獎號碼 提供出 javascript 串接介面

Latest version **1.0.1** (published 2021-04-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install tw-invoice-awards
pnpm add tw-invoice-awards
yarn add tw-invoice-awards
bun add tw-invoice-awards
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-04-02 |
| First published | 2021-04-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 28.1 KB |
| Known vulnerabilities | 0 (+24 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | EJay Cheng |
| Maintainers | ejay |

## Links

- npm: https://www.npmjs.com/package/tw-invoice-awards
- Repository: https://github.com/EJayCheng/tw-invoice-awards
- Homepage: https://github.com/EJayCheng/tw-invoice-awards#readme
- Issues: https://github.com/EJayCheng/tw-invoice-awards/issues
- npm.io page: https://npm.io/package/tw-invoice-awards

## Dependencies (3)

- [axios](https://npm.io/package/axios.md) ^0.21.1
- [dayjs](https://npm.io/package/dayjs.md) ^1.10.4
- [xml2js](https://npm.io/package/xml2js.md) ^0.4.23

## Recent versions

- 1.0.1 (latest) — 2021-04-02
- 1.0.0 — 2021-04-01

## README

# TW Invoice Awards

將 台灣統一發票中獎號碼 提供出 javascript 串接介面

## Dataset

財政部稅務入口站: https://invoice.etax.nat.gov.tw/invoice.xml

## Installation

```
npm install tw-invoice-awards --save
```

## Example

```typescript
/** 月份期數 */
type InvoiceAwardPeriodType = "1~2" | "3~4" | "5~6" | "7~8" | "9~10" | "11~12";

/** 統一發票開獎資訊 */
interface InvoiceAwardInfo {
  /** 標題 */
  title: string;
  /** 西元年份 */
  year: number;
  /** 中華民國年份 */
  rocYear: number;
  /** 月份期數 */
  period: InvoiceAwardPeriodType;
  /** 各獎項號碼 */
  awards: {
    特別獎: string;
    特獎: string;
    頭獎: string[];
    增開六獎: string[];
  };
  /** 領獎起始日期, 格式: YYYY-MM-DD */
  receiveAwardStartAt: string;
  /** 領獎結束日期, 格式: YYYY-MM-DD */
  receiveAwardEndAt: string;
  /** 資料公佈時間, 格式: YYYY-MM-DD HH:mm:ss */
  publishedAt: string;
}

type InvoiceAwardNameType =
  | "特別獎"
  | "特獎"
  | "頭獎"
  | "二獎"
  | "三獎"
  | "四獎"
  | "五獎"
  | "六獎"
  | "增開六獎";

/** 統一發票對獎結果 */
interface InvoiceAwardCheckResult {
  /** 是否中獎 */
  isWin: boolean;
  /** 查詢當下是否已經超過領獎時限 */
  isExpired: boolean;
  /** 當期對獎資訊 */
  awardInfo: InvoiceAwardInfo;
  /** 中獎的獎項名稱 */
  awardName?: InvoiceAwardNameType;
}
```

```typescript
// javascript
const { InvoiceAwards } = require("tw-invoice-awards");
// typescript
import { InvoiceAwards } from "tw-invoice-awards";

// 啟用快取, 選用, 預設: false
InvoiceAwards.enabledCache = true;

// 設定快取時間, 選用, 預設: 24 * 60 * 60 * 1000, 單位: 毫秒
InvoiceAwards.cacheTime = 60 * 1000;

// InvoiceAwards.fetchAwards(forceReload?:boolean): Promise<InvoiceAwardInfo[]>
InvoiceAwards.fetchAwards().then(console.log).catch(console.error);

// InvoiceAwards.check(year:number, period:string, code:string):Promise<InvoiceAwardCheckResult>
InvoiceAwards.check(2021, "1~2", code).then(console.log).catch(console.error);
```

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