Skip to content

configure()

SaltyKeys.configure(options?: Partial<SaltyKeysConfig>): void
ParameterTypeDescription
optionsobjectAn object containing one or more configuration keys to override.
KeyTypeDefaultDescription
urlPatternRegExpCodePen pattern (see below)A regex with one capture group that extracts the project/pen identifier from the page URL.
cacheEnabledbooleantrueWhen true, the extracted pen ID is cached after the first call to getPenId() and reused on subsequent calls.
environmentstring'codepen'An arbitrary string identifier for the current environment. Currently informational only.

Default urlPattern:

/(?:codepen|cdpn)\.io\/[^/]+\/(?:pen|debug|fullpage|fullembedgrid)\/([^?#]+)/

This matches URLs in the forms:

  • https://codepen.io/username/pen/AbCdEf
  • https://codepen.io/username/debug/AbCdEf
  • https://cdpn.io/username/fullpage/AbCdEf (CodePen’s short domain, also used for embeds)

voidconfigure() mutates SaltyKeys.config in place.

// These are the defaults — no need to call configure() unless you're changing them.
SaltyKeys.config;
// → { urlPattern: /codepen.../, cacheEnabled: true, environment: 'codepen' }
SaltyKeys.configure({
urlPattern: /my-site\.com\/projects\/([^?#]+)/,
environment: 'custom',
});

Useful in development or testing when the page URL changes frequently:

SaltyKeys.configure({ cacheEnabled: false });

For full control, replace the method:

SaltyKeys.getPenId = function () {
// Return a value from your own logic
return document.getElementById('my-project-id').textContent.trim();
};
console.log(SaltyKeys.config);
// → { urlPattern: /.../, cacheEnabled: true, environment: 'codepen' }