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 🙏

© 2024 – Pkg Stats / Ryan Hefner

zonemaster-js

v2.0.0

Published

JS interface for Zonemaster from IIS.se

Downloads

5

Readme

Zonemaster.js

JavaScript interface for Zonemaster JSONRPC API.

Build Status codecov npm version

Installation & basic usage

$ npm install --save zonemaster-js
import Zonemaster from 'zonemaster-js';

const zm = new Zonemaster('https://backend-url');
// backend needs to live on the same domain or accept CORS requests,
// use --disable-web-security flag for Chrome for easy testing


// using with Promises (ES6/ES2015):

zm.versionInfo().then(version => console.log(version));
// → {'zonemaster_backend': '…', 'zonemaster_engine': '…'}


// using with async/await (ES8/ES2017):

console.log(await zm.versionInfo());
// → {'zonemaster_backend': '…', 'zonemaster_engine': '…'}
console.log(await zm.nameserverIPs('nic.cz'));
// → {'nameservers': ['2001:1488:0:3::2', '217.31.205.50']}

Note: await can be used inside async functions only, as there is no support for "top-level await" in JS (currently?):

API

Table of Contents

Zonemaster

Interface to the Zonemaster backend.

Parameters

  • backendUrl Zonemaster backend URL, including protocol

Examples

const zm = new Zonemaster('http://localhost:5000/')

dataFromParentZone

Get domain data from it's parent zone. Async method.

API method: https://github.com/dotse/zonemaster-backend/blob/master/docs/API.md#api-method-get_data_from_parent_zone

Parameters

Examples

zm.dataFromParentZone('nic.cz')
// → {'ns_list': […], 'ds_list': […]}
zm.dataFromParentZone('does-not-exist.cz')
// → {'error': 'Domain does not exist.'}
zm.dataFromParentZone('.cz')
// → {'error': 'Domain name name or label outside allowed length'} -- error message from backend

Returns Object data

Returns Array data.ns_list - See backend docs.

Returns Array data.ds_list - See backend docs.

Returns String data.error - Returns an error message when both ns_list and ds_list are empty or when the backend responds with an error message.

startDomainTest

Start a new domain test. Async method.

API method: https://github.com/dotse/zonemaster-backend/blob/master/docs/API.md#api-method-start_domain_test

Parameters

  • config Object A config object with domain and some advanced options
    • config.domain String Domain name, required
    • config.nameservers Object Nameservers to use, optional, see backend docs
    • config.profile String Test profile to use, optional
    • config.ipv4 Boolean Use IPv4, optional
    • config.ipv6 Boolean Use IPv6, optional
    • config.priority Number Test priority, optional
  • domain String …or just a a domain name string

Examples

zm.startDomainTest('nic.cz')
zm.startDomainTest({domain: 'nic.cz', nameservers: {…}, ipv6: true})

Returns Object data

Returns String data.id - Test ID

testHistory

Get test history for a domain. Async method.

API method: https://github.com/dotse/zonemaster-backend/blob/master/docs/API.md#api-method-get_test_history

Parameters

Returns Object data

testProgress

Get test progress percentage. Async method.

API method: https://github.com/dotse/zonemaster-backend/blob/master/docs/API.md#api-method-test_progress

Parameters

  • testId
  • id String Test ID (as returned from the startDomainTest method)

Examples

zm.testProgress('abdf123456789012')
// → {progress: 80}
zm.testProgress('foo')
// → {error: 'Invalid test ID.'}
zm.testProgress('1234567890123456')
// → {error: 'Test not found.'}

Returns Object data

Returns Number data.progress - Test progress percentage

Returns String data.error - Returns an error message for an invalid ID format or when the test wasn't found.

testResult

Get test result. Async method.

API method: https://github.com/dotse/zonemaster-backend/blob/master/docs/API.md#api-method-get_test_results

Parameters

  • testId
  • language String (optional) Requested language for the test result messages (optional, default 'en')
  • id String Test ID (as returned from the startDomainTest method)

Returns Object data

Returns String data.error - Returns an error message for an invalid ID format or when the test wasn't found.

validateSyntax

Checks the domain name and params for validity. Sync method.

All checks are done localy, since the "validate_syntax" method was removed from backend.

Parameters

  • config Object A config object, same structure as in startDomainTest

Examples

zm.validateSyntax('nic.cz')
// → {ok: true, message: 'Syntax ok'}
zm.validateSyntax({domain: 'nic.cz', ipv4: false, ipv6: true})
// → {ok: true, message: 'Syntax ok'}
zm.validateSyntax('_')
// → {ok: false, message: 'Invalid domain.'}
zm.validateSyntax('háčkyčárky.cz')
// → {ok: false, message: 'Domain name contains non-ascii characters and IDN conversion is not installed'}
// (domain is valid, but didn't pass backend validation)

Returns Object data

Returns Boolean data.ok

Returns String data.message - Human readable message from the backend

validateTestID

Validate test ID with a simple regex.

Parameters

Examples

zm.validateTestID('abdf123456789012')
// → true
zm.validateTestID('foo')
// → false

Returns Boolean

versionInfo

Get Zonemaster's backend and engine version. Async method.

API method: https://github.com/dotse/zonemaster-backend/blob/master/docs/API.md#api-method-version_info

Examples

zm.versionInfo()
// → {'zonemaster_backend': '…', 'zonemaster_engine': '…'}

Returns Object data

Returns String data.zonemaster_backend

Returns String data.zonemaster_engine

Development

$ git clone https://github.com/helb/zonemaster-js.git && cd zonemaster-js.git
$ npm install

Testing

$ npm test

Set your options in test-config.js. HTTP calls are mocked by default, if you want to use a real backend, set it's URL in the config file and enable it's use:

const config = {
  backendUrl: 'https://url:port/',
  useRealBackend: true,
  …

Generating a test coverage report:

$ npm run coverage

Reports are placed into ./coverage directory and a HTML version should open in your default browser when finished.

Building

$ npm run build

Build output is placed to ./dist directory. Multiple module formats are built, as provided by microbundle (CJS, UMD & ESM).