@jeswr/prefixcc
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

prefixcc

Get prefixes for your URIs using the prefix.cc Web API.

GitHub license npm version build Dependabot semantic-release

Usage

Primarily this library can be used to look up common prefixes for a given URI, and also look up the URI most commonly associated with a prefix.

import { uriToPrefix, prefixToUri, lookupAllPrefixes } from '@jeswr/prefixcc'

const prefix = await uriToPrefix('http://xmlns.com/foaf/0.1/'); // foaf
const url = await prefixToUri('foaf');                          // http://xmlns.com/foaf/0.1/

// Returns an object with all prefixes recorded in prefix.cc
const prefixes = await lookupAllPrefixes(); // { ..., foaf: 'http://xmlns.com/foaf/0.1/', ... }

It can also mint new prefixes when there are no recommended ones available

await uriToPrefix('https://www.my-url/etad/', { mintOnUnknown: true }); // etad

and ensure that prefixes are unique from those that you're already using

await uriToPrefix(
  'https://www.my-url-2/etad/', {
    mintOnUnknown: true,
    existingPrefixes: { etad: 'https://www.my-url/etad/' }
}); // etad0

await uriToPrefix(
  'http://xmlns.com/foaf/0.1/', {
    existingPrefixes: { foaf: 'https://www.my-url/' }
}); // foaf0

License

©2022–present Jesse Wright, MIT License.

Package Sidebar

Install

npm i @jeswr/prefixcc

Weekly Downloads

1,997

Version

1.2.1

License

MIT

Unpacked Size

18.6 kB

Total Files

17

Last publish

Collaborators

  • jeswr