npm パッケージ v2

yubinbango-core2

yubinbango-core の後継フォーク。ソースの末尾に module.exports = YubinBango が追加され、CommonJS として正しくエクスポートされるようになっています。 Vite のプラグインなしで import が動作します。

yubinbango-core との違い

yubinbango-core(10年前)

// コンパイル後の末尾
})(YubinBango || (YubinBango = {}));
// module.exports なし → グローバル変数のみ
// Vite でのビルドに Vite plugin が必要

yubinbango-core2(7年前)

// コンパイル後の末尾
})(YubinBango || (YubinBango = {}));
module.exports = YubinBango;
// CommonJS エクスポートあり → そのまま動作

※ どちらも同じ JSONP データソース・同じ API インターフェイスです。 実装コードは yubinbango-core とほぼ同一で、module.exports の有無だけが実質的な差です。

7桁の数字を入力すると自動入力します

自動入力エリア

実装コード
// npm install yubinbango-core2
import YubinBango2 from 'yubinbango-core2'
// ↑ module.exports = YubinBango があるので Vite プラグイン不要

const form = reactive({ zip: '', pref: '', city: '', address: '' })

watch(() => form.zip, (val) => {
  const clean = val.replace(/-/g, '')
  if (!/^\d{7}$/.test(clean)) return
  if (!false) return

  new YubinBango2.Core(clean, (addr) => {
    form.pref    = addr.region   // 例: "東京都"
    form.city    = addr.locality // 例: "新宿区"
    form.address = addr.street   // 例: "新宿"
  })
})

yubinbango-core との実装上の差異

項目yubinbango-coreyubinbango-core2
CommonJS export❌ なし✅ module.exports あり
Vite プラグイン❌ 必要✅ 不要
データソースyubinbango.github.ioyubinbango.github.io(同一)
API インターフェイスCore(zip, cb)Core(zip, cb)(同一)
最終更新10年前7年前
  • ✅ CommonJS エクスポートあり → Vite/Rollup でそのまま動作
  • ✅ TypeScript source に export = YubinBango が追加
  • ✅ API・データは yubinbango-core と完全互換
  • ⚠️ どちらも JSONP でデータ取得(ネットワーク必須)
  • ⚠️ どちらも 7年〜10年前から更新なし