Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ jobs:
release:
name: Release ${{ github.ref }}
needs: test
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
# if: github.event_name == 'turned-off-temporary'
# if: github.ref == 'refs/heads/main' && github.event_name == 'push'
if: github.event_name == 'turned-off-temporary'
runs-on: ubuntu-latest
permissions:
checks: read
Expand Down Expand Up @@ -220,4 +220,4 @@ jobs:
- uses: actions/download-artifact@v5
with:
name: build
- run: deno test ./src/test/smoke/deno.test.js --allow-read --allow-sys --allow-env --allow-run
- run: deno test ./src/test/smoke/deno.test.js
19 changes: 14 additions & 5 deletions .size-limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@
"LICENSE",
"package-main.json"
],
"limit": "57.25 kB",
"limit": "60.00 kB",
"brotli": false,
"gzip": false
},
{
"name": "@webpod/ip/core",
"path": [
"target/*/core.*"
],
"limit": "41 kB",
"brotli": false,
"gzip": false
},
Expand All @@ -23,15 +32,15 @@
"LICENSE",
"package-main.json"
],
"limit": "17.35 kB",
"limit": "18.10 kB",
"gzip": true
},
{
"name": "cjs",
"path": [
"target/cjs"
],
"limit": "23.95 kB",
"limit": "25.30 kB",
"brotli": false,
"gzip": false
},
Expand All @@ -40,14 +49,14 @@
"path": [
"target/esm"
],
"limit": "20.06 kB",
"limit": "20.95 kB",
"brotli": false,
"gzip": false
},
{
"name": "libdefs",
"path": "target/dts",
"limit": "6.50 kB",
"limit": "7.00 kB",
"brotli": false,
"gzip": false
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/ts/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ export const isV6Format: Checker = (addr: string): boolean => {

export const isIPv4: Checker = isV4Format
export const isIPv6: Checker = isV6Format
export const isIP: Checker = (addr: string): boolean => isV4Format(addr) || isV6Format(addr)
export const isIP = (addr: string): 0 | Family => isV4Format(addr) ? 4 : isV6Format(addr) ? 6 : 0

export function isLoopback(addr: Raw): boolean {
return Address.isSpecial(addr, ['loopback', 'unspecified', 'linklocal'])
Expand Down
29 changes: 25 additions & 4 deletions src/main/ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
import * as address from './address.ts'
import * as native from './native.ts'
import * as core from './core.ts'

export * from './address.ts'
export * from './core.ts'
export * from './native.ts'
export {
type Special,
type BufferLike,
Address,
isPrivate,
isPublic,
isEqual,
isLoopback,
loopback,
toLong,
toBuffer,
toString,
fromLong,
fromPrefixLen,
cidr,
cidrSubnet,
subnet,
mask,
not,
or,
normalizeToLong,
} from './core.ts'

export const ip = { ...address, ...core }
export const ip = { ...core, ...native }
export default ip
8 changes: 8 additions & 0 deletions src/main/ts/address.ts → src/main/ts/native.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import os from 'node:os'
import { isLoopback, isPrivate, isPublic, loopback, Address } from './core.ts'

export {
isIP,
isIPv6,
isIPv4,
isIPv4 as isV4Format,
isIPv6 as isV6Format,
} from 'node:net'

const PUBLIC = 'public'
const PRIVATE = 'private'

Expand Down
1 change: 0 additions & 1 deletion src/test/js/export.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ describe('index', () => {
assert.equal(typeof index.isV6Format, 'function', 'index.isV6Format')
assert.equal(typeof index.loopback, 'function', 'index.loopback')
assert.equal(typeof index.mask, 'function', 'index.mask')
assert.equal(typeof index.normalizeToLong, 'function', 'index.normalizeToLong')
assert.equal(typeof index.not, 'function', 'index.not')
assert.equal(typeof index.or, 'function', 'index.or')
assert.equal(typeof index.subnet, 'function', 'index.subnet')
Expand Down
2 changes: 1 addition & 1 deletion src/test/ts/address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import assert from 'node:assert'
import os from 'node:os'
import net from 'node:net'
import { isPrivate } from '../../main/ts/core.ts'
import { address, addresses } from '../../main/ts/address.ts'
import { address, addresses } from '../../main/ts/native.ts'

describe('address()', () => {
test('private', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/test/ts/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,9 @@ describe('extra', () => {

describe('shortcuts', () => {
test('isIP(), isIPv4(), isIPv6()', () => {
assert.equal(isIP('foo'), false)
assert.equal(isIP('127.0.0.1'), true)
assert.equal(isIP('::1234:ffff'), true)
assert.equal(isIP('foo'), 0)
assert.equal(isIP('127.0.0.1'), 4)
assert.equal(isIP('::1234:ffff'), 6)
assert.equal(isIPv4('127.0.0.1'), true)
assert.equal(isIPv6('::1234:ffff'), true)
})
Expand Down
2 changes: 1 addition & 1 deletion src/test/ts/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {test, describe} from 'vitest'
import { address, isPrivate } from '../../main/ts/index.ts'

describe('index', () => {
test('re-exports both core & address helpers', () => {
test('re-exports both core & native helpers', () => {
assert.equal(typeof address, 'function')
assert.equal(typeof isPrivate, 'function')
})
Expand Down
2 changes: 1 addition & 1 deletion target/cjs/core.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ var isV6Format = (addr) => {
};
var isIPv4 = isV4Format;
var isIPv6 = isV6Format;
var isIP = (addr) => isV4Format(addr) || isV6Format(addr);
var isIP = (addr) => isV4Format(addr) ? 4 : isV6Format(addr) ? 6 : 0;
function isLoopback(addr) {
return Address.isSpecial(addr, ["loopback", "unspecified", "linklocal"]);
}
Expand Down
71 changes: 61 additions & 10 deletions target/cjs/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
const {
__spreadValues,
__export,
__reExport,
__toESM,
__toCommonJS
} = require('./cjslib.cjs');
Expand All @@ -11,21 +10,50 @@ const {
// src/main/ts/index.ts
var index_exports = {};
__export(index_exports, {
Address: () => import_core2.Address,
address: () => address,
addresses: () => addresses,
cidr: () => import_core2.cidr,
cidrSubnet: () => import_core2.cidrSubnet,
default: () => index_default,
ip: () => ip
fromLong: () => import_core2.fromLong,
fromPrefixLen: () => import_core2.fromPrefixLen,
ip: () => ip,
isEqual: () => import_core2.isEqual,
isIP: () => import_node_net.isIP,
isIPv4: () => import_node_net.isIPv4,
isIPv6: () => import_node_net.isIPv6,
isLoopback: () => import_core2.isLoopback,
isPrivate: () => import_core2.isPrivate,
isPublic: () => import_core2.isPublic,
isV4Format: () => import_node_net.isIPv4,
isV6Format: () => import_node_net.isIPv6,
loopback: () => import_core2.loopback,
mask: () => import_core2.mask,
normalizeToLong: () => import_core2.normalizeToLong,
not: () => import_core2.not,
or: () => import_core2.or,
subnet: () => import_core2.subnet,
toBuffer: () => import_core2.toBuffer,
toLong: () => import_core2.toLong,
toString: () => import_core2.toString
});
module.exports = __toCommonJS(index_exports);

// src/main/ts/address.ts
var address_exports = {};
__export(address_exports, {
// src/main/ts/native.ts
var native_exports = {};
__export(native_exports, {
address: () => address,
addresses: () => addresses
addresses: () => addresses,
isIP: () => import_node_net.isIP,
isIPv4: () => import_node_net.isIPv4,
isIPv6: () => import_node_net.isIPv6,
isV4Format: () => import_node_net.isIPv4,
isV6Format: () => import_node_net.isIPv6
});
var import_node_os = __toESM(require("os"), 1);
var import_core = require("./core.cjs");
var import_node_net = require("net");
var PUBLIC = "public";
var PRIVATE = "private";
var { normalizeFamily } = import_core.Address;
Expand Down Expand Up @@ -53,12 +81,35 @@ var address = (name, family) => addresses(name, family)[0];

// src/main/ts/index.ts
var core = __toESM(require("./core.cjs"), 1);
__reExport(index_exports, require("./core.cjs"), module.exports);
var ip = __spreadValues(__spreadValues({}, address_exports), core);
var import_core2 = require("./core.cjs");
var ip = __spreadValues(__spreadValues({}, core), native_exports);
var index_default = ip;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = Object.assign({
0 && (module.exports = {
Address,
address,
addresses,
cidr,
cidrSubnet,
fromLong,
fromPrefixLen,
ip,
}, require("./core.cjs")))
isEqual,
isIP,
isIPv4,
isIPv6,
isLoopback,
isPrivate,
isPublic,
isV4Format,
isV6Format,
loopback,
mask,
normalizeToLong,
not,
or,
subnet,
toBuffer,
toLong,
toString
});
2 changes: 1 addition & 1 deletion target/dts/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ export declare const isV4Format: Checker;
export declare const isV6Format: Checker;
export declare const isIPv4: Checker;
export declare const isIPv6: Checker;
export declare const isIP: Checker;
export declare const isIP: (addr: string) => 0 | Family;
export declare function isLoopback(addr: Raw): boolean;
export declare function loopback(family?: string | number): string;
19 changes: 10 additions & 9 deletions target/dts/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import * as native from './native.ts';
import * as core from './core.ts';
export * from './address.ts';
export * from './core.ts';
export * from './native.ts';
export { type Special, type BufferLike, Address, isPrivate, isPublic, isEqual, isLoopback, loopback, toLong, toBuffer, toString, fromLong, fromPrefixLen, cidr, cidrSubnet, subnet, mask, not, or, normalizeToLong, } from './core.ts';
export declare const ip: {
isIP: typeof native.isIP;
isIPv6: typeof native.isIPv6;
isIPv4: typeof native.isIPv4;
isV4Format: typeof native.isIPv4;
isV6Format: typeof native.isIPv6;
addresses: (name?: string, family?: string | number) => string[];
address: (name?: string, family?: string) => string | undefined;
fromPrefixLen(prefixlen: number, family?: string | number): string;
subnet(addr: string | number | bigint | number[] | core.BufferLike | core.Address, smask: string | number | bigint | number[] | core.BufferLike | core.Address): Omit<{
family: 4 | 6;
Expand Down Expand Up @@ -48,12 +56,5 @@ export declare const ip: {
or: (typeof core.Address)["or"];
cidr: (typeof core.Address)["cidr"];
normalizeToLong: (typeof core.Address)["normalizeToLong"];
isV4Format: (addr: string) => boolean;
isV6Format: (addr: string) => boolean;
isIPv4: (addr: string) => boolean;
isIPv6: (addr: string) => boolean;
isIP: (addr: string) => boolean;
addresses: (name?: string, family?: string | number) => string[];
address: (name?: string, family?: string) => string | undefined;
};
export default ip;
3 changes: 3 additions & 0 deletions target/dts/native.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { isIP, isIPv6, isIPv4, isIPv4 as isV4Format, isIPv6 as isV6Format, } from 'node:net';
export declare const addresses: (name?: string, family?: string | number) => string[];
export declare const address: (name?: string, family?: string) => string | undefined;
2 changes: 1 addition & 1 deletion target/esm/core.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ var isV6Format = (addr) => {
};
var isIPv4 = isV4Format;
var isIPv6 = isV6Format;
var isIP = (addr) => isV4Format(addr) || isV6Format(addr);
var isIP = (addr) => isV4Format(addr) ? 4 : isV6Format(addr) ? 6 : 0;
function isLoopback(addr) {
return Address.isSpecial(addr, ["loopback", "unspecified", "linklocal"]);
}
Expand Down
Loading
Loading