Core library modules for web extensions

NOTE
Adobe Experience Platform Launch has been rebranded as a suite of data collection technologies in Adobe Experience Platform. Several terminology changes have rolled out across the product documentation as a result. Please refer to the following document for a consolidated reference of the terminology changes.

This document provides a list of core library modules that you may use within your web extensions. You may access these modules using require('@adobe/{MODULE}'), where {MODULE} is the name of the core module want to use.

reactor-object-assign

reactor-object-assign mimics the native Object.assign method by copying properties from source objects to a target object.

var objectAssign = require('@adobe/reactor-object-assign');
var all = objectAssign({ a: 'a' }, { b: 'b' });

The reactor-cookie object is a utility for reading and writing cookies. See the js-cookie npm package for more information.

var cookie = require('@adobe/reactor-cookie');
cookie.set('foo', 'bar');
console.log(cookie.get('foo'));
cookie.remove('foo');

reactor-document

reactor-document represents the Document object. This can be beneficial when testing the module by allowing tests to inject a mock document object using utilities like inject-loader.

var document = require('@adobe/reactor-document');
console.log(document.location);

reactor-query-string

reactor-query-string is a utility for parsing and serializing query strings.

var queryString = require('@adobe/reactor-query-string');
var parsed = queryString.parse(location.search);
console.log(parsed.campaign);
var obj = {
  campaign: 'Campaign A'
};
var stringified = queryString.stringify(obj);

The utility has the following methods:

  • queryString.parse({STRING}): Parses a query string into an object. Leading ?, #, and & characters on the query string are ignored.
  • queryString.stringify({OBJECT}): Stringifies an object into a query string.

reactor-load-script

reactor-load-script is a function that loads a script when given a URL. A script tag will be created and placed within the head node of the document. A promise will be returned which you may use to determine when loading of the script succeeds or fails.

var loadScript = require('@adobe/reactor-load-script');
var url = 'http://code.jquery.com/jquery-3.1.1.js';
loadScript(url).then(function() {
  // Do something ...
})

reactor-promise

reactor-promise is a constructor that mimics the Promise API native in ECMAScript 6. If the native Promise API is available, it will be returned instead.

var Promise = require('@adobe/reactor-promise');
new Promise(function(resolve) {
  resolve();
}, function(err) {
  console.error(err);
});

reactor-window

reactor-window represents the Window object. This can be beneficial when testing the module by allowing tests to inject a mock Window object using utilities like inject-loader.

var window = require('@adobe/reactor-window');
console.log(window.document);
recommendation-more-help
12b4e4a9-5028-4d88-8ce6-64a580811743