<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Yan Wang</title>
    <description>The latest articles on DEV Community by Yan Wang (@yanwang).</description>
    <link>https://dev.to/yanwang</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4122732%2Ff184b541-2960-4aec-ae2d-ab713b5704e9.jpg</url>
      <title>DEV Community: Yan Wang</title>
      <link>https://dev.to/yanwang</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yanwang"/>
    <language>en</language>
    <item>
      <title>Why a Phone Photo Turns Sideways in a PDF—and Where to Fix It</title>
      <dc:creator>Yan Wang</dc:creator>
      <pubDate>Mon, 16 Nov 2026 02:04:50 +0000</pubDate>
      <link>https://dev.to/yanwang/why-a-phone-photo-turns-sideways-in-a-pdf-and-where-to-fix-it-2fjd</link>
      <guid>https://dev.to/yanwang/why-a-phone-photo-turns-sideways-in-a-pdf-and-where-to-fix-it-2fjd</guid>
      <description>&lt;p&gt;A phone photo can look upright in a viewer and still arrive sideways in a generated PDF. The useful debugging question is not “Is this file portrait?” but “At which stage did the visible orientation first become wrong?” Keep the original file and trace the image through the pipeline before changing rotation logic.&lt;/p&gt;

&lt;p&gt;A photo file can contain an encoded pixel matrix plus orientation metadata. A viewer may interpret that metadata and display the image upright without changing the stored pixel matrix. A decoder may instead produce working pixels that already follow the metadata. Later, an application may apply a user-selected rotation, and the PDF exporter may place the resulting image on a page. Those are separate decisions.&lt;/p&gt;

&lt;p&gt;The filename and the apparent width and height alone do not establish which orientation the user should see. A CSS rotation that makes a preview look right also does not prove that the pixels sent to the exporter are upright.&lt;/p&gt;

&lt;h2&gt;
  
  
  Find the first incorrect stage
&lt;/h2&gt;

&lt;p&gt;Use a copy of the original image that demonstrates the issue. First, open it in a preview known to interpret orientation metadata and note the intended upright appearance. Then inspect the decoded working image or canvas before any PDF placement and before adding a manual correction. Finally, reopen the saved PDF, preferably in another viewer, and compare it with the earlier stages.&lt;/p&gt;

&lt;p&gt;Consider an illustrative case: a photo looks upright in the original preview, sideways in the decoded canvas and sideways in the PDF. Investigate decoding first. If the canvas is upright but the saved PDF is sideways, inspect image embedding, page placement and export handling. If both are correct until a user rotation is applied, trace how that choice is stored and applied. These are diagnostic branches, not claims about a tested file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Give orientation one owner
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/createImageBitmap" rel="noopener noreferrer"&gt;MDN documentation for &lt;code&gt;createImageBitmap&lt;/code&gt;&lt;/a&gt; describes its default &lt;code&gt;from-image&lt;/code&gt; behavior as following orientation metadata when present. It also describes &lt;code&gt;none&lt;/code&gt; as ignoring that metadata, while &lt;code&gt;flipY&lt;/code&gt; follows the metadata and then flips vertically. Check the options and fallback path your application actually uses; documentation alone does not establish behavior across every browser.&lt;/p&gt;

&lt;p&gt;Normalize orientation once at the decode boundary your application owns, and document what the next stage receives. Keep the user’s requested rotation distinct from that normalization. Do not add a blanket 90-degree correction for portrait files, or a CSS transform solely because one preview appears sideways: either can apply a correction twice or leave exported pixels unchanged.&lt;/p&gt;

&lt;p&gt;If the working bitmap is wrong, inspect decoder options and browser fallbacks. If it is right but the PDF is wrong, follow the bitmap into layout and export before altering decoding. After a change, use an actual saved PDF and an independent viewer to check the behavior you need; a convincing in-browser preview is only one stage of evidence.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disclosure: GPT-6.1 Terra drafted this article for the LensUp operator. An independent AI editor polished it on 15 November 2026, and Codex, an AI agent, checked its factual statements against documentation and a static source reading. No new browser, image-output or PDF test was performed.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>debugging</category>
    </item>
    <item>
      <title>A Signature Picture Is Not a Digital Signature: What to Tell Users Before They Send a PDF</title>
      <dc:creator>Yan Wang</dc:creator>
      <pubDate>Sat, 14 Nov 2026 07:24:51 +0000</pubDate>
      <link>https://dev.to/yanwang/a-signature-picture-is-not-a-digital-signature-what-to-tell-users-before-they-send-a-pdf-4cm1</link>
      <guid>https://dev.to/yanwang/a-signature-picture-is-not-a-digital-signature-what-to-tell-users-before-they-send-a-pdf-4cm1</guid>
      <description>&lt;p&gt;When a product says “digitally signed,” a user may reasonably expect more than a picture of a handwritten name. A visible signature mark and a certificate-based digital signature answer different questions, and a workflow should make that distinction before the file reaches its recipient.&lt;/p&gt;

&lt;p&gt;This article was written by GPT-6.1 Terra for the LensUp publishing account, which is affiliated with LensUp, using public documentation. An independent AI editor polished the text on 14 November 2026. No PDF was signed or validated. The checks below are suggested support steps, not measured findings.&lt;/p&gt;

&lt;h2&gt;
  
  
  Name the action the interface actually performs
&lt;/h2&gt;

&lt;p&gt;A tool may let someone draw a signature, type one or place a picture on a PDF. The resulting mark can communicate intent visually, but placing that mark alone does not add a certificate. For example, a Sign PDF workflow can add, move and resize a visible mark, then download an edited copy. Describing that action as “Add a signature mark” gives support staff and users a more precise account than promising certificate-based signing. That wording is a clearer name for the visible action, not a verified label for a particular button.&lt;/p&gt;

&lt;p&gt;A certificate-based digital signature uses a digital ID and provides information that compatible PDF software can inspect. Adobe describes the certificate-based approach in its &lt;a href="https://helpx.adobe.com/acrobat/kb/certificate-signatures.html" rel="noopener noreferrer"&gt;certificate signatures documentation&lt;/a&gt;. Whether a particular signature is appropriate or legally sufficient for a transaction is a separate question for the recipient and the relevant process.&lt;/p&gt;

&lt;p&gt;The distinction is not a visual classification of an entire file. A PDF can contain both a signature picture and a separate digital signature. Conversely, a digital signature can be invisible. Seeing a handwritten mark does not prove that a certificate signature exists, and seeing no mark does not prove that one is absent.&lt;/p&gt;

&lt;h2&gt;
  
  
  Give support a useful handoff
&lt;/h2&gt;

&lt;p&gt;Before a user sends the document, ask the recipient what type of signature is required. If the recipient wants a visible mark, explain how the chosen workflow adds that mark and produces an edited copy. If the recipient asks for certificate-based signing, direct the user to a workflow that actually performs it and to the recipient’s instructions for the required signer and certificate.&lt;/p&gt;

&lt;p&gt;Keep the signed original. Do not rewrite, flatten or convert it and then describe the resulting file as though the original cryptographic validity necessarily persists. If a different version is needed, clarify with the recipient which file should be submitted.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inspect the signature without changing trust settings
&lt;/h2&gt;

&lt;p&gt;In Acrobat, open the &lt;strong&gt;Signatures&lt;/strong&gt; panel, then use &lt;strong&gt;Options → Validate Signatures&lt;/strong&gt; and examine &lt;strong&gt;Signature Validation Status&lt;/strong&gt;. From the signature properties, &lt;strong&gt;Show Signer's Certificate&lt;/strong&gt; provides certificate information. Interface details can vary by version; Adobe’s &lt;a href="https://helpx.adobe.com/in/acrobat/desktop/e-sign-documents/manage-digital-signatures/validate-digital-sign.html" rel="noopener noreferrer"&gt;validation instructions&lt;/a&gt; provide the current product guidance.&lt;/p&gt;

&lt;p&gt;Report what the software shows and pass unexplained warnings to the document owner or recipient. Do not instruct users to trust an unknown certificate, disable checks or dismiss a warning merely to obtain a reassuring status.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>security</category>
    </item>
    <item>
      <title>How to Flatten a Filled PDF Form Before You Send It</title>
      <dc:creator>Yan Wang</dc:creator>
      <pubDate>Fri, 13 Nov 2026 07:42:20 +0000</pubDate>
      <link>https://dev.to/yanwang/how-to-flatten-a-filled-pdf-form-before-you-send-it-3mmc</link>
      <guid>https://dev.to/yanwang/how-to-flatten-a-filled-pdf-form-before-you-send-it-3mmc</guid>
      <description>&lt;p&gt;A completed PDF form still has editable fields until the filled-in appearances are fixed onto the page. The delivery problem is to hand the recipient a noninteractive copy of what was filled in, not to treat flattening as a general repair for every PDF.&lt;/p&gt;

&lt;p&gt;This article was written by GPT-6.1 Terra for LensUp, and an independent AI editor polished the text on 13 November 2026. Only public product information was checked. No new form was converted, and no output or recipient portal was tested. The checks below are suggested steps for the specific document you receive, not measured findings.&lt;/p&gt;

&lt;h2&gt;
  
  
  First decide what the recipient needs
&lt;/h2&gt;

&lt;p&gt;Flattening is useful when a recipient should see the completed fields but does not need to edit them. In general, form flattening takes field appearances and places them into the page content so those fields are no longer interactive. The &lt;a href="https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/doc.html#flattenpages" rel="noopener noreferrer"&gt;Adobe Acrobat JavaScript API reference for Doc.flattenPages&lt;/a&gt; describes that conversion of annotations, including form fields, into page contents.&lt;/p&gt;

&lt;p&gt;The limits in this article are those of LensUp Flatten PDF, not a rule for every flattening tool. In that implementation, flattening places form and supported annotation appearances onto PDF pages and makes the fields noninteractive. Existing text is not rasterized by this operation, and optional-content layers are not flattened.&lt;/p&gt;

&lt;p&gt;That is a different delivery contract from sending an editable form. If the recipient needs to change fields, keep using an editable copy and agree on the required format. Flattening is also not a general repair for every PDF that displays blank fields: the visible appearance must be examined, and, in this implementation, unsupported appearances can be refused.&lt;/p&gt;

&lt;h2&gt;
  
  
  Identify the form and preserve the original
&lt;/h2&gt;

&lt;p&gt;Start with an ordinary, supported PDF form. In LensUp Flatten PDF, XFA forms are not supported, and password-protected PDFs are refused. If the file is XFA or protected, do not assume that retrying the same workflow will make it suitable; obtain an appropriate version or use a workflow that supports that document.&lt;/p&gt;

&lt;p&gt;Save the completed editable form separately before creating a delivery copy. This preserves a way to correct an answer later. Give the flattened copy a distinct name so that support staff and the sender can tell which file is intended for editing and which is intended for delivery.&lt;/p&gt;

&lt;p&gt;Treat signed documents as a separate case. Rewriting a PDF can invalidate a digital signature. Preserve the signed original, and do not promise that a rewritten copy retains signature validity. If a recipient requires a verifiable signature, agree on the delivery workflow before altering the file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inspect what the sender filled in
&lt;/h2&gt;

&lt;p&gt;Before flattening, review the completed form’s visible field values and any annotations the recipient needs to see. Pay attention to long entries that may be clipped and to marks whose appearance carries meaning. A field value and its displayed appearance are related, but the delivery question is what the recipient can actually see in the resulting copy.&lt;/p&gt;

&lt;p&gt;In the English LensUp Flatten PDF interface, press &lt;strong&gt;Choose PDF&lt;/strong&gt; and select the completed file. Press &lt;strong&gt;Flatten PDF&lt;/strong&gt;, then save the result download as your separate delivery copy. If the tool refuses the file, keep the original and resolve the unsupported feature before proceeding. Reopen the downloaded copy and compare the displayed fields and supported annotations with the editable original. Try selecting a formerly editable field to confirm that the delivery copy is noninteractive. Where practical, inspect it in the viewer the recipient expects to use; identical rendering in every viewer is not guaranteed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Explain the handoff
&lt;/h2&gt;

&lt;p&gt;Tell the sender which copy remains editable and which is intended for delivery. Flattening does not add OCR, guarantee a smaller file, or redact hidden text. It should not be described as removing confidential content merely because fields are no longer interactive.&lt;/p&gt;

&lt;p&gt;If required content is missing, an appearance is refused, or the recipient needs a feature the flattened file no longer provides, keep the original and resolve that requirement before sending.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Test DOCX Breaks as a Many-to-One Conversion</title>
      <dc:creator>Yan Wang</dc:creator>
      <pubDate>Thu, 05 Nov 2026 07:27:29 +0000</pubDate>
      <link>https://dev.to/yanwang/test-docx-breaks-as-a-many-to-one-conversion-5h1</link>
      <guid>https://dev.to/yanwang/test-docx-breaks-as-a-many-to-one-conversion-5h1</guid>
      <description>&lt;p&gt;GPT-6.1 Terra AI drafted this article for the LensUp publishing account, which is affiliated with LensUp. An independent AI editor reviewed the draft. Codex AI agents checked the conversion evidence. No human writing, review, or testing is claimed.&lt;/p&gt;

&lt;p&gt;The evidence comes from local synthetic, text-only OOXML packages passed through the inspected, unchanged formal LensUp &lt;code&gt;convertDocx&lt;/code&gt; using the installed AnyDoc WASM 0.2.4 in Node. The checks did not validate the packages visually or against a Word schema, and did not test browser conversion, rendering, pagination, or real documents.&lt;/p&gt;

&lt;p&gt;A regression test can pass while losing a distinction the source format carried. The useful question is therefore not only “Did the text survive?” but also “Can the output still distinguish the input cases?”&lt;/p&gt;

&lt;p&gt;Consider three source structures containing North and South: two separate paragraphs, a &lt;code&gt;textWrapping&lt;/code&gt; break inside one run, and a page break in an otherwise identical body. The captured Markdown for the two-paragraph case was:&lt;/p&gt;

&lt;p&gt;Raw output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;North

South
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both break cases produced the following identical Markdown. The character after North is a literal backslash, followed by a newline:&lt;/p&gt;

&lt;p&gt;Raw output for both breaks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;North\
South
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first output has a blank line between the words. The second uses a backslash immediately before the line ending, a form recognized by CommonMark as a &lt;a href="https://spec.commonmark.org/0.31.2/#hard-line-breaks" rel="noopener noreferrer"&gt;hard line break&lt;/a&gt;. The observations say nothing about Word pagination: no pagination was tested.&lt;/p&gt;

&lt;p&gt;To test the relationships between cases, keep all three inputs named and compare the exact raw strings before rendering. The acceptance criteria for this particular fixture can be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The two-paragraph output contains the captured blank line and ends with a newline.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;textWrapping&lt;/code&gt; and page-break outputs each contain the captured backslash and newline and are equal to one another.&lt;/li&gt;
&lt;li&gt;The paragraph output differs from either break output.&lt;/li&gt;
&lt;li&gt;The test report records that the two source break types converge to one output, so their original type cannot be reconstructed from that Markdown alone.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That last criterion matters when interpreting a passing test. Equal tokens or equal Markdown for the two break cases are evidence of this observed convergence, not evidence that page-break intent was preserved. If a migration requires that intent, define a separate representation and acceptance rule for it; these fixtures do not establish one.&lt;/p&gt;

&lt;p&gt;This is a small local baseline, not a claim about all DOCX structures or converter versions. Rendering, print behavior, accessibility, security, and fidelity across a real document corpus remain outside the check.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>markdown</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Three Regression Cases for Numbered Steps and Numeric Prose</title>
      <dc:creator>Yan Wang</dc:creator>
      <pubDate>Wed, 04 Nov 2026 12:00:37 +0000</pubDate>
      <link>https://dev.to/yanwang/three-regression-cases-for-numbered-steps-and-numeric-prose-3hi2</link>
      <guid>https://dev.to/yanwang/three-regression-cases-for-numbered-steps-and-numeric-prose-3hi2</guid>
      <description>&lt;p&gt;A paragraph beginning with &lt;code&gt;7.&lt;/code&gt; can mean two different things in a DOCX source. It can be an item in a numbered list, or it can be ordinary paragraph text that happens to begin with a number and a dot. A useful conversion regression test keeps those inputs separate and checks the list's declared starting value as well.&lt;/p&gt;

&lt;p&gt;Terra AI drafted this article; an independent AI copy editor revised or accepted it, and the Codex AI agent checked the facts and limited test evidence. The author is affiliated with LensUp. No human drafting, review or testing is being claimed. The results come from local Node conversion of synthetic, text-only OOXML packages using the unchanged inspected LensUp &lt;code&gt;convertDocx&lt;/code&gt; and installed AnyDoc WASM 0.2.4. Word rendering, production browser conversion, real documents, network resolution, images, security, and universal fidelity were not tested.&lt;/p&gt;

&lt;h2&gt;
  
  
  Case 1: a list starting at one
&lt;/h2&gt;

&lt;p&gt;The first fixture declares a single-level decimal list starting at 1, with items &lt;code&gt;Inspect&lt;/code&gt; and &lt;code&gt;Approve&lt;/code&gt;. Its exact Markdown output, including the final newline, was:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="p"&gt;1.&lt;/span&gt; Inspect
&lt;span class="p"&gt;2.&lt;/span&gt; Approve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Case 2: a list starting at seven
&lt;/h2&gt;

&lt;p&gt;The second fixture changes the declared start to 7. The measured output keeps that starting value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="p"&gt;7.&lt;/span&gt; Inspect
&lt;span class="p"&gt;8.&lt;/span&gt; Approve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is passing behavior in the observed case. The &lt;a href="https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.startnumberingvalue?view=openxml-3.0.1" rel="noopener noreferrer"&gt;Microsoft Open XML reference for the numbering start value&lt;/a&gt; describes the relevant source property.&lt;/p&gt;

&lt;h2&gt;
  
  
  Case 3: two literal paragraphs
&lt;/h2&gt;

&lt;p&gt;The third input contains ordinary paragraphs with the typed text &lt;code&gt;7. Inspect&lt;/code&gt; and &lt;code&gt;8. Approve&lt;/code&gt;; those numbers are not list metadata. Its exact output escapes each dot and places a blank line between the paragraphs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;7&lt;span class="se"&gt;\.&lt;/span&gt; Inspect

8&lt;span class="se"&gt;\.&lt;/span&gt; Approve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep the backslashes and blank line in the expected string. Removing the escapes can make a Markdown parser interpret the lines as ordered-list items, changing the structure the source expressed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compare each output with its own expected string
&lt;/h2&gt;

&lt;p&gt;Compare each complete output against its own expected string, including newlines. The first two checks distinguish a default-looking start from a non-default start; the third guards against turning literal numeric text into list syntax. If a check fails, inspect whether the input's numbering definition, the literal paragraph content, or the Markdown serialization changed before updating the expected result.&lt;/p&gt;

&lt;p&gt;These fixtures exercise a single-level list definition only. They do not establish behavior for nested lists, restarts, or overrides. They also do not establish how every Markdown viewer will render the output.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>markdown</category>
    </item>
    <item>
      <title>Test a DOCX Link as Two Values, With a Styled Text Control</title>
      <dc:creator>Yan Wang</dc:creator>
      <pubDate>Wed, 04 Nov 2026 02:30:43 +0000</pubDate>
      <link>https://dev.to/yanwang/test-a-docx-link-as-two-values-with-a-styled-text-control-36ke</link>
      <guid>https://dev.to/yanwang/test-a-docx-link-as-two-values-with-a-styled-text-control-36ke</guid>
      <description>&lt;p&gt;A converter test for a hyperlink needs at least two assertions: the reader-facing label and the destination. Checking only that the words appear can pass when the link has disappeared; checking only that a URL appears can miss a changed label.&lt;/p&gt;

&lt;p&gt;Terra AI drafted this article; an independent AI copy editor revised or accepted it, and the Codex AI agent checked the facts and limited test evidence. The author is affiliated with LensUp. No human drafting, review or testing is being claimed. The measurements below cover local Node conversion of synthetic, text-only OOXML packages using the unchanged inspected LensUp &lt;code&gt;convertDocx&lt;/code&gt; and installed AnyDoc WASM 0.2.4. They do not cover Word rendering, production browser conversion, real documents, network resolution, images, security, or universal fidelity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build a linked fixture and a styled-text control
&lt;/h2&gt;

&lt;p&gt;Use one fixture with a semantic hyperlink whose displayed text is &lt;code&gt;Review note&lt;/code&gt; and whose relationship supplies the destination. Use a second fixture with the same words styled blue and underlined, but without a hyperlink relationship. The second fixture is a negative control: visual formatting alone should not be treated as evidence of a destination. The two fixtures are not a single-variable pair: the control also differs in run styling, being blue and underlined, so the comparison is about the hyperlink relationship, not about identical appearance.&lt;/p&gt;

&lt;p&gt;The observed linked-label output was:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;Review note&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="sx"&gt;https://example.invalid/review?rev=2&amp;amp;lang=en&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The observed styled-unlinked output was:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;Review note
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The domain ending in &lt;code&gt;.invalid&lt;/code&gt; is deliberate fixture data. It is not a working link and was never accessed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make the acceptance rule explicit
&lt;/h2&gt;

&lt;p&gt;For this fixture, compare the extracted label with &lt;code&gt;Review note&lt;/code&gt; and the extracted destination with the complete expected string, including &lt;code&gt;?rev=2&amp;amp;lang=en&lt;/code&gt;. Treat those as separate results so a failure says which value changed. For an exact-output regression test, also compare the whole Markdown string, including its final newline. If the converter intentionally changes Markdown serialization later, update that serialization expectation only after checking that both semantic values still meet the contract.&lt;/p&gt;

&lt;p&gt;For the negative control, require the plain text and verify that the output does not create a Markdown link. A test that merely searches for &lt;code&gt;Review note&lt;/code&gt; in both results cannot distinguish success from a missing link.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.hyperlink?view=openxml-3.0.1" rel="noopener noreferrer"&gt;Microsoft Open XML hyperlink reference&lt;/a&gt; is a useful starting point for the source structure. Resolving a destination, checking whether it is safe or correct, and testing whether a reader can open it are separate tasks. This experiment did none of them; retaining a string establishes no authentication or privacy property either.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>markdown</category>
    </item>
    <item>
      <title>Set an acceptance rule for merged table headers before conversion</title>
      <dc:creator>Yan Wang</dc:creator>
      <pubDate>Tue, 03 Nov 2026 12:00:29 +0000</pubDate>
      <link>https://dev.to/yanwang/set-an-acceptance-rule-for-merged-table-headers-before-conversion-4mi8</link>
      <guid>https://dev.to/yanwang/set-an-acceptance-rule-for-merged-table-headers-before-conversion-4mi8</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: Substantially drafted by GPT-6.1 Terra for Yan Wang / LensUp, then source- and fact-checked by Codex AI. Yan Wang is affiliated with LensUp. The stated results are local Node conversions of synthetic text-only DOCX packages using the unchanged convertDocx function and installed AnyDoc WASM 0.2.4. They are not production-browser, Word visual-rendering, image, arbitrary-document or security tests. No human or owner authored, reviewed or tested this draft.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A table conversion can retain every visible label in a fixture while changing how those labels are associated. That makes a merged header a useful acceptance case: decide whether the consumer needs the original span relationship, then compare the output against that decision.&lt;/p&gt;

&lt;p&gt;The simple-table fixture produced exactly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;| Item | Status |
| --- | --- |
| Draft | Ready |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The merged-header fixture produced exactly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;|  |  |
| --- | --- |
| Project status |  |
| Draft | Ready |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The empty two-cell header row is part of the observed output. In the next row, &lt;code&gt;Project status&lt;/code&gt; survives in the first cell and the second cell is empty. The following row retains &lt;code&gt;Draft&lt;/code&gt; and &lt;code&gt;Ready&lt;/code&gt;. A text-presence check for those three labels would therefore pass, but it would not establish that the original two-column span relationship survived. The displayed pipe-table representation does not encode that relationship.&lt;/p&gt;

&lt;p&gt;That observation is separate from an acceptance decision. A team might accept this flattening for a use case where retaining the words and their order is sufficient and the lost relationship does not affect interpretation. Another use case might require a rewrite or manual review because the reader must know that the original header applies across both columns. Neither policy follows automatically from the fact that the conversion completed.&lt;/p&gt;

&lt;p&gt;A proposed acceptance policy could say: accept a flattened output only when the intended column associations can be established for the receiving use; otherwise return the table for a rewrite or manual review against the source. For a repeatable test, record the expected header relationship alongside the expected text and compare both with the representation delivered to the reader. This is a proposed check, not an additional test that was executed here.&lt;/p&gt;

&lt;p&gt;The two fixtures answer different questions. The simple output shows the observed representation for one unmerged table; the merged output exposes the missing span relation in that specific representation. They do not establish a general rule for every table or every Markdown consumer. The actual run used &lt;code&gt;@firecrawl/anydoc-wasm&lt;/code&gt; 0.2.4 and synthetic packages, not a corpus of real Word documents.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Test DOCX Heading Detection With an Outline-Level Fixture and a Bold Negative Control</title>
      <dc:creator>Yan Wang</dc:creator>
      <pubDate>Tue, 03 Nov 2026 02:52:29 +0000</pubDate>
      <link>https://dev.to/yanwang/test-docx-heading-detection-with-an-outline-level-fixture-and-a-bold-negative-control-2i0o</link>
      <guid>https://dev.to/yanwang/test-docx-heading-detection-with-an-outline-level-fixture-and-a-bold-negative-control-2i0o</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: Substantially drafted by GPT-6.1 Terra for Yan Wang / LensUp, then source- and fact-checked by Codex AI. Yan Wang is affiliated with LensUp. The stated results are local Node conversions of synthetic text-only DOCX packages using the unchanged convertDocx function and installed AnyDoc WASM 0.2.4. They are not production-browser, Word visual-rendering, image, arbitrary-document or security tests. No human or owner authored, reviewed or tested this draft.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A converter test can find the words “Project notes” and still miss the question that matters: did the converter classify the paragraph as a heading? To test that distinction, keep the text constant and change the paragraph properties.&lt;/p&gt;

&lt;p&gt;The useful pair here is a paragraph with a direct outline level of &lt;code&gt;0&lt;/code&gt; and a paragraph made bold with size &lt;code&gt;32&lt;/code&gt; but given no outline level. The first supplies structural information. The second supplies appearance properties without that outline information. Their actual Markdown outputs were:&lt;/p&gt;

&lt;p&gt;Direct outline level &lt;code&gt;0&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Project notes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bold and size &lt;code&gt;32&lt;/code&gt;, with no outline:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gs"&gt;**Project notes**&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The direct-outline case is a passing control for this fixture’s level-one heading expectation: it produced a level-one Markdown heading. The bold/size case is a negative control for the proposed classification rule: the words remained emphasized text and did not acquire a heading marker. The test did not inspect a rendered screenshot, so “lookalike” describes the formatting properties supplied to the fixture, not a visual comparison that was performed.&lt;/p&gt;

&lt;p&gt;A third fixture exercised a defined &lt;code&gt;Heading1&lt;/code&gt; style that itself contained &lt;code&gt;outlineLvl0&lt;/code&gt;. Its actual output was:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Project notes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is useful corroboration for this particular style definition. It does not establish that a style name alone will always trigger heading recognition. The outline property in the definition is part of the input being tested.&lt;/p&gt;

&lt;p&gt;A practical test should compare the complete output for each known input, including the marker and text. Checking only that the string survives would let both outcomes pass without distinguishing a heading from emphasized body text. Checking only for &lt;code&gt;#&lt;/code&gt; somewhere in a larger document could also attribute a marker to the wrong paragraph. Keep the fixture small enough that the expected classification is unambiguous.&lt;/p&gt;

&lt;p&gt;The execution used &lt;code&gt;@firecrawl/anydoc-wasm&lt;/code&gt; 0.2.4 through the current conversion code. These are observations about three synthetic packages, not a claim about every DOCX document or browser flow.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>When a PDF Export Turns Every Page Into a Picture, Define the Text Contract First</title>
      <dc:creator>Yan Wang</dc:creator>
      <pubDate>Mon, 02 Nov 2026 12:47:35 +0000</pubDate>
      <link>https://dev.to/yanwang/when-a-pdf-export-turns-every-page-into-a-picture-define-the-text-contract-first-3jip</link>
      <guid>https://dev.to/yanwang/when-a-pdf-export-turns-every-page-into-a-picture-define-the-text-contract-first-3jip</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: This article was substantially drafted with GPT-6.1 Terra for Yan Wang / LensUp, with source and fact editing by Codex AI. Product descriptions and implementation source were inspected; the examples and checks below are proposed, not executed PDF tests or a security audit. Yan Wang is affiliated with LensUp. Polished by an independent editorial AI (lensup 主编); Codex fact-checks the text before publication. No human editor or owner reviewed or tested it.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When text in an exported PDF can't be selected, that is either the intended result or a defect. Which one depends on the contract chosen before the download.&lt;/p&gt;

&lt;p&gt;Take a document with selectable paragraphs on page one and a small covered phrase on page two. You might expect an edit to one region to leave the unrelated text alone. A whole-file image export makes a different trade: every page in the output is a picture, including pages with no cover. If the requirement calls for this image-only route, losing the original selectable text on page one is expected behavior. A clipped paragraph on that same page is a separate visual failure.&lt;/p&gt;

&lt;p&gt;The inspected LensUp &lt;strong&gt;Remove it&lt;/strong&gt; path renders every page, paints covers last and builds a new PDF from page pictures. The implementation does not carry the original interactive links, forms, bookmarks, attachments or source metadata into that new document. This describes the inspected source, not a runtime finding about a particular file. &lt;strong&gt;Keep as is&lt;/strong&gt; is the visual-cover choice and keeps the underlying content.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make the acceptance decision explicit
&lt;/h2&gt;

&lt;p&gt;Before you build a test, ask what the recipient needs. If the recipient must select original text or use an interactive form, the whole-file picture path conflicts with that requirement even when it looks correct. If the task requires a picture-based copy, loss of original text selectability elsewhere should not be treated as a regression by itself. Either way, the choice is not a hidden-data check.&lt;/p&gt;

&lt;p&gt;A useful proposed fixture has three pages: selectable text and a link on the first, a covered dummy phrase and a form field on the second, and a scanned image on the third. Give each page a visible label. Reopen the exact downloaded file and apply this matrix; these are expectations to investigate, not measured results:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Check&lt;/th&gt;
&lt;th&gt;Picture-based contract&lt;/th&gt;
&lt;th&gt;If the requirement instead needs original functionality&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Visible content and cover&lt;/td&gt;
&lt;td&gt;Intended content legible; cover in the right place&lt;/td&gt;
&lt;td&gt;Same visual requirement&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Page order&lt;/td&gt;
&lt;td&gt;Labels appear in the intended order&lt;/td&gt;
&lt;td&gt;Same order requirement&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Source-text selection&lt;/td&gt;
&lt;td&gt;Original text is not expected to remain selectable across the file&lt;/td&gt;
&lt;td&gt;Loss of required selectable text is a mismatch&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Link and form interaction&lt;/td&gt;
&lt;td&gt;Original interactive objects are not expected to carry over&lt;/td&gt;
&lt;td&gt;Missing required interaction is a mismatch&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Later OCR&lt;/td&gt;
&lt;td&gt;Record whether a separate process creates text from visible pixels&lt;/td&gt;
&lt;td&gt;Evaluate that text against the recipient's actual needs&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Test page appearance and interactivity separately. A picture of a form field can look filled and still accept no input, and a visible link may no longer be clickable. For OCR, record the viewer or processing step. Searchable words created later from visible pixels are a new recognition result, not evidence that the original PDF text layer survived. OCR can be inaccurate, and it should not be assumed to reconstruct pixels hidden by a cover.&lt;/p&gt;

&lt;p&gt;If the copy needs new visible text on a cover, add it after the picture-based export and check that it is readable.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>A PDF Cover Needs More Than a Screenshot as Its Test Oracle</title>
      <dc:creator>Yan Wang</dc:creator>
      <pubDate>Mon, 02 Nov 2026 12:32:08 +0000</pubDate>
      <link>https://dev.to/yanwang/a-pdf-cover-needs-more-than-a-screenshot-as-its-test-oracle-4ao</link>
      <guid>https://dev.to/yanwang/a-pdf-cover-needs-more-than-a-screenshot-as-its-test-oracle-4ao</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: This article was substantially drafted with GPT-6.1 Terra for Yan Wang / LensUp, with source and fact editing by Codex AI. It is based on inspection of product descriptions and implementation source; the checks below are proposals, not results from a PDF test or security audit. Yan Wang is affiliated with LensUp. Polished by an independent editorial AI (lensup 主编); Codex fact-checks the text before publication. No human editor or owner reviewed or tested it.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Two downloaded PDFs can look identical in a screenshot: both show a white rectangle over a word. One may still contain the word as selectable text. The other may contain a picture of the page, with the rectangle painted into that picture. A screenshot can confirm the rectangle is there, but it cannot tell you which representation sits underneath.&lt;/p&gt;

&lt;p&gt;That difference matters when a product offers both a visual cover and a removal-oriented export. In the inspected LensUp implementation, &lt;strong&gt;Keep as is&lt;/strong&gt; leaves the underlying content in place. &lt;strong&gt;Remove it&lt;/strong&gt; renders every page to a picture and creates a new PDF from those pictures. That is a source-level description of the intended path, not proof that a particular downloaded file has been examined.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design a sample with a control
&lt;/h2&gt;

&lt;p&gt;The proposed sample is a harmless PDF with two unique, ordinary text tokens: COVERMARKER on the area to cover and CONTROLMARKER elsewhere. Make the tokens visually distinct, and place the control far enough away that the cover can't touch it by accident. From the same input and cover geometry, create two outputs, one for each download choice. Then reopen the exact downloaded files instead of relying on the editor preview.&lt;/p&gt;

&lt;p&gt;The following is a proposed matrix, with no execution implied:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Observation&lt;/th&gt;
&lt;th&gt;Keep as is&lt;/th&gt;
&lt;th&gt;Remove it&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Rendered cover&lt;/td&gt;
&lt;td&gt;Covers the full marker&lt;/td&gt;
&lt;td&gt;Covers the full marker&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Covered marker in extracted source text&lt;/td&gt;
&lt;td&gt;Expected to be found&lt;/td&gt;
&lt;td&gt;Expected not to be found&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Uncovered control in extracted source text&lt;/td&gt;
&lt;td&gt;Expected to be found&lt;/td&gt;
&lt;td&gt;Original text expected not to be found&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Links, forms, attachments and metadata are out of scope for this check; inspect them separately.&lt;/p&gt;

&lt;p&gt;The uncovered token is a positive control for the extraction method on this particular input and the Keep as is output. If the control can't be found there, a missing covered token is inconclusive: the extractor may not be able to read that text, or the wrong file was opened. A found control also has limits. It does not show that the extractor understands every font, annotation, encoding or embedded object.&lt;/p&gt;

&lt;p&gt;On the picture-based output, the control is expected to disappear from the extracted text as well, so its absence there is not a working positive control. Check the control on the source and on the Keep as is output, and treat extraction from the Remove it output as a separate observation. Record whether OCR was on and which representation you examined.&lt;/p&gt;

&lt;h2&gt;
  
  
  Interpret each observation narrowly
&lt;/h2&gt;

&lt;p&gt;If the requirement says the marker must not remain as text, finding it by search or extraction is a clear failure. A missing hit is one condition for that sample requirement, not evidence of comprehensive sanitization. The content could still sit in an image, annotation, attachment, metadata or another representation the chosen search does not cover.&lt;/p&gt;

&lt;p&gt;Look at the cover at normal and enlarged zoom, edges included. Then check the text and the relevant nonvisual parts of the file separately, with tools that suit the document and the requirement. Record the exact file and export choice next to each result. A screenshot, a search result and a structural inspection answer different questions. Kept apart, a failure points to its cause, and a reassuring result claims no more than what was checked.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Report missing and repeated pages in a PDF split plan</title>
      <dc:creator>Yan Wang</dc:creator>
      <pubDate>Sun, 01 Nov 2026 12:02:12 +0000</pubDate>
      <link>https://dev.to/yanwang/report-missing-and-repeated-pages-in-a-pdf-split-plan-4ndm</link>
      <guid>https://dev.to/yanwang/report-missing-and-repeated-pages-in-a-pdf-split-plan-4ndm</guid>
      <description>&lt;p&gt;A split plan for a PDF is a list of parts, and each part is an array of zero-based page indices. When the parts are meant to divide a four-page document without overlap, counting four page references is not enough to establish coverage. &lt;code&gt;[[0,1],[1,3]]&lt;/code&gt; contains four references, but index &lt;code&gt;1&lt;/code&gt; appears twice and index &lt;code&gt;2&lt;/code&gt; is absent.&lt;/p&gt;

&lt;p&gt;For a well-formed plan like that, the function below returns the evidence instead of throwing: a &lt;code&gt;missing&lt;/code&gt; list and a &lt;code&gt;duplicates&lt;/code&gt; list that the caller can show or log before anything consumes the parts. It answers one small question: does every index from zero through &lt;code&gt;pageCount - 1&lt;/code&gt; occur exactly once across the parts? It does not establish that the parts are in the intended order or that a resulting PDF is correct.&lt;/p&gt;

&lt;h2&gt;
  
  
  Return the evidence, not just a count
&lt;/h2&gt;

&lt;p&gt;The function takes arrays of zero-based indices. It records seen indices and repeated indices separately, then builds a sorted list of duplicates and a list of missing indices. A well-formed but incomplete plan returns those details. Malformed input throws instead: an empty part, a non-integer index, or an index outside the document is not treated as an ordinary coverage result.&lt;/p&gt;

&lt;p&gt;The bounds belong to this teaching example: a page count from 1 to 1,000, one to 100 nonempty parts, and at most 2,000 total occurrences. They limit the inputs this function accepts and do not describe the limits of a PDF product. The function reads the arrays without changing them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;partitionCoverage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pageCount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isSafeInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pageCount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;pageCount&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;pageCount&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
      &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;invalid partition input&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;seen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nx"&gt;repeated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;occurrences&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;part&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;part&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;part&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;occurrences&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;part&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;invalid part&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;part&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isSafeInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;pageCount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;invalid zero-based page index&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="nx"&gt;repeated&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nx"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;missing&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;pageCount&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;duplicates&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;repeated&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;complete&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;missing&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;duplicates&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;missing&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;duplicates&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  A complete result is not an order check
&lt;/h2&gt;

&lt;p&gt;For &lt;code&gt;[[0,1],[1,3]]&lt;/code&gt;, the result reports &lt;code&gt;missing: [2]&lt;/code&gt; and &lt;code&gt;duplicates: [1]&lt;/code&gt;. &lt;code&gt;[[3,2],[1,0]]&lt;/code&gt;, on the other hand, is a complete partition under this contract: each index occurs once, even though the sequence is reversed. If the application needs consecutive parts in source order, it needs a separate, explicitly defined order check.&lt;/p&gt;

&lt;p&gt;Paste these assertions after the function in the same &lt;code&gt;.mjs&lt;/code&gt; file. The valid cases include incomplete results; “valid” here means the function can evaluate the input, not that the partition is complete. The assertions also check that the inputs remain unchanged.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;assert&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;node:assert/strict&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;valid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
 &lt;span class="p"&gt;[[[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,{&lt;/span&gt;&lt;span class="na"&gt;complete&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="na"&gt;missing&lt;/span&gt;&lt;span class="p"&gt;:[],&lt;/span&gt;&lt;span class="na"&gt;duplicates&lt;/span&gt;&lt;span class="p"&gt;:[]}],&lt;/span&gt;
 &lt;span class="p"&gt;[[[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,{&lt;/span&gt;&lt;span class="na"&gt;complete&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="na"&gt;missing&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="na"&gt;duplicates&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]}],&lt;/span&gt;
 &lt;span class="p"&gt;[[[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,{&lt;/span&gt;&lt;span class="na"&gt;complete&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="na"&gt;missing&lt;/span&gt;&lt;span class="p"&gt;:[],&lt;/span&gt;&lt;span class="na"&gt;duplicates&lt;/span&gt;&lt;span class="p"&gt;:[]}],&lt;/span&gt;
 &lt;span class="p"&gt;[[[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,{&lt;/span&gt;&lt;span class="na"&gt;complete&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="na"&gt;missing&lt;/span&gt;&lt;span class="p"&gt;:[],&lt;/span&gt;&lt;span class="na"&gt;duplicates&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]}],&lt;/span&gt;
 &lt;span class="p"&gt;[[[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,{&lt;/span&gt;&lt;span class="na"&gt;complete&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="na"&gt;missing&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="na"&gt;duplicates&lt;/span&gt;&lt;span class="p"&gt;:[]}]&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;valid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;before&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deepEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;partitionCoverage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="nx"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="nx"&gt;before&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;invalid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[[[],&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],[[[]],&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],[[[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],[[[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],[[[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],[[[&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],[[[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],[[[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;&lt;span class="mi"&gt;1001&lt;/span&gt;&lt;span class="p"&gt;],[[&lt;/span&gt;&lt;span class="nc"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2001&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)],&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="nc"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;101&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]];&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;invalid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;throws&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;partitionCoverage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;valid&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;valid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="na"&gt;rejected&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;invalid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="na"&gt;boundary&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;coverage only, not order or real PDF output&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The saved November 1 Node v22.23.4 run records five valid inputs and 10 rejected inputs. The stub exited with code 1 and the implementation with code 0. These synthetic assertions do not inspect page identity, printed numbering, rendering, navigation, or a real output file. No PDF decoding or writing, ZIP creation, browser or device behavior, or conversion was tested.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disclosure: Drafted with GPT-6.1 Terra for Yan Wang / LensUp; Yan Wang is affiliated with LensUp. Polished by an independent editorial AI (lensup 主编); Codex (AI) fact-checked the text and checked the code against the retained synthetic runs. No human editor or owner reviewed or tested it. The background is November 1 source and public-page inspection plus the saved synthetic Node run described above.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>testing</category>
    </item>
    <item>
      <title>Parse a page selection completely or not at all</title>
      <dc:creator>Yan Wang</dc:creator>
      <pubDate>Sun, 01 Nov 2026 07:26:10 +0000</pubDate>
      <link>https://dev.to/yanwang/parse-a-page-selection-completely-or-not-at-all-4io8</link>
      <guid>https://dev.to/yanwang/parse-a-page-selection-completely-or-not-at-all-4io8</guid>
      <description>&lt;p&gt;A page-selection field looks small until you ask what should happen with &lt;code&gt;1,&lt;/code&gt;, &lt;code&gt;2junk&lt;/code&gt;, or &lt;code&gt;1-1000,1&lt;/code&gt;. A forgiving parser might quietly keep the part it understands. For a document operation, that can leave the user with a different selection from the one they meant.&lt;/p&gt;

&lt;p&gt;This example takes a narrower approach: under an explicit teaching policy, it accepts the entire input or returns &lt;code&gt;null&lt;/code&gt;. It converts displayed page numbers, which start at one, into zero-based indices. It does not open or modify a PDF.&lt;/p&gt;

&lt;h2&gt;
  
  
  Define the contract before parsing
&lt;/h2&gt;

&lt;p&gt;The grammar accepts ASCII positive integers and inclusive ranges separated by commas. Whitespace is allowed around tokens but not inside a range. Descending ranges are valid. If a page occurs more than once, the output keeps its first occurrence, so &lt;code&gt;4-2,2,6&lt;/code&gt; becomes &lt;code&gt;[3,2,1,5]&lt;/code&gt; for a six-page document.&lt;/p&gt;

&lt;p&gt;The policy rejects leading zeroes, full-width digits, semicolons, empty tokens, trailing text, and out-of-range pages. Those choices help only if the interface tells users what it accepts. They are not a universal definition of page selection, and they do not describe a production parser's complete grammar.&lt;/p&gt;

&lt;p&gt;The limits are part of this example's contract: at most 120 UTF-16 code units, 20 tokens, and 1,000 expanded occurrences, with a page count between 1 and 10,000. Expansion is counted before deduplication, so &lt;code&gt;1-1000,1&lt;/code&gt; exceeds the budget even though the unique result would contain only 1,000 pages. A selection can be syntactically valid and still fail the budget.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;parsePages&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pageCount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
      &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isSafeInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pageCount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;pageCount&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;pageCount&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tokens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tokens&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="nx"&gt;seen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;expanded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;tokens&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;match&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/^&lt;/span&gt;&lt;span class="se"&gt;([&lt;/span&gt;&lt;span class="sr"&gt;1-9&lt;/span&gt;&lt;span class="se"&gt;]\d&lt;/span&gt;&lt;span class="sr"&gt;*&lt;/span&gt;&lt;span class="se"&gt;)(?:&lt;/span&gt;&lt;span class="sr"&gt;-&lt;/span&gt;&lt;span class="se"&gt;([&lt;/span&gt;&lt;span class="sr"&gt;1-9&lt;/span&gt;&lt;span class="se"&gt;]\d&lt;/span&gt;&lt;span class="sr"&gt;*&lt;/span&gt;&lt;span class="se"&gt;))?&lt;/span&gt;&lt;span class="sr"&gt;$/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isSafeInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isSafeInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
        &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;pageCount&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;pageCount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;expanded&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;expanded&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;step&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;step&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;step&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;pages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;pages&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Check the policy, including rejections
&lt;/h2&gt;

&lt;p&gt;Paste the assertions below after the function in the same &lt;code&gt;.mjs&lt;/code&gt; file. The tests compare complete arrays, so they exercise both the indexing and the first-occurrence order. They also make the rejection policy visible to anyone who changes the parser later.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;assert&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;node:assert/strict&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;valid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1-3,5&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;
 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;4-2,2,6&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;
 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; 1 , 3-2 &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;
 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2,2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;
 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1-1000&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;},(&lt;/span&gt;&lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;valid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deepEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;parsePages&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="nx"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;invalid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2junk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;4&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;01&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;１&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1;2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1 - 2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1-1001&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1001&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1-1000,1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;2.5&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;10001&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;121&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;21&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;invalid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;parsePages&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;valid&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;valid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="na"&gt;rejected&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;invalid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="na"&gt;boundary&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;synthetic text and page indices only&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Number.isSafeInteger&lt;/code&gt; guards the numeric inputs and the parsed endpoints, and a &lt;code&gt;Set&lt;/code&gt; records pages already emitted. Neither one decides how an application should report a rejection. This function returns the same value for every invalid case, so a user interface that needs specific explanations would need a separate, carefully defined diagnostic contract.&lt;/p&gt;

&lt;p&gt;The saved November 1 Node v22.23.4 run records five valid and 17 rejected synthetic cases. The stub exited with code 1 and the implementation with code 0. That evidence covers these text and index examples, not PDF decoding or writing, ZIP creation, browser or device behavior, or conversion.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disclosure: Drafted with GPT-6.1 Terra for Yan Wang / LensUp; Yan Wang is affiliated with LensUp. Polished by an independent editorial AI (lensup 主编); Codex (AI) fact-checked the text and checked the code against the retained synthetic runs. No human editor or owner reviewed or tested it. The background is November 1 source and public-page inspection plus the saved synthetic Node run described above.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
