StaffCoder
TypeScript
Vanilla TypeScriptTypeScript 7.0
6 modules · 24 challengesSign up
Module 5 · Modules & Code Organisation

Storefront Utilities Package

easyStructuring cohesive named-export modules with a thin entry—No data yet

Problem statement

A small storefront page renders one featured product card and a newsletter signup. Instead of a single entry file where every helper is inline and stitched together with globals, the formatting, validation, and DOM helpers must live in their own modules — importable and testable on their own — with a thin entry that wires them to the page using Vanilla TypeScript and standard DOM APIs.

Demo

The page, styles, product interface, and seeded product data are already scaffolded and wired. Only the three helper modules in src/js/ — format.ts, validate.ts, and dom.ts — and the entry wiring in script.ts are missing. Implement them so every test passes. Do not edit any other file.

What to implement

  • Show a featured product card that displays the seeded product's name.
  • Show the current price of the product formatted as dollars with two decimal places.
  • Show the savings versus the original price as a whole-number percentage badge next to the price.
  • Show a newsletter signup panel with an email field and a Subscribe button.
  • Keep the Subscribe button disabled until the email field holds a valid email address; enable it as soon as the value looks like an email, and disable it again if the value stops looking like one.
  • Leave the seeded product data unchanged.
  • Everything shown must come from the seeded product — nothing should be hardcoded.

More in Modules & Code Organisation

See the module
Storefront Config Module Write config.ts — DEFAULTS, UnknownConfigKeyError, getConfig, and the generically-typed getConfigValue<K>(key) — as the single seam between a raw window.__STOREFRONT_CONFIG__ object and every consumer. Defaults document absent keys, injected values (including false and "") win over defaults, the returned object is frozen, unknown keys throw the named error, and no consumer file references the raw global.—No data yeteasyAnalytics Chart LoaderImplement createChartLoader(importFn) and the default loadChart so a heavy chart module is only fetched via import('./chart') when the user clicks Load. The loader dedupes concurrent calls to a single in-flight promise, caches the resolved module for every future call, and does not cache failures so Retry starts clean. The entry never references ./chart statically.—No data yeteasyShared Storefront Bootstrap Write bootstrap.ts, homeEntry.ts, and productEntry.ts so nothing runs at import time. initBootstrap() runs its work exactly once no matter how many entries invoke it; each entry's init() writes only to its own view and registers only its own click listener; and any init() is safe to call multiple times without duplicating listeners or double-writing text. Idempotency lives in module-scope let flags; no file assigns to window.—No data yeteasy

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.