3.0.0-alpha.55 • Published 5 months ago

@ietf-tools/idnits v3.0.0-alpha.55

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
5 months ago

⚠️ This branch is for the new JS-based idnits3. For the older shell-based idnits2, view the v2 branch instead.


Installation

  1. Install Node.js 18.x or later
  2. Install idnits using one of the methods:

Globally (recommended)

npm install -g @ietf-tools/idnits

In an existing npm project

npm install @ietf-tools/idnits

Without Installation

npx @ietf-tools/idnits <args>

!TIP This is only useful for quickly running the command once without installing. If you plan on using this tool regularly, you should install it globally instead.

CLI Usage

idnits [args] <file path|url>
ArgumentsAliasDescriptionDefault
--filter-fFilter output to only certain severity types. Can be declared multiple times to filter multiple severity types.Accepted values: errors, warnings, comments
--mode-mValidation mode, must be either normal, forgive-checklist or submissionAccepted shorthands: norm, n, f-c, fc, f, sub, snormal
--no-colorDisable colors in pretty output.No effect in other output formats.
--no-progressDisable progress messages / animations in pretty output.No effect in other output formats.
--offlineDisable validations that require an internet connection.
--output-oOutput format, must be either pretty, simple, json or countpretty
--solarizedUse alternate colors for a solarized light theme terminal.Only used with the pretty output format.
--year-yExpect the given year in the boilerplate
--help-hPrint the help text and exit
--versionPrint the version and exit

Library Usage

!NOTE The library documentation is a work in progress.

Ensure you installed the library locally to your project (npm install @ietf-tools/idnits).

Simple Validation Run

Use the checkNits() method to quickly run all the validation checks and return a results array.

import { checkNits } from '@ietf-tools/idnits'

const documentRawBuffer = ...
const documentFileName = 'draft-ietf-abcd-efgh-01.xml'

const results = await checkNits(documentRawBuffer, documentFileName)

Task Runner

You can implement your own task runner to have full control over how the validations are executed. The getAllValidations() method returns a list of all validations that should be run.

import { getAllValidations } from '@ietf-tools/idnits'

const ext = filename.endsWith('.xml') ? 'xml' : 'txt'
const result = []
const ctx = {
  raw,
  filename,
  options: {
    allowedDomains,
    mode,
    offline,
    year
  }
}

const validations = getAllValidations(ext)

for (const valGroup of validations) {
  // Skip validation group if condition is not met
  if (valGroup.condition && !valGroup.condition(ctx)) {
    continue
  }

  // Run validations in parallel when possible
  if (valGroup.concurrent) {
    const valGroupResult = await Promise.all(valGroup.tasks.map(valTask => valTask.task(ctx)))
    for (const taskResult of valGroupResult) {
      if (Array.isArray(taskResult)) {
        result.push(...taskResult)
      }
    }
  } else {
    // Run validations sequentially otherwise
    for (const valTask of valGroup.tasks) {
      const taskResult = await valTask.task(ctx)
      if (!valTask.isVoid && Array.isArray(taskResult)) {
        result.push(...taskResult)
      }
    }
  }
}

return result

Tests

Tests are made using the Jest library and are located under the tests directory.

You can run the suite of tests using:

# Make sure you installed dependencies first:
npm install

# Run the tests
npm test

Code coverage is expected to reach 100%. Ensure this is still the case when making edits / adding new functionality.

Development

  1. Clone the project
  2. Run npm install
  3. Run the CLI: (replacing <args> and <file path|url> with the desired flags + file path)
    node cli.js <args> <file path|url>
3.0.0-alpha.50

6 months ago

3.0.0-alpha.52

6 months ago

3.0.0-alpha.51

6 months ago

3.0.0-alpha.54

6 months ago

3.0.0-alpha.53

6 months ago

3.0.0-alpha.55

5 months ago

3.0.0-alpha.38

8 months ago

3.0.0-alpha.37

8 months ago

3.0.0-alpha.39

8 months ago

3.0.0-alpha.47

7 months ago

3.0.0-alpha.46

7 months ago

3.0.0-alpha.49

7 months ago

3.0.0-alpha.48

7 months ago

3.0.0-alpha.41

7 months ago

3.0.0-alpha.40

7 months ago

3.0.0-alpha.42

7 months ago

3.0.0-alpha.45

7 months ago

3.0.0-alpha.44

7 months ago

3.0.0-alpha.36

2 years ago

3.0.0-alpha.35

2 years ago

3.0.0-alpha.34

2 years ago

3.0.0-alpha.30

2 years ago

3.0.0-alpha.32

2 years ago

3.0.0-alpha.31

2 years ago

3.0.0-alpha.33

2 years ago

3.0.0-alpha.25

2 years ago

3.0.0-alpha.27

2 years ago

3.0.0-alpha.26

2 years ago

3.0.0-alpha.29

2 years ago

3.0.0-alpha.28

2 years ago

3.0.0-alpha.14

2 years ago

3.0.0-alpha.13

2 years ago

3.0.0-alpha.16

2 years ago

3.0.0-alpha.15

2 years ago

3.0.0-alpha.18

2 years ago

3.0.0-alpha.17

2 years ago

3.0.0-alpha.19

2 years ago

3.0.0-alpha.24

2 years ago

3.0.0-alpha.21

2 years ago

3.0.0-alpha.20

2 years ago

3.0.0-alpha.23

2 years ago

3.0.0-alpha.22

2 years ago

3.0.0-alpha.12

3 years ago

3.0.0-alpha.11

3 years ago

3.0.0-alpha.10

3 years ago

3.0.0-alpha.9

3 years ago

3.0.0-alpha.8

3 years ago

3.0.0-alpha.7

3 years ago

3.0.0-alpha.6

3 years ago

3.0.0-alpha.5

3 years ago

3.0.0-alpha.4

3 years ago

3.0.0-alpha.3

3 years ago

3.0.0-alpha.2

3 years ago

3.0.0-alpha.1

3 years ago