the JSON-LD property to inspect
the property type
the JSON-LD property to inspect
the property type
Construct a property mapping for a known type and subtype.
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.
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
the subject to inspect
Generated using TypeDoc. Delivered by Vercel. @m-ld/m-ld - v0.10.0 Source code licensed MIT. Privacy policy
Runtime representation of the mapping between a Javascript class property and a runtime type.
value