2.1.0 • Published 2 years ago

@teamfabric/xpm v2.1.0

Weekly downloads
124
License
ISC
Repository
gitlab
Last release
2 years ago

lib-xpm

getEnrichedData

getEnrichedData function hydrates component's content (component data) by replacing template string with provided data. The output is hydrated/non-hydrated data.

For example, if we have a component with content that says "TODAY ONLY: {%= product.title %} IS 50% OFF!", it returns "TODAY ONLY: HAIRBRUSH IS 50% OFF!" by replacing {%= product.title %} with HAIRBRUSH.

Dependency

getEnrichData function uses npm package EJS to hydrate template string.

EJS: Documentation

Behaviors

Returns hydrated data if these conditions are satisfied

  • Data validation against schema passes
  • Component data contains template string
  • Data contains corresponding value to each template string

Returns component data as it is when

  • Provided component data doesn't contain template string

Throws error in these cases

  • Data validation against schema fails
  • Invalid component data (null | empty object) is provided

Usage Example

const { getEnrichedData } = require('@teamfabric/xpm')

/**
 * Hydrates component data and returns it.
 * @param {Object} componentData The component data possibly contains template string.
 * @param {Object} data The data to map template string.
 * @param {Object} schema The schema validates data type.
 * @returns {Object} Hydrated or none-hydrated component data
 */
const data = getEnrichedData({ componentData, data, schema })
2.0.1

2 years ago

2.1.0

2 years ago

1.5.2-alpha.5

2 years ago

1.5.2-alpha.4

2 years ago

1.5.2-alpha.3

2 years ago

1.5.2-alpha.2

2 years ago

1.5.2-alpha.1

2 years ago

1.5.2-alpha.0

2 years ago

1.5.2-beta.4

2 years ago

1.5.2-beta.3

2 years ago

1.5.2-beta.2

2 years ago

1.5.2-beta.1

2 years ago

2.0.0

2 years ago

1.5.0

2 years ago

1.5.1-beta.0

2 years ago

1.4.0-0

3 years ago

1.3.0-0

3 years ago

1.2.2

3 years ago

1.2.2-0

3 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.3-0

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.1-0

4 years ago

1.1.0

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago