Skip to content

Parse octal string

parseOctalString parses octal string literals (0o…) into bigint values.

It enforces strict base‑8 formatting and rejects any malformed or non‑octal input. If the value is not a string, does not match the octal literal pattern, or cannot be parsed by BigInt, the rule emits no parse result.

Signature

Through the API:

.parse('octal');

And internally:

export const parseOctalString: ParseRule<unknown>
(value: unknown, path: FieldPath) => ParseResult<unknown>[]

Events

Event code Description
string.now.octal Parsed octal string into a bigint value.

Design rationale

  • Accepts only canonical octal bigint literals:
  • Must start with 0o.
  • Must contain only digits0–7.
  • No whitespace, separators, signs, or formatting.
  • Rejects ambiguous formats such as "0O77", "0o", "0o89", " 0o10 ", or "0o1_2".
  • Ensures contributors can rely on strict, predictable octal parsing.
  • Produces a single parse step containing the parsed bigint and one parseEvent.
  • Never guesses, normalizes, or coerces — parsing is explicit and opt‑in.

Invoke

parseOctalString runs only when explicitly included in a boundary or pipeline. It is not affected by normalization mode and does not run automatically.

The rule activates when:

  • The value is a string.
  • The string matches the octal literal pattern: /^0o[0-7]+$/.
  • BigInt(value) succeeds.

Examples

Valid octal strings

parseOctalString("0o77", "$");
// → [
//     {
//       path: "$",
//       nextValue: 63n,
//       events: [
//         JaneEvent{ kind: "info", code: "string.now.octal", ... }
//       ]
//     }
//   ]

parseOctalString("0o123", "$");
// → [
//     {
//       path: "$",
//       nextValue: 83n,
//       events: [ JaneEvent{ code: "string.now.octal", ... } ]
//     }
//   ]

Invalid formats — no parse

parseOctalString("0o", "$");        // → []
parseOctalString("0o89", "$");      // → []
parseOctalString("0O77", "$");      // → []
parseOctalString(" 0o10 ", "$");    // → []
parseOctalString("0o1_2", "$");     // → []

Non‑string value

parseOctalString(42, "$"); // → []