package
Activity Streams 2.0 JavaScript Implementation
npm install activitystrea.msGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Based on:
Version 4 is an ES module and requires Node.js 22.12 or later. CommonJS
consumers on those versions can still load it with a plain require().
The library also runs in browsers: it bundles cleanly with standard
tooling (esbuild, webpack, etc.) and is tested in Chromium, Firefox, and
WebKit.
npm install activitystrea.ms
Use as.import() to turn a plain JavaScript Activity Streams document into a
model object. This works for documents you receive and documents you create.
Estimated unpacked size across 11 packages.
8.1 MB
Includes dependencies.
jasnell
jasnell@gmail.com
import as from 'activitystrea.ms'
const activity = await as.import({
'@context': 'https://www.w3.org/ns/activitystreams',
type: 'Create',
actor: 'https://social.example/user/sample',
object: {
type: 'Note',
content: 'Hello, world!'
}
})Model type names are expanded IRIs. Object-valued properties are iterable
collections of references or embedded objects; .first retrieves the first
value. Text properties such as content are language values, read with .get().
console.log(activity.type) // 'https://www.w3.org/ns/activitystreams#Create'
console.log(activity.actor.first.id) // 'https://social.example/user/sample'
console.log(activity.object.first.content.get()) // 'Hello, world!'Language maps can be supplied directly in the imported document:
const note = await as.import({
'@context': 'https://www.w3.org/ns/activitystreams',
type: 'Note',
contentMap: {
en: 'Hello, world!',
fr: 'Bonjour tout le monde !'
}
})
console.log(note.content.get('fr')) // 'Bonjour tout le monde !'export() returns a plain JavaScript document after JSON-LD compaction.
write() returns a JSON string, and prettyWrite() returns indented JSON.
All three methods are asynchronous.
const document = await activity.export()
console.log(document.type) // 'Create'
console.log(document.object.content) // 'Hello, world!'
const json = await activity.write()
const prettyJson = await activity.prettyWrite()To retain an imported document's original context when exporting, pass
{ useOriginalContext: true } to export(), write(), or prettyWrite().
Custom context documents can be registered with as.registerContext() for
offline resolution; see the API reference below.
Bundle the library and its dependencies with browser tooling such as esbuild or webpack. The source dependency graph still includes CommonJS packages, so resolving package names alone is insufficient for direct browser imports. Browser tests that import source modules need the same dependency transformation as the application build.
The fluent builder interface remains supported as an alternative; see Builder interface below.
The builder interface uses a fluent factory pattern for creating AS objects. There are
factory methods for each of the main types of objects defined by the Activity
Streams 2.0 vocabulary. Each takes an optional array of types that will be set
on the object. If the [types] is unspecified, a default will be assigned
depending on the object being created. Each of the factory methods returns a
builder specific to the kind of object being generated. Once the object has
been built, call the get method to return the generated object.
as.object([types])as.activity([types])as.collection([types])as.orderedCollection([types])as.collectionPage([types])as.orderedCollectionPage([types])as.link([types])as.accept([types])as.tentativeAccept([types])as.add([types])as.arrive([types])as.create([types])as.delete([types])as.follow([types])as.ignore([types])as.join([types])as.leave([types])as.like([types])as.offer([types])as.invite([types])as.reject([types])as.tentativeReject([types])as.remove([types])as.undo([types])as.update([types])as.view([types])as.listen([types])as.read([types])as.move([types])as.travel([types])as.announce([types])as.block([types])as.flag([types])as.dislike([types])as.application([types])as.group([types])as.person([types])as.organization([types])as.service([types])as.article([types])as.document([types])as.relationship([types])as.profile([types])as.audio([types])as.image([types])as.video([types])as.note([types])as.page([types])as.question([types])as.event([types])as.place([types])as.mention([types])as.tombstone([types])The object returned by get() is a read-only view of the Activity Stream
object. It will have property methods that are specific to the object's type.
You can export the built object as an ordinary Javascript object using the
export method. This will generate a JSON-LD compliant Javascript object.
import as from 'activitystrea.ms'
const note = as.note()
.name('foo')
.content('this is a simple note')
.get()
console.log(note.name.valueOf())
console.log(note.content.valueOf())
console.log(note.type)import as from 'activitystrea.ms'
const obj = await as.note()
.name('foo')
.content('this is a simple note')
.get()
.export()
// obj is an ordinary javascript object
console.log(obj.type)
console.log(obj.name)
console.log(obj.content)To serialize the Activity Streams object out as JSON, use the write or
prettyWrite methods
import as from 'activitystrea.ms'
const doc = await as.note()
.name('foo')
.content('this is a simple note')
.write()import as from 'activitystrea.ms'
const doc = await as.note()
.name('foo')
.content('this is a simple note')
.prettyWrite()Note that the export, write, and prettyWrite methods are all async and return promises.
This is largely because of the JSON-LD processing that's happening under the covers.
import as from 'activitystrea.ms'The base module. (CommonJS consumers on Node 22.12+ can use
const as = require('activitystrea.ms') instead.)
<Promise<as.models.Object>> as.import(obj[, options])Imports the specified JavaScript object obj, performing JSON-LD expansion as necessary. Returns a promise that resolves to the imported as.models.Object.
const obj = {
'@context': 'https://www.w3.org/ns/activitystreams',
type: 'Person',
name: 'Joe'
}
const imp = await as.import(obj)
console.log(imp.type)<void> as.registerContext(url, context)Registers a JSON-LD context document for offline resolution. When an
imported document's @context includes the registered URL, the local copy
is used instead of fetching it over the network. The AS2 context and
https://w3id.org/security/v1 are pre-registered.
as.registerContext('https://example.com/context', {
'@context': {
ex: 'https://example.com/context#',
bar: 'ex:bar'
}
})as.mediaTypeSet to a constant value of application/activity+json
<as.models.Object.Builder> as.object([types])Returns a new as.models.Object.Builder instance.
<as.models.Activity.Builder> as.activity([types])Returns a new as.models.Activity.Builder instance.
<as.models.Collection.Builder> as.collection([types])Returns a new as.models.Collection.Builder instance.
<as.models.OrderedCollection.Builder> as.orderedCollection([types])Returns a new as.models.OrderedCollection.Builder instance.
<as.models.CollectionPage.Builder> as.collectionPage([types])Returns a new as.models.CollectionPage.Builder instance.
<as.models.OrderedCollectionPage.Builder> as.orderedCollectionPage([types])Returns a new as.models.OrderedCollectionPage.Builder instance.
<as.models.Link.Builder> as.link([types])Returns a new as.models.Link.Builder instance.
<as.models.Activity.Builder> as.accept([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Accept activity.
<as.models.Activity.Builder> as.tentativeAccept([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#TentativeAccept activity.
<as.models.Activity.Builder> as.add([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Add activity.
<as.models.Activity.Builder> as.arrive([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Arrive activity.
<as.models.Activity.Builder> as.create([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Create activity.
<as.models.Activity.Builder> as.delete([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Delete activity.
<as.models.Activity.Builder> as.follow([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Follow activity.
<as.models.Activity.Builder> as.ignore([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Ignore activity.
<as.models.Activity.Builder> as.join([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Join activity.
<as.models.Activity.Builder> as.leave([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Leave activity.
<as.models.Activity.Builder> as.like([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Like activity.
<as.models.Activity.Builder> as.offer([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Offer activity.
<as.models.Activity.Builder> as.invite([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Invite activity.
<as.models.Activity.Builder> as.reject([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Reject activity.
<as.models.Activity.Builder> as.tentativeReject([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#TentativeReject activity.
<as.models.Activity.Builder> as.remove([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Remove activity.
<as.models.Activity.Builder> as.undo([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Undo activity.
<as.models.Activity.Builder> as.update([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Update activity.
<as.models.Activity.Builder> as.view([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#View activity.
<as.models.Activity.Builder> as.listen([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Listen activity.
<as.models.Activity.Builder> as.read([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Read activity.
<as.models.Activity.Builder> as.move([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Move activity.
<as.models.Activity.Builder> as.travel([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Travel activity.
<as.models.Activity.Builder> as.announce([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Announce activity.
<as.models.Activity.Builder> as.block([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Block activity.
<as.models.Activity.Builder> as.flag([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Flag activity.
<as.models.Activity.Builder> as.dislike([types])Returns a new as.models.Activity.Builder instance generating an http://www.w3.org/ns/activity#Dislike activity.
<as.models.Object.Builder> as.application([types])Returns a new as.models.Object.Builder instance generating an http://www.w3.org/ns/activity#Application object.
<as.models.Object.Builder> as.group([types])Returns a new as.models.Object.Builder instance generating an http://www.w3.org/ns/activity#Group object.
<as.models.Object.Builder> as.person([types])Returns a new as.models.Object.Builder instance generating an http://www.w3.org/ns/activity#Person object.
<as.models.Object.Builder> as.service([types])Returns a new as.models.Object.Builder instance generating an http://www.w3.org/ns/activity#Service object.
<as.models.Object.Builder> as.organization([types])Returns a new as.models.Object.Builder instance generating an http://www.w3.org/ns/activity#Organization object.
<as.models.Object.Builder> as.article([types])Returns a new as.models.Object.Builder instance generating an http://www.w3.org/ns/activity#Article object.
<as.models.Object.Builder> as.document([types])Returns a new as.models.Object.Builder instance generating an http://www.w3.org/ns/activity#Document object.
<as.models.Object.Builder> as.audio([types])Returns a new as.models.Object.Builder instance generating an http://www.w3.org/ns/activity#Audio object.
<as.models.Object.Builder> as.image([types])Returns a new as.models.Object.Builder instance generating an http://www.w3.org/ns/activity#Image object.
<as.models.Object.Builder> as.video([types])Returns a new as.models.Object.Builder instance generating an http://www.w3.org/ns/activity#Video object.
<as.models.Object.Builder> as.note([types])Returns a new as.models.Object.Builder instance generating an http://www.w3.org/ns/activity#Note object.
<as.models.Object.Builder> as.page([types])Returns a new as.models.Object.Builder instance generating an http://www.w3.org/ns/activity#Page object.
<as.models.Question.Builder> as.question([types])Returns a new as.models.Question.Builder instance generating an http://www.w3.org/ns/activity#Question object.
<as.models.Object.Builder> as.event([types])Returns a new as.models.Object.Builder instance generating an http://www.w3.org/ns/activity#Event object.
<as.models.Relationship.Builder> as.relationship([types])Returns a new as.models.Relationship.Builder instance generating an http://www.w3.org/ns/activity#Relationship object.
<as.models.Profile.Builder> as.profile([types])Returns a new as.models.Profile.Builder instance generating an http://www.w3.org/ns/activity#Profile object.
<as.models.Place.Builder> as.place([types])Returns a new as.models.Place.Builder instance generating an http://www.w3.org/ns/activity#Place object.
<as.models.Link.Builder> as.mention([types])Returns a new as.models.Link.Builder instance generating an http://www.w3.org/ns/activity#Mention link.
<as.models.Tombstone.Builder> as.tombstone([types])Returns a new as.models.Tombstone.Builder instance generating an
http://www.w3.org/ns/activity#Tombstone object.
as.models.Base(expanded, builder)as.models.Base is the base class for all objects. It is not intended to be used directly by developers.
expanded - The underlying JSON-LD expanded JavaScript objectbuilder - A as.model.Base.Builder subclass<string> as.models.Base.prototype.idReturns the value of the JSON-LD @id property or underfined.
<string||string[]> as.models.Base.prototype.typeReturns the value of the JSON-LD @type property. If @type has only a single value, then a single JavaScript string will be returned. If the @type has multiple values, a JavaScript Array will be returned. If the @type is not specified, undefined will be returned.
<boolean> as.models.Base.prototype.has(key)Returns true if the object has a value for the specified key
<any> as.models.Base.prototype.get(key)Returns the value for the specified key. The return value will vary based on the property being requested. The return value can be a JavaScript primitive, a as.models.Base instance, or an Iterable of JavaScript primitives or as.models.Base instances. Will returned undefined if the no value is specified for the given key
<Promise> as.models.Base.prototype.export([options])Exports the object by performing a JSON-LD compaction. If export fails, the promise will reject with the error. If the export succeeds, the promise will resolve with the exported JavaScript object.
const obj = await as.import({ type: 'Object', name: 'Sample Person' })
const exp = await obj.export()
console.log(exp.name)
console.log(exp.type)<Promise> as.models.Base.prototype.write([options])Write the object out to a JSON-LD string. If writing fails, the promise will reject with the error. If the write succeeds, the promise will resolve with the JSON-LD string.
const obj = await as.import({ type: 'Object', name: 'Sample Person' })
const string = await obj.write()
console.log(string)<Promise> as.models.Base.prototype.prettyWrite([options])Write the object out to an indented JSON-LD string. If writing fails, the promise will reject with the error. If the write succeeds, the promise will resolve with the JSON-LD string.
const obj = await as.import({ type: 'Object', name: 'Sample Person' })
const string = await obj.prettyWrite()
console.log(string)<as.models.Base.Builder<?>> as.models.Base.prototype.modify()Returns a new as.models.Base.Builder instance that can be used to modify
this object. Note that model objects memoize property values on first
access, so modify() should only be used on objects that have not been
read from yet.
<function> as.models.Base.prototype.template()Returns a function that can be used to create new as.models.Base.Builder instances using this object as a template. The new Builder will be pre-filled with the properties already specified on this object.
const templ = as.like().actor('http://example.org/sally').get().template()
const like1 = await templ().object('http://example.org/1').prettyWrite()
const like2 = await templ().object('http://example.org/2').prettyWrite()as.models.Base.Builder(types, base)The base Builder interface. This is not intended to be used directly by developers. Most of the methods on the Builder instances return a reference back to the Builder itself allowing methods to be chained.
<Builder> as.models.Base.Builder.prototype.id(val)Set the value of the @id property. Calling this repeatedly will overwrite the previous value.
<Builder> as .models.Base.Builder.prototype.set(key, val[, options])Set a value for the specified key.
const object = as.object()
object.set('foo', 'bar')<as.models.Base> as.models.Base.Builder.prototype.get()Returns the constructed as.models.Base instance.
as.models.Object > as.models.BaseThe base class for all Activity Streams 2.0 Object instances. Inherits from as.models.Base
as.models.Object.prototype.attachmentReturns the value of the https://www.w3.org/ns/activitystreams#attachment property. Will be either undefined or an Iterable of as.model.Base instances.
Returns the value of the https://www.w3.org/ns/activitystreams#attributedTo property. Will be either undefined or an Iterable of as.model.Base instances.
as.models.Object.prototype.contentReturns the value of the https://www.w3.org/ns/activitystreams#content property. Will be either undefined or a as.models.LanguageValue.
as.models.Object.prototype.contextReturns the value of the https://www.w3.org/ns/activitystreams#context property. Will be either undefined or an Iterable of as.model.Base instances.
as.models.Object.prototype.nameReturns the value of the https://www.w3.org/ns/activitystreams#name property. Will be either undefined or a as.models.LanguageValue.
as.models.Object.prototype.summaryReturns the value of the https://www.w3.org/ns/activitystreams#summary property. Will be either undefined or a as.models.LanguageValue.
as.models.Object.prototype.endTimeReturns the value of the https://www.w3.org/ns/activitystreams#endTime property. Will be either undefined or a JavaScript Date object.
as.models.Object.prototype.publishedReturns the value of the https://www.w3.org/ns/activitystreams#published property. Will be either undefined or a JavaScript Date object.
as.models.Object.prototype.startTimeReturns the value of the https://www.w3.org/ns/activitystreams#startTime property. Will be either undefined or a JavaScript Date object.
as.models.Object.prototype.updatedReturns the value of the https://www.w3.org/ns/activitystreams#updated property. Will be either undefined or a JavaScript Date object.
as.models.Object.prototype.generatorReturns the value of the https://www.w3.org/ns/activitystreams#generator property. Will be either undefined or an Iterable of as.model.Base instances.
as.models.Object.prototype.iconReturns the value of the https://www.w3.org/ns/activitystreams#icon property. Will be either undefined or an Iterable of as.model.Base instances.
as.models.Object.prototype.imageReturns the value of the https://www.w3.org/ns/activitystreams#image property. Will be either undefined or an Iterable of as.model.Base instances.
as.models.Object.prototype.inReplyToReturns the value of the https://www.w3.org/ns/activitystreams#inReplyTo property. Will be either undefined or an Iterable of as.model.Base instances.
as.models.Object.prototype.locationReturns the value of the https://www.w3.org/ns/activitystreams#location property. Will be either undefined or an Iterable of as.model.Base instances.
as.models.Object.prototype.previewReturns the value of the https://www.w3.org/ns/activitystreams#preview property. Will be either undefined or an Iterable of as.model.Base instances.
as.models.Object.prototype.repliesReturns the value of the https://www.w3.org/ns/activitystreams#replies property. Will be either undefined or an Iterable of as.model.Base instances.
as.models.Object.prototype.audienceReturns the value of the https://www.w3.org/ns/activitystreams#audience property. Will be either undefined or an Iterable of as.model.Base instances.
as.models.Object.prototype.tagReturns the value of the https://www.w3.org/ns/activitystreams#tag property. Will be either undefined or an Iterable of as.model.Base instances.
as.models.Object.prototype.urlReturns the value of the https://www.w3.org/ns/activitystreams#url property. Will be either undefined or an Iterable of as.model.Link instances.
as.models.Object.prototype.toReturns the value of the https://www.w3.org/ns/activitystreams#to property. Will be either undefined or an Iterable of as.model.Base instances.
as.models.Object.prototype.btoReturns the value of the https://www.w3.org/ns/activitystreams#bto property. Will be either undefined or an Iterable of as.model.Base instances.
as.models.Object.prototype.ccReturns the value of the https://www.w3.org/ns/activitystreams#cc property. Will be either undefined or an Iterable of as.model.Base instances.
as.models.Object.prototype.bccReturns the value of the https://www.w3.org/ns/activitystreams#bcc property. Will be either undefined or an Iterable of as.model.Base instances.
as.models.Object.prototype.durationReturns the value of the https://www.w3.org/ns/activitystreams#duration property. Will be either undefined or a frozen plain object with the same numeric properties as a Temporal.Duration: years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, and nanoseconds. All properties are always present, with 0 for unspecified units. Negative durations have negative values. Malformed duration strings yield undefined.
const doc = await as.import({ type: 'Video', duration: 'PT1H30M' })
console.log(doc.duration.hours) // 1
console.log(doc.duration.minutes) // 30as.models.Object.Builder > as.models.Base.BuilderBuilder for as.models.Object instances.
<Builder> as.models.Object.Builder.prototype.attachment(val)Adds a value to the https://www.w3.org/ns/activitystreams#attachment property.
<Builder> as.models.Object.Builder.prototype.attributedTo(val)Adds a value to the https://www.w3.org/ns/activitystreams#attributedTo property.
<Builder> as.models.Object.Builder.prototype.content(val)Sets an optional language-tagged value for the https://www.w3.org/ns/activitystreams#content property. To set
language-tagged values, use the as.langmap method to create a
LanguageValue.Builder.
as.object()
.content('simple content')
.get()as.object()
.content(
as.langmap()
.set('default content')
.set('es', 'other content')
)
.get()<Builder> as.models.Object.Builder.prototype.context(val)Adds a value to the https://www.w3.org/ns/activitystreams#context property.
<Builder> as.models.Object.Builder.prototype.name(val)Sets an optional language-tagged value for the https://www.w3.org/ns/activitystreams#name property.
as.object()
.name('simple display name')
.get()as.object()
.name(
as.langmap()
.set('default display name')
.set('es', 'other display name')
)
.get()<Builder> as.models.Object.Builder.prototype.summary(val)Sets an optional language-tagged value for the https://www.w3.org/ns/activitystreams#summary property.
as.object()
.summary('simple summary')
.get()as.object()
.summary(
as.langmap()
.set('default summary')
.set('es', 'other summary')
)
.get()<Builder> as.models.Object.Builder.prototype.endTime(val)Sets the value of the https://www.w3.org/ns/activitystreams#endTime property.
The value must be a JavaScript Date object.
<Builder> as.models.Object.Builder.prototype.endTimeNow()Sets the value of the https://www.w3.org/ns/activitystreams#endTime property to the current date and time.
<Builder> as.models.Object.Builder.prototype.published(val)Sets the value of the https://www.w3.org/ns/activitystreams#published property.
The value must be a JavaScript Date object.
<Builder> as.models.Object.Builder.prototype.publishedNow()Sets the value of the https://www.w3.org/ns/activitystreams#published property to the current date and time.
<Builder> as.models.Object.Builder.prototype.startTime(val)Sets the value of the https://www.w3.org/ns/activitystreams#startTime property.
The value must be a JavaScript Date object.
<Builder> as.models.Object.Builder.prototype.startTimeNow()Sets the value of the https://www.w3.org/ns/activitystreams#startTime property to the current date and time.
<Builder> as.models.Object.Builder.prototype.updated(val)Sets the value of the https://www.w3.org/ns/activitystreams#updated property.
The value must be a JavaScript Date object.
<Builder> as.models.Object.Builder.prototype.updatedNow()Sets the value of the https://www.w3.org/ns/activitystreams#updated property to the current date and time.
<Builder> as.models.Object.Builder.prototype.generator(val)Adds a value to the https://www.w3.org/ns/activitystreams#generator property.
<Builder> as.models.Object.Builder.prototype.icon(val)Adds a value to the https://www.w3.org/ns/activitystreams#icon property.
<Builder> as.models.Object.Builder.prototype.image(val)Adds a value to the https://www.w3.org/ns/activitystreams#image property.
<Builder> as.models.Object.Builder.prototype.inReplyTo(val)Adds a value to the https://www.w3.org/ns/activitystreams#inReplyTo property.
<Builder> as.models.Object.Builder.prototype.location(val)Adds a value to the https://www.w3.org/ns/activitystreams#location property.
<Builder> as.models.Object.Builder.prototype.preview(val)Adds a value to the https://www.w3.org/ns/activitystreams#preview property.
<Builder> as.models.Object.Builder.prototype.replies(val)Adds a value to the https://www.w3.org/ns/activitystreams#replies property.
<Builder> as.models.Object.Builder.prototype.audience(val)Adds a value to the https://www.w3.org/ns/activitystreams#audience property.
<Builder> as.models.Object.Builder.prototype.tag(val)Adds a value to the https://www.w3.org/ns/activitystreams#tag property.
<Builder> as.models.Object.Builder.prototype.url(val)Adds a value to the https://www.w3.org/ns/activitystreams#url property.
<Builder> as.models.Object.Builder.prototype.to(val)Adds a value to the https://www.w3.org/ns/activitystreams#to property.
<Builder> as.models.Object.Builder.prototype.bto(val)Adds a value to the https://www.w3.org/ns/activitystreams#bto property.
<Builder> as.models.Object.Builder.prototype.cc(val)Adds a value to the https://www.w3.org/ns/activitystreams#cc property.
<Builder> as.models.Object.Builder.prototype.bcc(val)Adds a value to the https://www.w3.org/ns/activitystreams#bcc property.
<Builder> as.models.Object.Builder.prototype.duration(val)Sets the value of the https://www.w3.org/ns/activitystreams#duration property.
The value is either a number of seconds or an ISO 8601 duration string
(e.g. 'PT1H30M').
as.models.Activity > as.models.ObjectBase class for all Activity Streams 2.0 Activity instances. Inherits from as.models.Object
as.models.Activity.prototype.actorReturns the value of the https://www.w3.org/ns/activitystreams#actor property. Will be either undefined or an Iterable of as.model.Base instances.
as.models.Activity.prototype.objectReturns the value of the https://www.w3.org/ns/activitystreams#object property. Will be either undefined or an Iterable of as.model.Base instances.
as.models.Activity.prototype.targetReturns the value of the https://www.w3.org/ns/activitystreams#target property. Will be either undefined or an Iterable of as.model.Base instances.
as.models.Activity.prototype.resultReturns the value of the https://www.w3.org/ns/activitystreams#result property. Will be either undefined or an Iterable of as.model.Base instances.
as.models.Activity.prototype.originReturns the value of the https://www.w3.org/ns/activitystreams#origin property. Will be either undefined or an Iterable of as.model.Base instances.
as.models.Activity.prototype.instrumentReturns the value of the https://www.w3.org/ns/activitystreams#instrument property. Will be either undefined or an Iterable of as.model.Base instances.
as.models.Activity.Builder > as.models.Object.BuilderThe base class for all as.models.Activity builder instances. Inherits from as.models.Object.Builder
<Builder> as.models.Activity.Builder.actor(val)Adds a value to the https://www.w3.org/ns/activitystreams#actor property.
<Builder> as.models.Activity.Builder.object(val)Adds a value to the https://www.w3.org/ns/activitystreams#object property.
<Builder> as.models.Activity.Builder.target(val)Adds a value to the https://www.w3.org/ns/activitystreams#target property.
<Builder> as.models.Activity.Builder.result(val)Adds a value to the https://www.w3.org/ns/activitystreams#result property.
<Builder> as.models.Activity.Builder.origin(val)Adds a value to the https://www.w3.org/ns/activitystreams#origin property.
<Builder> as.models.Activity.Builder.instrument(val)Adds a value to the https://www.w3.org/ns/activitystreams#instrument property.
as.models.Collection > as.models.ObjectThe base class for all Activity Streams 2.0 Collection objects. Inherits from as.models.Object
as.models.Collection.prototype.totalItemsReturns the value of the https://www.w3.org/ns/activitystreams#totalItems property. The value will either be undefined or a numeric integer greater than or equal to zero.
as.models.Collection.prototype.currentReturns the value of the https://www.w3.org/ns/activitystreams#current property. The value will either be undefined or a as.models.Base instance.
as.models.Collection.prototype.lastReturns the value of the https://www.w3.org/ns/activitystreams#last property. The value will either be undefined or a as.models.Base instance.
as.models.Collection.prototype.firstReturns the value of the https://www.w3.org/ns/activitystreams#first property. The value will either be undefined or a as.models.Base instance.
as.models.Collection.prototype.itemsReturns the value of the https://www.w3.org/ns/activitystreams#items property as an Iterable of as.models.Base instances.
as.models.Collection.Builder> as.models.Object.BuilderThe base class for all as.models.Collection builders. Inherits from as.models.Object.Builder
<Builder> as.models.Collection.Builder.prototype.totalItems(val)Sets the value of the https://www.w3.org/ns/activitystreams#totalItems property. The value must be a numeric integer greater than or equal to 0.
<Builder> as.models.Collection.Builder.current(val)Sets the value of the https://www.w3.org/ns/activitystreams#current property. The value must either be a URL string or a as.models.Link instance.
<Builder> as.models.Collection.Builder.last(val)Sets the value of the https://www.w3.org/ns/activitystreams#last property. The value must either be a URL string or a as.models.Link instance.
<Builder> as.models.Collection.Builder.first(val)Sets the value of the https://www.w3.org/ns/activitystreams#first property. The value must either be a URL string or a as.models.Link instance.
<Builder> as.models.Collection.Builder.items(val)Adds a value to the https://www.w3.org/ns/activitystreams#items property.
as.models.OrderedCollection > as.models.CollectionThe base class for all Activity Streams 2.0 OrderedCollection objects. Inherits from as.models.Collection
as.models.OrderedCollection.Builder > as.models.Collection.BuilderThe base class for all as.models.OrderedCollection builders. Inherits from as.models.Collection.Builder
as.models.CollectionPage > as.models.CollectionThe base class for all as.models.CollectionPage instances. Inherits from as.models.Collection
as.models.CollectionPage.prototype.nextReturns the value of the https://www.w3.org/ns/activitystreams#next property. The value will either be undefined or a as.models.Base instance.
as.models.CollectionPage.prototype.prevReturns the value of the https://www.w3.org/ns/activitystreams#prev property. The value will either be undefined or a as.models.Base instance.
as.models.CollectionPage.Builder > as.models.Collection.BuilderThe base class for all as.models.CollectionPage builders. Inherits from as.models.Collection.Builder
<Builder> as.models.CollectionPage.Builder.next(val)Sets the value of the https://www.w3.org/ns/activitystreams#next property. The value must either be a URL string or a as.models.Link instance.
<Builder> as.models.CollectionPage.Builder.prev(val)Sets the value of the https://www.w3.org/ns/activitystreams#prev property. The value must either be a URL string or a as.models.Link instance.
as.models.OrderedCollectionPage > as.models.CollectionPage, as.models.OrderedCollectionThe base class for all as.models.OrderedCollectionPage instances. Inherits from both as.models.CollectionPage and as.models.OrderedCollection
as.models.OrderedCollectionPage.prototype.startIndexReturns the value of the https://www.w3.org/ns/activitystreams#startIndex property. The value will either be undefined or a numeric integer greater than or equal to zero.
as.models.OrderedCollectionPage.Builder > as.models.CollectionPage.Builder, as.models.OrderedCollection.BuilderThe base class for all as.models.OrderedCollectionPage builders. Inherits from both as.models.CollectionPage.Builder and as.models.OrderedCollection.Builder.
as.models.OrderedCollectionPage.Builder.prototype.startIndex(val)Sets the value of the https://www.w3.org/ns/activitystreams#startIndex property. The value must be a numeric integer greater than or equal to zero.
as.models.Link > as.models.BaseThe base class for all Activity Streams 2.0 Links. Inherits from as.models.Base
as.models.Link.prototype.hrefReturns the value of the https://www.w3.org/ns/activitystreams#href property. The value will either be undefined or a URL string.
as.models.Link.prototype.relReturns the value of the https://www.w3.org/ns/activitystreams#rel property. The value will either be undefined or an Iterable of strings.
as.models.Link.prototype.mediaTypeReturns the value of the https://www.w3.org/ns/activitystreams#mediaType property. The value will either be undefined or a MIME Media Type.
as.models.Link.prototype.nameReturns the value of the https://www.w3.org/ns/activitystreams#name property as a LanguageValue.
as.models.Link.prototype.hreflangReturns the value of the https://www.w3.org/ns/activitystreams#hreflang property. The value will either be undefined or a BCP 47 Language Tag.
as.models.Link.prototype.heightReturns the value of the https://www.w3.org/ns/activitystreams#height property.The value will either be undefined or a numeric integer greater than or equal to zero.
as.models.Link.prototype.widthReturns the value of the https://www.w3.org/ns/activitystreams#width property.The value will either be undefined or a numeric integer greater than or equal to zero.
as.models.Link.Builder > as.models.Base.BuilderThe base class for all as.models.Link builders. Inherits from as.models.Base.Builder
<Builder> as.models.Link.Builder.prototype.href(val)Specifies the value of the https://www.w3.org/ns/activitystreams#href property. The value must be a URL string.
<Builder> as.models.Link.Builder.prototype.rel(val)Adds a value to the https://www.w3.org/ns/activitystreams#rel property;
<Builder> as.models.Link.Builder.prototype.mediaType(val)Sets the value of the https://www.w3.org/ns/activitystreams#mediaType property. The value must be a valid MIME type.
<Builder> as.models.Link.Builder.prototype.name(val)Specifies an optionally language-tagged name.
as.link()
.name('simple display name')
.get()as.link()
.name(
as.langmap()
.set('default display name')
.set('es', 'other display name')
)
.get()<Builder> as.models.Link.Builder.prototype.hreflang(val)Sets the value of the https://www.w3.org/ns/activitystreams#hreflang property.
The value must be a BCP 47 Language Tag.
<Builder> as.models.Link.Builder.prototype.height(val)Sets the value of the https://www.w3.org/ns/activitystreams#height property.
The value is a numeric integer greater than or equal to zero.
<Builder> as.models.Link.Builder.prototype.width(val)Sets the value of the https://www.w3.org/ns/activitystreams#width property.
The value is a numeric integer greater than or equal to zero.
as.models.Place > as.models.ObjectThe base class for all Activity Streams 2.0 Place objects. Inherits from as.models.Object
as.models.Place.prototype.accuracyReturns the value of the https://www.w3.org/ns/activitystreams#accuracy property. The value will either be undefined or a numeric integer in the range 0 <= n <= 100.
as.models.Place.prototype.altitudeReturns the value of the https://www.w3.org/ns/activitystreams#altitude property. The value will be either undefined or a numeric float.
as.models.Place.prototype.latitudeReturns the value of the https://www.w3.org/ns/activitystreams#latitude property. The value will be either undefined or a numeric float in the range -90.0 <= n <= 90.0.
as.models.Place.prototype.longitudeReturns the value of the https://www.w3.org/ns/activitystreams#longitude property. The value will be either undefined or a numeric float in the range -180.0 <= n <= 180.0.
as.models.Place.prototype.radiusReturns the value of the https://www.w3.org/ns/activitystreams#radius property.
The value will be either undefined or a numeric float greater than or equal to zero.
as.models.Place.prototype.unitsReturns the value of the https://www.w3.org/ns/activitystreams#units property. The value will be one of: cm, feet, inches, km, m, miles, or any absolute URI.
as.models.Place.Builder > as.models.Object.BuilderThe base class for all as.models.Place builders. Inherits from as.models.Object.Builder
as.models.Place.Builder.prototype.accuracy(val)Sets the value of the https://www.w3.org/ns/activitystreams#accuracy property.
The value is a numeric integer in the range 0 <= n <= 100
as.models.Place.Builder.prototype.altitude(val)Sets the value of the https://www.w3.org/ns/activitystreams#altitude property. The value is a numeric float.
as.models.Place.Builder.prototype.latitude(val)Sets the value of the https://www.w3.org/ns/activitystreams#latitude property. The value is a numeric float in the range -90.0 <= n <= 90.0.
as.models.Place.Builder.prototype.longitude(val)Sets the value of the https://www.w3.org/ns/activitystreams#longitude property. The value is a numeric float in the range -180.0 <= n <= 180.0.
as.models.Place.Builder.prototype.radius(val)Sets the value of the https://www.w3.org/ns/activitystreams#radius property. The value is a numeric float greater or equal to 0.0.
as.models.Place.Builder.prototype.units(val)Sets the value of the https://www.w3.org/ns/activitystreams#units property.
The value must be one of: cm, feet, inches, km, m, miles, or any absolute URI.
as.models.Profile > as.models.ObjectThe base class for all Activity Streams 2.0 Profile objects. Inherits from as.models.Object
as.models.Profile.prototype.describesas.models.Profile.Builder > as.models.Object.BuilderThe base class for all as.models.Profile builders. Inherits from
as.models.Object.Builder
as.models.Profile.Builder.prototype.describes(val)Sets the value of the https://www.w3.org/ns/activitystreams#describes property.
as.models.Question > as.models.ActivityThe base class for all Activity Streams 2.0 Question objects. Inherits from
as.models.Activity;
as.models.Question.prototype.anyOfReturns the value of the https://www.w3.org/ns/activitystreams#anyOf property.
The value will either be undefined or an Iterable of as.models.Base objects.
as.models.Question.prototype.oneOfReturns the value of the https://www.w3.org/ns/activitystreams#oneOf property.
The value will either be undefined or an Iterable of as.models.Base objects.
as.models.Question.Builder > as.models.Activity.BuilderThe base class for all as.models.Question builders. Inherits from
as.models.Activity.Builder;
as.models.Question.Builder.anyOf(val)Adds a value to the https://www.w3.org/ns/activitystreams#anyOf property.
as.models.Question.Builder.oneOf(val)Adds a value to the https://www.w3.org/ns/activitystreams#oneOf property.
as.models.Relationship > as.models.ObjectThe base class for all Activity Streams 2.0 Relationship objects. Inherits
from as.models.Object.
as.models.Relationship.prototype.subjectReturns the value of the https://www.w3.org/ns/activitystreams#subject property. The value will either be undefined or an as.models.Base object.
as.models.Relationship.prototype.relationshipReturns the value of the https://www.w3.org/ns/activitystreams#relationship property. The value will either be undefined or an Iterable of as.models.Base objects.
as.models.Relationship.prototype.objectReturns the value of the https://www.w3.org/ns/activitystreams#object property. The value will either be undefined or an Iterable of as.models.Base objects.
as.models.Relationship.Builder > as.models.Object.BuilderThe base class for all as.models.Relationship builders. Inherits from as.models.Object.Builder.
as.models.Relationship.Builder.prototype.subject(val)Sets the value of the http://ww.w3.org/ns/activitystreams#subject property.
as.models.Relationship.Builder.prototype.relationship(val)Adds a value to the https://www.w3.org/ns/activitystreams#relationship property.
as.models.Relationship.Builder.prototype.object(val)Adds a value to the https://www.w3.org/ns/activitystreams#object property.
as.models.Tombstone > as.models.Objectas.models.Tombstone.prototype.deletedReturns the date and time the object was deleted.
as.models.Tombstone.prototype.formerTypeReturns the former type of the object that was deleted.
as.models.Tombstone.Builder > as.models.Object.Builderas.models.Tombstone.Builder.prototype.deleted(val)Sets the date and time the represented object was deleted.
as.models.Tombstone.Builder.prototype.formerType(val)Specifies the former type of the object that was deleted.
LanguageValueUsed to encapsulate language tagged properties within an Activity Streams document.
// assuming the default system locale is `en-US`:
const obj = as.object()
.name(
as.langmap()
.set('default display name')
.set('es', 'other display name')
)
.get()
const languagevalue = obj.name
console.log(languagevalue.get()) // 'default display name'
console.log(languagevalue.get('es')) // 'other display name'// assuming the default system locale is `es`:
const obj = as.object()
.name(
as.langmap()
.set('default display name')
.set('es', 'other display name')
)
.get()
const languagevalue = obj.name
console.log(languagevalue.get()) // 'other display name'
console.log(languagevalue.get('en-US')) // 'default display name'Language tags are matched case-insensitively, using RFC 4647 lookup with a
prefix-match fallback (asking for en finds an en-US entry, and asking
for en-US-x-foo finds an en-US entry). The default language comes from
the LANG environment variable in Node.js, navigator.language in
browsers, and falls back to en-US.
^2.0.3
2.0.3
^3.4.1
3.4.1