StackpressGitHub

API reference

Attribute

Attribute represents one annotation from Idea source, such as @label(...), @id, @field.string, or @is.required(...).

Import

import { Attribute } from 'stackpress/schema';

Instantiation

Create an attribute with a name and either args or a boolean flag.

const label = new Attribute('label', [ 'Title' ]);
const id = new Attribute('id', true);

The first example is a method-style attribute with arguments. The second is a flag-style attribute.

Properties

PropertyTypeDescription
namestringAttribute name.
enabledbooleanWhether the attribute is enabled.
assertionAttributeAssertionAssertion helper.
componentAttributeComponentComponent helper.
referenceAttributeReferenceRelation/reference helper.
argsData[]Positional argument values.
isFlagbooleanTrue when the attribute was created as a flag.
isMethodbooleanTrue when the attribute has method-style args.
valueDataFirst argument value for method attributes.

Example

const attribute = column.attribute('label');

if (attribute?.isMethod) {
  console.log(attribute.value);
}

This example checks that the attribute has arguments before reading its first value. Flag attributes such as @id do not carry the same method-style value.