chai-ip

Travis npm package Coverage Status

使用 Chai 斷言進行 IP 位址測試。

功能

  • 僅限 esm 模組,支援 node >= 16 和現代瀏覽器
  • chai expectshould 介面

安裝

$ npm install chai-ip

外掛

import { use } from 'chai';
import ip from 'chai-ip';

use(ip);

斷言

.ip

斷言字串代表有效的 IP 位址。

expect('127.0.0.1').to.be.an.ip;
expect('2001:0db8:85a3:0000:0000:8a2e:0370:7334').to.be.an.ip;

.ipv4

斷言字串代表有效的 IPv4 位址。

expect('127.0.0.1').to.be.an.ipv4;
expect('2001:0db8:85a3:0000:0000:8a2e:0370:7334').to.not.be.an.ipv4;

.ipv6

斷言字串代表有效的 IPv6 位址。

expect('127.0.0.1').to.not.be.an.ipv6;
expect('2001:0db8:85a3:0000:0000:8a2e:0370:7334').to.be.an.ipv6;

授權條款

請參閱 LICENSE 檔案以了解授權權利和限制 (MIT)。