Chapter 21 of 22 Part V: Near-Field & Finding Networks

NFC: The Secret Power of a Tap

3 Verified Book Snippets

Every .js file below is byte-identical (SHA-256 verified) to the printed code in Volume 1. Runnable blocks execute inside an isolated sandboxed iframe and Web Worker with a 2-second timeout and zero network access.

Download Chapter ZIP

block-01.js

Printed book snippet (byte-identical) · 184 bytes · SHA-256: 04993973e806…
Standalone runnable

Dependencies: None (standard ES2022 JavaScript). Runs directly in Node.js or the isolated browser sandbox and logs output.

function coupling(d, alignment) {
  if (d < 0 || alignment < 0 || alignment > 1)
    throw Error("Invalid model input");
  return alignment / (1 + d * d);
}
console.log(coupling(2,1));
Download .js

block-02.js

Printed book snippet (byte-identical) · 165 bytes · SHA-256: 567dd8387ef3…
Standalone runnable

Dependencies: None (standard ES2022 JavaScript). Runs directly in Node.js or the isolated browser sandbox and logs output.

function fitsText(text, budget) {
  const bytes = new TextEncoder().encode(text).length;
  return {bytes, fits: bytes <= budget};
}
console.log(fitsText("Hello",8));
Download .js

block-03.js

Printed book snippet (byte-identical) · 339 bytes · SHA-256: dbfde6aa0465…
Standalone runnable

Dependencies: None (standard ES2022 JavaScript). Runs directly in Node.js or the isolated browser sandbox and logs output.

function classifyTap(value) {
  try {
    const u = new URL(value);
    return u.protocol === "https:" &&
      u.hostname === "museum.example" &&
      !u.username && !u.password && !u.port
      ? "Review known host" : "Do not open";
  } catch { return "Not a web address"; }
}
console.log(classifyTap("https://museum.example/exhibit"));
Download .js