Skip to content

Latest commit

 

History

History
49 lines (35 loc) · 2.06 KB

README.md

File metadata and controls

49 lines (35 loc) · 2.06 KB

Validate IRI

Build status Coverage Status npm version

This tool validates an IRI, either using strict RFC 3987 grammar, or using a faster but less strict pragmatic validation mode. It works in both JavaScript and TypeScript.

Installation

$ npm install validate-iri

or

$ yarn add validate-iri

This package also works out-of-the-box in browsers via tools such as webpack and browserify.

Usage

Multiple validation modes are provided:

  • IriValidationStrategy.Strict: carefully validates the IRI using RFC 3987 grammar. This is the default value.
  • IriValidationStrategy.Pragmatic: quickly validates that the IRI has a valid scheme and does not contain any character forbidden by the N-Triples, Turtle and N3 grammars.
  • IriValidationStrategy.None: does not validate the IRI at all.

Example:

import { validateIri, IriValidationStrategy } from 'validate-iri'
const yourIri = 'https://example.com/john-doe'
validateIri(yourIri, IriValidationStrategy.Pragmatic) // Will return an error if the IRI is invalid.

Performance

When using strict validation mode, a significant performance overhead should be taken into account. In isolation, strict validation is an order of magnitude slower than pragmatic validation.

When used in a parser such as rdfxml-streaming-parser.js, the performance impact on parsing is the following (GeoSpecies Knowledge Base with 1.8M triples):

  • Strict validation: 12.053s
  • Pragmatic validation: 9.116s
  • No validation: 8.338s

License

This code is released under the MIT license.