Headless API
SDK reference
hydrogen
lib
points

lib/points

Variables

DEFAULT_POINTS_LABEL

const DEFAULT_POINTS_LABEL: "points" = 'points';

The defaultValue of every block's "Points label" input, so resolvePointsLabel compares against one value rather than a literal repeated per block. test/schema.test.ts pins every block's default to it — a block that drifts would silently stop reading the shop's own point name.


POINTS_LABEL_HELP

const POINTS_LABEL_HELP: "Leave it as it is to use your shop’s own point name from Joy, singular or plural to match the number." = 'Leave it as it is to use your shop’s own point name from Joy, singular or plural to match the number.';

Trailing sentence of every block's "Points label" help text. The rule below is invisible in Studio otherwise — a merchant who leaves the field alone is choosing the shop's own wording without being told so.

Functions

formatPointsNumber()

function formatPointsNumber(value, locale?): string;

A point count written the way the shopper's locale writes it — "1,500" in en, "1.500" in de.

locale is Hydrogen's, threaded down from the block's loader, which is the point: it is the SAME value server-side and client-side, so an SSR'd number and its hydrated re-render agree. Never call toLocaleString() with no argument here — the runtime default is the Oxygen worker's on the server and the shopper's browser setting on the client, i.e. a hydration mismatch by construction. A block whose loader surfaced no locale (Hydrogen exposes none) therefore keeps a fixed tag rather than falling through to that default.

Parameters

ParameterType
valuenumber
locale?string

Returns

string


resolvePointsLabel()

function resolvePointsLabel(
   count, 
   setting, 
   shopLabel?
): string;

The word to print after count — "1 point" / "2 points".

Two branches, and deliberately NO second Studio setting (eight blocks × two label inputs is worse than the problem it solves):

  • the merchant typed their own label ⇒ it is used verbatim for both counts. That is an explicit display choice ("stars", "crowns"), and inventing its plural would be guessing at grammar for a word we were handed, not told.
  • the label is still the schema default ⇒ the shop's own pointLabel.singular/.plural from /shop-config, picked by the number. Merchants already configure that pair in the Joy admin, so this is what JoyBlocks prints and what the Liquid theme block prints — that block has no label setting at all, which is why the Weaverse one must not grow a second.
  • no pair (the /shop-config call failed) ⇒ the setting, exactly as before.

Singular at ±1 matches the Joy backend's rule: a −1 spend is still one point, and 0 is plural.

Parameters

ParameterType
countnumber
settingstring
shopLabel?PointLabel | null

Returns

string