npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jama-japia-qr-formatter

v2.0.1

Published

Format the QR code of the standard ledger sheet guideline.

Downloads

19

Readme

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

| Property | Type | Default | Description | | --------------- | --------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | data * | string | | QR コード文字列 | | isGSOnly | boolean | false | true の場合、GS 制御文字のみでフォーマットを行います。 | | isEncoded | boolean | false | true の場合、data 文字列のエンコードを行いません。 | | formatZ | QRFormatZ | | 各社固有項目 のフォーマットを行う場合に設定します。 | | dataIdentifiers | dataIdentifiers | | カスタムデータ拡張子 のフォーマットを行う場合に指定します。 |

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.