Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
schema-dts
Advanced tools
The schema-dts npm package provides TypeScript definitions for Schema.org vocabulary, allowing developers to create structured data in a type-safe manner. This package is useful for generating JSON-LD scripts for SEO and other purposes.
Creating a Person schema
This feature allows you to create a Person schema using TypeScript definitions. The code sample demonstrates how to define a person named John Doe who works as a Software Engineer for a company named Tech Company.
const person: schema.Person = {
'@type': 'Person',
name: 'John Doe',
jobTitle: 'Software Engineer',
worksFor: {
'@type': 'Organization',
name: 'Tech Company'
}
};
Creating an Event schema
This feature allows you to create an Event schema using TypeScript definitions. The code sample demonstrates how to define an event named Tech Conference 2023, including its start date and location.
const event: schema.Event = {
'@type': 'Event',
name: 'Tech Conference 2023',
startDate: '2023-11-01T09:00:00Z',
location: {
'@type': 'Place',
name: 'Convention Center',
address: '123 Main St, Anytown, USA'
}
};
Creating a Product schema
This feature allows you to create a Product schema using TypeScript definitions. The code sample demonstrates how to define a product named Smartphone, including its brand and price.
const product: schema.Product = {
'@type': 'Product',
name: 'Smartphone',
brand: {
'@type': 'Brand',
name: 'TechBrand'
},
offers: {
'@type': 'Offer',
price: '699.99',
priceCurrency: 'USD'
}
};
The jsonld package is a JSON-LD processor and API implementation for JavaScript. It allows you to work with JSON-LD data, including parsing, serializing, and transforming JSON-LD documents. Unlike schema-dts, it does not provide TypeScript definitions for Schema.org vocabulary but focuses on JSON-LD processing.
The schema-org package provides a set of tools for working with Schema.org data in JavaScript. It includes utilities for creating, validating, and manipulating Schema.org data. While it offers similar functionalities to schema-dts, it does not provide TypeScript definitions and focuses more on data manipulation and validation.
The structured-data-testing-tool package is a Node.js library for testing structured data against Schema.org definitions. It allows you to validate JSON-LD, Microdata, and RDFa formats. Unlike schema-dts, it is primarily focused on testing and validation rather than generating structured data.
JSON-LD TypeScript types for Schema.org vocabulary.
schema-dts provides TypeScript definitions for Schema.org vocabulary in JSON-LD format. The typings are exposed as complete sets of discriminated type unions, allowing for easy completions and stricter validation.
Note: This is not an officially supported Google product.
To use the typings for your project, simply add the schema-dts
NPM package to
your project:
npm install schema-dts
Then you can use it by importing "schema-dts"
.
import {Person} from 'schema-dts';
const inventor: Person = {
'@type': 'Person',
name: 'Grace Hopper',
disambiguatingDescription: 'American computer scientist',
birthDate: '1906-12-09',
deathDate: '1992-01-01',
awards: [
'Presidential Medal of Freedom',
'National Medal of Technology and Innovation',
'IEEE Emanuel R. Piore Award',
],
};
JSON-LD requires a "@context"
property to be set on the top-level JSON object,
to describe the URIs represeting the types and properties being referenced.
schema-dts provides the WithContext<T>
type to facilitate this.
import {Organization, Thing, WithContext} from 'schema-dts';
export function JsonLd<T extends Thing>(json: WithContext<T>): string {
return `<script type="application/ld+json">
${JSON.stringify(json)}
</script>`;
}
export const MY_ORG = JsonLd<Organization>({
'@context': 'https://schema.org',
'@type': 'Corporation',
name: 'Google LLC',
});
JSON-LD supports '@graph'
objects that have richer interconnected links
between the nodes. You can do that easily in schema-dts
by using the Graph
type.
Notice that any node can have an @id
when defining it. And you can reference
the same node from different places by simply using an ID stub, for example
{ '@id': 'https://my.site/about/#page }
below is an ID stub.
The example below shows potential JSON-LD for an About page. It includes
definitions of Alyssa P. Hacker (the author & subject of the page), the specific
page in this URL, and the website it belongs to. Some objects are still defined
as inline nested objects (e.g. Occupation), since they are only referenced by
their parent. Other objects are defined at the top-level with an @id
, because
multiple nodes refer to them.
import {Graph} from 'schema-dts';
const graph: Graph = {
'@context': 'https://schema.org',
'@graph': [
{
'@type': 'Person',
'@id': 'https://my.site/#alyssa',
name: 'Alyssa P. Hacker',
hasOccupation: {
'@type': 'Occupation',
name: 'LISP Hacker',
qualifications: 'Knows LISP',
},
mainEntityOfPage: {'@id': 'https://my.site/about/#page'},
subjectOf: {'@id': 'https://my.site/about/#page'},
},
{
'@type': 'AboutPage',
'@id': 'https://my.site/#site',
url: 'https://my.site',
name: "Alyssa P. Hacker's Website",
inLanguage: 'en-US',
description: 'The personal website of LISP legend Alyssa P. Hacker',
mainEntity: {'@id': 'https://my.site/#alyssa'},
},
{
'@type': 'WebPage',
'@id': 'https://my.site/about/#page',
url: 'https://my.site/about/',
name: "About | Alyssa P. Hacker's Website",
inLanguage: 'en-US',
isPartOf: {
'@id': 'https://my.site/#site',
},
about: {'@id': 'https://my.site/#alyssa'},
mainEntity: {'@id': 'https://my.site/#alyssa'},
},
],
};
FAQs
A TypeScript package with latest Schema.org Schema Typings
The npm package schema-dts receives a total of 288,983 weekly downloads. As such, schema-dts popularity was classified as popular.
We found that schema-dts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.