Choosing the right mode¶
Modes are one of the most important ideas in Jane. They let you control how strict, forgiving, or developer‑friendly the pipeline should be — without rewriting your rules, without changing your validators, and without touching your parsing logic.
A mode is not a
- Validator.
- Parser.
- Policy override.
A mode is the personality of the pipeline.
It determines how much normalization happens, whether scan runs, how lossy transformations are allowed to be, and how strict the pipeline should feel.
Let’s walk through the three modes and how they shape your pipeline.
The Three Modes¶
Jane has three built‑in modes:
strictmoderate(default)lax
Each mode affects:
- Whether scan runs.
- How normalization behaves.
- Whether lossy changes are allowed.
- How forgiving the pipeline is.
- How much structural noise is tolerated.
You can switch modes at any point in the chain:
jane.value(input).strict().run();
jane.value(input).moderate().run();
jane.value(input).lax().run();
Let’s look at each one in plain language.
- Strict Mode — Maximum Scrutiny
Strict mode is for environments where correctness and safety matter more than convenience:
- Backend boundaries.
- Compliance systems.
- Regulated environments.
- Internal APIs.
- Anything that must reject questionable input.
Strict mode¶
- Enables scan.
- Disables normalization.
- Rejects lossy transformations.
- Treats warnings more seriously.
- Expects clean, well‑formed input.
Example:
const result = await jane.value(" 42 ")
.strict()
.parse("numeric")
.run();
In strict mode:
" 42 "is not trimmed.- Parsing
" 42 "fails. - The pipeline rejects the value.
Strict mode never guesses. Strict mode never cleans up for you. Strict mode expects the input to be correct as‑is.
Moderate Mode¶
Moderate mode is the default mode for Jane. It’s designed for:
- Internal services.
- Backend logic.
- Typical application boundaries.
- Places where you want safety without being overly rigid.
Moderate mode:
- Disables scan.
- Enables safe, non‑lossy normalization.
- Trims strings.
- Compacts arrays.
- Removes undefined keys.
- Never performs lossy transformations.
Example:
const result = await jane.value(" 42 ")
.parse("numeric")
.run();
In moderate mode:
" 42 "becomes"42"."42"parses cleanly.- The pipeline accepts the value.
Moderate mode is the “balanced” personality — safe, predictable, and developer‑friendly without being permissive.
Lax Mode¶
Lax mode is for:
- User‑facing forms.
- Prototyping.
- Exploratory development.
- Places where convenience matters more than strictness.
Lax mode:
- Disables scan.
- Enables full normalization.
- Allows lossy transformations.
- Downgrades some errors to warnings.
- Accepts a wider range of inputs.
Example:
const result = await jane.value(" 42 ")
.lax()
.parse("numeric")
.run();
In lax mode:
" 42 "is trimmed."42"parses.- Minor structural issues are tolerated.
- The pipeline accepts the value.
Lax mode is intentionally forgiving — perfect for messy real‑world input.
How Modes Affect Normalization¶
Here’s a quick comparison:
| Feature | Strict | Moderate | Lax |
|---|---|---|---|
| Scan | ✔️ | ❌ | ❌ |
| Safe normalization | ❌ | ✔️ | ✔️ |
| Lossy normalization | ❌ | ❌ | ✔️ |
| Trimming strings | ❌ | ✔️ | ✔️ |
| Compacting arrays | ❌ | ✔️ | ✔️ |
| Removing empty keys | ❌ | ✔️ | ✔️ |
| Aggressive cleanup | ❌ | ❌ | ✔️ |
This is why choosing the right mode matters — it changes how the pipeline behaves before parsing and validation even begin.
How Modes Affect Real Code¶
Let’s take a messy input:
const input = {
name: " Alice ",
age: " 42 ",
tags: ["a", "", "b"]
};
Strict Mode¶
const result = await jane.value(input).strict().run();
- No trimming.
- No compaction.
- No cleanup.
- Parsing " 42 " fails.
- Pipeline rejects.
Moderate Mode¶
const result = await jane.value(input).run();
- Trims " Alice " → "Alice"
- Trims " 42 " → "42"
- Compacts tags → ["a", "b"]
- Parsing succeeds
- Pipeline accepts
Lax Mode¶
const result = await jane.value(input).lax().run();
- Everything moderate mode does.
- Plus lossy cleanup if needed.
- Even more forgiving.
When to Use Each Mode¶
Use strict when:
- You’re validating API boundaries.
- You’re enforcing compliance.
- You’re handling sensitive data.
- You want zero surprises.
Use moderate when:
- You want safe defaults.
- You want predictable behavior.
- You want clean input without being rigid.
- You’re building typical backend logic.
Use lax when:
- You’re handling user input.
- You’re prototyping.
- You want convenience.
- You expect messy data.
What You’ve Learned¶
You now understand:
- What modes are.
- How they shape the pipeline.
- How they affect normalization and scan.
- How strict, moderate, and lax differ.
- When to choose each one.
Modes are one of Jane’s most powerful features — they let you tune strictness without rewriting your pipelines.
In the next chapter, we’ll dive into parsing — how to turn raw strings into meaningful values. Start your engines!