Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rdf-validate-datatype

Package Overview
Dependencies
Maintainers
3
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rdf-validate-datatype

Validate literal value of an RDF term based on its datatype.

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.7K
increased by50.79%
Maintainers
3
Weekly downloads
 
Created
Source

rdf-validate-datatype

Validate literal value of an RDF term based on its declared datatype.

npm version

Install

$ npm install rdf-validate-datatype

Usage

validateTerm

import { validateTerm } from 'rdf-validate-datatype'
import rdf from '@rdfjs/data-model'
import { xsd } from '@tpluscode/rdf-ns-builders'

const term = rdf.literal('test')
const isValid = validateTerm(term) // -> true

const term = rdf.literal('2019-01-01', xsd.date)
const isValid = validateTerm(term) // -> true

const term = rdf.literal('invalid date', xsd.date)
const isValid = validateTerm(term) // -> false

validateQuad

validateQuad validates that the .object of a given quad is valid in regards to its declared datatype.

import { validateQuad } from 'rdf-validate-datatype'
import rdf from '@rdfjs/data-model'
import { schema, xsd } from '@tpluscode/rdf-ns-builders'

const quad = rdf.quad(
  rdf.namedNode('bob'),
  schema.birthDate,
  rdf.literal('2019-01-01', xsd.date)
)
const isValid = validateQuad(term) // -> true

const quad = rdf.quad(
  rdf.namedNode('bob'),
  schema.birthDate,
  rdf.literal('invalid date', xsd.date)
)
const isValid = validateQuad(term) // -> false

Configuring validators

Datatype validators are stored in a registry. They can be changed at runtime.

import { validators, validateTerm } from 'rdf-validate-datatype'
import rdf from '@rdfjs/data-model'
import { xsd } from '@tpluscode/rdf-ns-builders'

// Register a new datatype
const myDatatype = rdf.namedNode('my-datatype')
validators.register(myDatatype, value => value.startsWith('X-'))
validateTerm(rdf.literal('X-test', myDatatype)) // -> true
validateTerm(rdf.literal('test', myDatatype)) // -> false

// Override an existing datatype
validators.register(xsd.date, value => true)
validateTerm(rdf.literal('banana', xsd.date)) // -> true

Keywords

FAQs

Package last updated on 18 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc