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 の有無だけが実質的な差です。
実装コード
// 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-core | yubinbango-core2 |
|---|---|---|
| CommonJS export | ❌ なし | ✅ module.exports あり |
| Vite プラグイン | ❌ 必要 | ✅ 不要 |
| データソース | yubinbango.github.io | yubinbango.github.io(同一) |
| API インターフェイス | Core(zip, cb) | Core(zip, cb)(同一) |
| 最終更新 | 10年前 | 7年前 |
- ✅ CommonJS エクスポートあり → Vite/Rollup でそのまま動作
- ✅ TypeScript source に
export = YubinBangoが追加 - ✅ API・データは yubinbango-core と完全互換
- ⚠️ どちらも JSONP でデータ取得(ネットワーク必須)
- ⚠️ どちらも 7年〜10年前から更新なし