2.0.1 • Published 3 years ago

jama-japia-qr-formatter v2.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

JAMA・JAPIA QR Formatter

Actions Status npm version GitHub license

標準帳票ガイドラインで策定されている QR コードのフォーマットを行います。

TypeScript をサポートしています。

Installation

npm

npm install jama-japia-qr-formatter

yarn

yarn add jama-japia-qr-formatter

Usage

基本的な例

import { QRFormatter } from 'jama-japia-qr-formatter'

const formatted = new QRFormatter({
  data: '[)>...9K201XXXXX...EOT',
}).format()

if (Array.isArray(formatted)) {
  formatted.forEach((map) => {
    console.log(map.get('9K'))

    // '201XXXXX'
  })
}

各社固有項目の取得例

各社固有項目を処理するコールバック関数の指定が行なえます。

import { QRFormatter, DetectDataId } from 'jama-japia-qr-formatter'

// 想定される値
const ZIds = ['9S', '2B'] as const
type ZIds = typeof ZIds[number]

const formatted = new QRFormatter<ZIds>({
  data: '[)>...Z2B12;...EOT',
  formatZ: (str) => {
    // 任意の変換処理
    return str.split(';').reduce<DetectDataId<ZIds>[]>((prev, item) => {
      const id = ZIds.find((id) => item.startsWith(id))

      if (!id) return prev

      const data = decodeURIComponent(item.substr(id.length))

      prev.push({ id, data })

      return prev
    }, [])
  },
}).format()

if (Array.isArray(formatted)) {
  formatted.forEach((map) => {
    console.log(map.get('2B'))

    // '12'
  })
}

カスタムデータ拡張子の取得例

既定のデータ拡張子以外をフォーマットすることが行なえます。

import { QRFormatter } from 'jama-japia-qr-formatter'

// カスタムデータ拡張子
const customIds = ['1X', '1Y'] as const

const formatted = new QRFormatter({
  data: '[)>...1XYZ...EOT',
  dataIdentifiers: customIds,
}).format()

if (Array.isArray(formatted)) {
  formatted.forEach((map) => {
    console.log(map.get('1X'))

    // 'YZ'
  })
}

API

QRFormatter

new QRFormatter<Z, T>(Request, QRFormatZ)

Request

PropertyTypeDefaultDescription
data *stringQR コード文字列
isGSOnlybooleanfalsetrue の場合、GS 制御文字のみでフォーマットを行います。
isEncodedbooleanfalsetrue の場合、data 文字列のエンコードを行いません。
formatZQRFormatZ各社固有項目 のフォーマットを行う場合に設定します。
dataIdentifiersdataIdentifiersカスタムデータ拡張子 のフォーマットを行う場合に指定します。

isGSOnly は、HID コードスキャナーなどでの使用を想定しています。※一品一葉のみ対応

isEncoded を有効にした場合は、事前に文字列のエンコードを行ってください。

QRFormatZ

(z: string, map: Map<DataIds, string>): {
  id: string      // Map Key
  data: string    // Map Value
}[]

z 変数をコールバック関数で処理することで Map オブジェクトに追加されます。

iddata プロパティのオブジェクト配列を返す必要があります。

map 変数には通常のフォーマット済み Map オブジェクトが含まれます。

QRFormatter.format

(): string | Map<DataIds, string>[]

フォーマットが行えない場合は、入力文字列をそのまま返却します。

DataIds

  • Type: string
  • Value: 9K, P, 20P などの定義済みデータ拡張子及び各社固有項目やカスタムデータ拡張子

QRFormatter.detectLedgerSheet

詳細な帳票区分の取得が行えます。

(data: string): {         // データ拡張子: 9K
  a: {
    id: string            // 値
    label?: string        // 日本語ラベル
    description?: string  // 説明
  }
  b: {
    id: string
    label?: string
  }
  c: {
    id: string
  }
}
  • a: 帳票区分
  • b: 適用業務区分
  • c: 各社自由設定域

License

The MIT License.

2.0.1

3 years ago

2.0.0

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago