Skip to content

Helpers and types

formatMoney(cents) Formats an amount with the store’s money format, such as £45.00
translate(key, variables) One of the cart’s own texts, in the shopper’s language
getVariantMetafield(line, namespace, key, fallback) A metafield of the line’s variant
getProductMetafield(line, namespace, key, fallback) A metafield of the line’s product

All four return straight away, not a promise.

NativeSlide.formatMoney(4500); // '£45.00'
NativeSlide.translate('general.cartTitle'); // the drawer's title

translate replaces {name} placeholders in the text with variables, such as translate(key, { amount: '£5.00' }). A count variable also picks the text’s plural form. A text missing in the shopper’s language comes from the store’s primary language, then English (Languages). If there’s no text for key, or the API isn’t ready yet, it returns key.

The metafield helpers take a line from NativeSlide.Cart.items and return fallback (null if you leave it out) when there’s no such metafield.

Type definitions come with every snippet release:

  • https://cdn.nativeslide.com/snippet/nativeslide.d.ts for the current release
  • https://cdn.nativeslide.com/snippet/types/1.1.0/nativeslide.d.ts for a given release

Save the file into your project and add it to your tsconfig.json. It types window.NativeSlide, window.NativeSlideQueue and the nativeslide: events on document. The types are under the NativeSlide namespace, such as NativeSlide.CartLine and NativeSlide.Result.