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)。