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

semantic-chess

v0.2.1

Published

Semantic version of chess.js

Downloads

21

Readme

Semantic Chess

A semantic representation of a chess game in JavaScript that allows doing and loading moves. It will generate the corresponding RDF, SPARQL updates, and inbox notifications. It is used in solid-chess, a decentralized chess game, based on Solid.

The full documentation can be found here.

Install

You can install the library via

npm i semantic-chess

Usage

Create a new chess game

In the example below we create a new game and do a single move. We print the corresponding SPARQL update for that move together the notification that should be send to the inbox of the opponent.

const SemanticChess = require('semantic-chess').SemanticChess;

const chess = new SemanticChess({
  url: 'http://example.org/mygame',
  userWebId: 'http://example.org/user1/#me',
  userDataUrl: 'http://example.org/storage/chess.ttl',
  opponentsWebId: 'http://example.org/user2/#me',
  name: 'My first chess game!'
});

const move = chess.doMove('e4');

console.log(move.sparqlUpdate);
// INSERT DATA {
//   <http://example.org/mygame> <http://purl.org/NET/rdfchess/ontology/hasHalfMove> <http://example.org/storage/chess.ttl#ufulmwjo8f4vo7>;
//     <http://purl.org/NET/rdfchess/ontology/hasFirstHalfMove> <http://example.org/storage/chess.ttl#ufulmwjo8f4vo7>.
//
//   <http://example.org/storage/chess.ttl#ufulmwjo8f4vo7> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/NET/rdfchess/ontology/HalfMove>;
//     <http://purl.org/NET/rdfchess/ontology/hasSANRecord> "e4"^^<http://www.w3.org/2001/XMLSchema#string>.
// }
 

console.log(move.notification);
// <http://example.org/mygame> <http://purl.org/NET/rdfchess/ontology/hasFirstHalfMove> <http://example.org/storage/chess.ttl#ufulmwjo8f4vo7>.

Note that the URLs of the moves might be different for every run, as a unique id is generated for every move.

Load a chess game via its url

In the example below we load a game from its url. The Loader needs a fetch function that will be used to fetch the data. The fetch from solid-auth-client is a possibility. We also need to provide the WebId of the current user, so the game know when a move is valid. Furthermore, the base URL that is used for new moves is also provided. This can either be a string or a function that returns a string.

const Loader = require('semantic-chess').Loader;
const auth = require('solid-auth-client);

const loader = new Loader(auth.fetch);
const chess = await loader.loadFromUrl('http://example.org/mygame', 'http://example.org/user1/#me', 'http://example.org/storage/chess.ttl');

Tests

The test are executed via

npm test

The test files can be found in the folder lib and have the extension test.js.

Documentation

The documentation is generated via

npm run doc

You can find the resulting HTML in the folder docs.

License

© 2018 Pieter Heyvaert, MIT License