Module: microdata-exploder

Methods

(inner) extractPrimitiveTypeFromMicrodata(CONTEXT, rule, isNested) → {unknown}

Parameters:
Name Type Default Description
CONTEXT ParseContext
rule RecipeRule.itemprop
isNested boolean false

Extracts any primitive type from the given microdata. PrimitiveValueTypes

Source:
Returns:

Type: unknown

(async, inner) extractOrderedListTypeFromMicrodata(CONTEXT, rule, itemType, isNested) → {Array.<unknown>|undefined}

Parameters:
Name Type Default Description
CONTEXT ParseContext
rule RecipeRule
itemType StringValue | IntegerValue | NumberValue | BooleanValue | StringifiableValue | ReferenceToObjValue | ReferenceToIdValue | ReferenceToClobValue | ReferenceToBlobValue | MapValue | BagValue | ArrayValue | SetValue | ObjectValue
isNested boolean false

Extracts an ordered list from the given microdata.

Source:
Returns:

Type: Array.<unknown> | undefined

(async, inner) extractMapTypeFromMicrodata(CONTEXT, rule, valueType, isNested) → {Map.<unknown, unknown>}

Parameters:
Name Type Default Description
CONTEXT ParseContext
rule RecipeRule.itemprop
valueType MapValue
isNested boolean false

Extracts map object from the given microdata.

Source:
Returns:

Type: Map.<unknown, unknown>

(async, inner) extractUnorderedListTypeFromMicrodata(CONTEXT, rule, itemType, isNested) → {Array.<unknown>|undefined}

Parameters:
Name Type Default Description
CONTEXT ParseContext
rule RecipeRule
itemType StringValue | IntegerValue | NumberValue | BooleanValue | StringifiableValue | ReferenceToObjValue | ReferenceToIdValue | ReferenceToClobValue | ReferenceToBlobValue | MapValue | BagValue | ArrayValue | SetValue | ObjectValue
isNested boolean false

Extracts an unordered list from the given microdata.

Source:
Returns:

Type: Array.<unknown> | undefined

(async, inner) extracObjectTypeFromMicrodata(CONTEXT, rule, valueType) → {unknown}

Parameters:
Name Type Description
CONTEXT ParseContext
rule RecipeRule
valueType ObjectValue

Extracts an object from the given microdata.

Source:
Returns:

Type: unknown

(async, inner) parseMicrodataByTheExpectedType(valueType, rule, CONTEXT, isNested) → {unknown}

Parameters:
Name Type Default Description
valueType ValueType
rule RecipeRule
CONTEXT ParseContext
isNested boolean false
Source:
Returns:

Type: unknown

(async, static) explode(html, expectedTypeopt) → {Promise.<AnyObjectCreation>}

Parameters:
Name Type Attributes Description
html string

One object in HTML (MicroData) representation

expectedType OneObjectTypeNames | Array.<OneObjectTypeNames> <optional>

An optional expected type or an array of expected type names. If it is not matched by the microdata leads to an Error when attempting to parse the microdata. Leaving this parameter undefined or setting it to '*' disables the type check.

Convert the microdata representation of a ONE object to Javascript using the rules in object-recipes.js. An exception is thrown if there is a problem during the conversion.

Parsing has been optimized to go through the microdata string only once. That means we will proceed only forward and never look ahead, for example look for an end-tag and then go back to parse what is in between.

Another optimization is that the original HTML string is kept unaltered and no new strings containing parts of the original string are created. Instead, we keep track of the ever-advancing position that our parsing has reached. Each sub-function returns 1) its result and 2) the new position within the original string that has been reached successfully.

The only exception are - by necessity - the actual values gained from parsing the string. We have to use one of the high-level Javascript methods (here: String.prototype.slice) without knowing how it is implemented in the respective Javascript runtime (and version).

While V8 (and probably other JS engines too) have an internal optimized representation of sub-strings using pointers we don't want to rely on that. For some background see: http://mrale.ph/blog/2016/11/23/making-less-dart-faster.html

If there is any discrepancy between what we expect and what we find the respective function throws an exception immediately. This means the exception-free code path does not need any checks, if the code continues to run we know everything is fine.

Source:
Throws:
Error | Error
Returns:

Returns the result of storing the exploded object. All inner objects were stored separately and replaced by Reference objects.

Type: Promise.<AnyObjectCreation>