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

rdf-validate-datatype

v0.2.1

Published

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

Downloads

15,905

Readme

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