JSPM

@ali1416/ip2region

1.3.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 31
  • Score
    100M100P100Q58390F
  • License Apache-2.0

IP地址转区域JavaScript版

Package Exports

  • @ali1416/ip2region
  • @ali1416/ip2region/dist/ip2region.node.js
  • @ali1416/ip2region/lib/main.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ali1416/ip2region) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

IP Address To Region For JavaScript IP地址转区域JavaScript版

License Node Support NPM Tag Repo Size

Node CI

简介

本项目迁移自ALI1416/ip2region,构建后ip2region.min.js文件仅3kb

在线示例

数据文件

其他语言项目

依赖导入

网页

https://unpkg.com/@zip.js/zip.js/dist/zip.min.js https://unpkg.com/@ali1416/ip2region/dist/ip2region.min.js

node

npm install @ali1416/ip2region

使用示例

// node test-node.js
const fs = require('fs')
const {Ip2Region} = require('../dist/ip2region.node')

let url = 'https://www.404z.cn/files/ip2region/v3.0.0/data/ip2region.zdb'
let zdbPath = 'D:/ip2region.zdb'

let ip2Region = new Ip2Region()

// runUrl()
runFile()

async function runUrl() {
  await ip2Region.initByUrl(url)
  run()
}

async function runFile() {
  console.log(`是否已经初始化:${ip2Region.initialized()}`)
  let buffer = fs.readFileSync(zdbPath).buffer
  await ip2Region.init(buffer)
  console.log(`是否已经初始化:${ip2Region.initialized()}`)
  run()
}

function run() {
  console.log(ip2Region.parse('0.0.0.0'))
  console.log(ip2Region.parse('123.132.0.0'))
  console.log(`ip2Number 123.132.0.0 -> ${ip2Region.ip2Number('123.132.0.0')}`)
  console.log(`number2Ip 2072248320 -> ${ip2Region.number2Ip('2072248320')}`)
  console.log(`123.132.0.0 是合法的IP地址 -> ${ip2Region.isValidIp('123.132.0.0')}`)
}

更多请见测试

更新日志

点击查看

参考

关于

About