Options
All
  • Public
  • Public/Protected
  • All
Menu

Runtime representation of the mapping between a Javascript class property and a runtime type.

see

value

Type parameters

  • T

  • S

Hierarchy

  • JsProperty

Index

Constructors

Properties

Utility Methods

Other Methods

Constructors

constructor

  • Parameters

    • name: string

      the JSON-LD property to inspect

    • type: JsType<T, S>

      the property type

    Returns JsProperty

Properties

Readonly name

name: string

the JSON-LD property to inspect

Readonly type

type: JsType<T, S>

the property type

Utility Methods

Static for

  • Construct a property mapping for a known type and subtype.

    see

    JsType#for

    Type parameters

    • T

    • S

    Parameters

    Returns JsProperty<T, S>

Other Methods

value

  • Extracts a property value from the given subject with the given Javascript type. This is a typesafe cast which will not perform type coercion e.g. strings to numbers.

    Per m-ld data semantics, a single value in a field is equivalent to a singleton set (see example), and will also cast successfully to a singleton array.

    Examples:

    new JsProperty('name', JsType.for(String)).value({ name: 'Fred' }); // => 'Fred'
    new JsProperty('name', JsType.for(Number)).value({ name: 'Fred' }); // => throws TypeError
    new JsProperty('name', JsType.for(Set, String)).value({ name: 'Fred' }); // => Set(['Fred'])
    new JsProperty('age', JsType.for(Set)).value({ name: 'Fred' }, 'age'); // => Set([])
    new JsProperty('shopping', JsType.for(Array, String)).value({
      shopping: { '@list': ['Bread', 'Milk'] }
    }); // => ['Bread', 'Milk']
    new JsProperty('birthday', JsType.for(Date)).value({
      birthday: {
        '@value': '2022-01-08T16:49:43.572Z',
        '@type': 'http://www.w3.org/2001/XMLSchema#dateTime'
      }
    }); // => Javascript Date
    
    throws

    TypeError if the given property does not have the correct type

    Parameters

    Returns ValueConstructed<T, S>

Legend

  • Constructor
  • Property
  • Method
  • Property
  • Method
  • Inherited property
  • Inherited method
  • Static property
  • Static method
  • Protected method

Generated using TypeDoc. Delivered by Vercel. @m-ld/m-ld - v0.10.1-edge.4 Source code licensed MIT. Privacy policy