npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

nsap-address

v1.0.3

Published

ITU-T Rec. X.213 Network Service Access Point (NSAP) address parsing and printing

Readme

X.213 NSAP Library

JSR

ITU-T Recommendation X.213 Network Service Access Point (NSAP) address parsing and printing. These address types were designed for use in OSI networking, but have full compatibility with IP networking. Since OSI networking is ancient history, this library prioritizes the IP networking aspects, but everything should be supported.

This module

This module decodes and encodes a Network Service Access Point (NSAP) to and from the "preferred binary encoding" described in Annex A, Section A.5.3 of ITU-T Recommendation X.213 (2001).

In addition to this, it displays and decodes NSAPs to and from human-readable strings according to the procedures defined in IETF RFC 1278, drawing on additional information found in IETF RFC 1277.

There are some deviations to the above, however. Since the human-friendly string syntax was defined, new AFIs were added, including one for directly representing IP addresses and another for representing URLs. As such this library extends the specification, but should be completely backwards compatible with it.

You should not expect an NSAP decoded from a string to encode back into the same exact string. You should not expect an NSAP decoded from bytes to encode back into the same exact bytes. You should not expect all NSAP syntaxes to be recognized everywhere; your application and dependencies should handle unrecognized NSAP syntaxes gracefully.

All standard syntaxes can be both parsed ("from string") and displayed ("to string"). There is no guarantee that all non-standard syntaxes can be parsed if they can be displayed (namely, the IP6 syntax).

Unit test coverage is close to 100% of all lines and functions, and about 70% of branches. Some of the branches not tested are trivial error handling branches or even thought to be unreachable. This module is written in Typescript with the strictest settings.

This module is ESM-only. I will not publish a CommonJS version. Please consider migrating to using ESM if you are not.

I believe this module will work on all Javascript runtimes. It does not even depend on Buffer (the tests, do, though).

Usage

Most of what you would want out of this module is parsing, printing, encoding, decoding, and comparing NSAP addresses. Without further ado, here is a quick showcase of this module's features:

import { X213NetworkAddress } from "@wildboar/nsap-address";

const addr = X213NetworkAddress.fromString("PSTN+8881235050+ECMA-117-Decimal+65535+35492+128");
// s is "PSTN+8881235050+ECMA-117-Decimal+65535+35492+128"
const s = addr.toString();
// b are the bytes of the encoding described in ITU-T Rec. X.213, Annex A.
const b = addr.getOctets();
// This evaluates to true, of course. This is just a trivial byte comparison.
b.isEqualTo(b);
// 0x42 (AFI_E163_DEC_LEADING_NON_ZERO) The AFI for E.163 with no leading zero and a decimal DSP
const afi = addr.afi();
// This always converts the address to a string of the `NS+<hex>` format.
// While not user-friendly, this is the best format for interoperability.
const ns = addr.toNSString();
// idi_digits is [ 8,8,8,1,2,3,5,0,5,0 ]
const idi_digits = Array.from(addr.idiDigits() ?? []);
// dsp_digits is [ 6,5,5,3,5,3,5,4,9,2,1,2,8 ]
const dsp_digits = Array.from(addr.dspDigits() ?? []);

const addr2 = X213NetworkAddress.fromIpAddress([ 127, 0, 0, 1 ]);
const ip = addr2.getIp(); // [ 127, 0, 0, 1 ]

const addr3 = X213NetworkAddress.fromNonOsiUrl("tcp://127.0.0.1");
const url = addr3.getUrl(); // "tcp://127.0.0.1"

There is sort of a "mini-database" of NSAP AFI's / network types, etc. You can use it like so:

import {
    get_nsap_address_schema,
    afi_to_network_type,
    is_individual_afi,
    is_group_afi,
    group_afi_to_individual_afi,
} from "@wildboar/nsap-address/data";

const afi = 0x58;
const schema = get_nsap_address_schema(afi);
schema.network_type; // "e164"
schema.leading_zeroes_in_idi; // true
schema.dsp_syntax; // "decimal"
schema.max_idi_len_digits; // 15
schema.idi_len_exact; // false
afi_to_network_type(afi); // "e164"
is_individual_afi(afi); // true
is_group_afi(afi); // false
group_afi_to_individual_afi(afi) === afi; // true

AI Usage Statement

Most of the code in this repository is based off of a Rust equivalent of this library, which is currently located here (but this will change). The code was manually transliterated from Rust to Typescript by a human (your truly), but with a lot of assistance from the Cursor IDE. I think about six unit tests related to parsing were written exclusively by AI. I don't know what you would consider this, but I would say this module counts as "not written by AI" overall.

Deviations from IETF RFC 1278

  • ICP and IND AFIs recognized in the <afi>-<idi>-<dsp> syntax
  • IP4, IP6, and URL schemes supported in FromStr and Display
  • Zero-length IDI tolerated in parsed strings when using the LOCAL syntax

To Do (Future)

Note

I think there is an error in IETF RFC 1278: it specifies a special AFI syntax for LOCAL AFIs, but this syntax requires at least one digit for the IDI and ITU-T Recommendation X.213 says that the Local AFI uses zero digits for the IDI.