SFCC-Utils

SFCC-Utils cartridge is a set of utilities, which may be useful for a typical SFCC (Salesforce Commerce Cloud) project.

The provided utils completes SFCC API and simplifies a routine development tasks.

All the utils are covered by unit tests using Chai/Mocha.

How to use

  1. Add the "plugin_utils" cartridge to your project.
  2. If you would like to use dependency injection via SFCC "modules" shorthand, then also add the "modules" folder.
  3. Upload the updated code version on your SFCC instance.
  4. Inject required module using CommonJS require('*/cartridge/scripts/<UTIL_MODULE_NAME>') or require('sfcc-utils/<UTIL_MODULE_NAME>') if you're using dependency injection via SFCC "modules" shorthand.

List of utils

plugin_utils/cartridge/scripts/arrayUtils OR sfcc-utils/array

plugin_utils/cartridge/scripts/objectUtils OR sfcc-utils/object

plugin_utils/cartridge/scripts/webUtils OR sfcc-utils/web

plugin_utils/cartridge/scripts/iteratorUtils OR sfcc-utils/iterator

plugin_utils/cartridge/scripts/collectionUtils OR sfcc-utils/collection

Usage examples

const { unique } = require('*/cartridge/scripts/arrayUtils');

unique(['DE', 'BE', 'DE', 'CZ', 'NL', 'DK', 'NL', 'EE']);
// [ 'DE', 'BE', 'CZ', 'NL', 'DK', 'EE' ]
// Dependency injection via SFCC "modules" shorthand
const { isEqual } = require('sfcc-utils/object');

isEqual({id: 1, category: { name: 'Other'}}, {id: 1, category: { name: 'Other'}});
// true
// Dependency injection via SFCC "modules" shorthand
const { filter } = require('sfcc-utils/collection');

const czAddresses = filter(
  customer.addressBook.addresses,
  address => address.countryCode.value === 'CZ'
);