(token: string): stringEscapes a JSON Pointer reference token according to RFC 6901 by encoding special characters so the token can be safely used as a segment in a JSON Pointer.
When to use
Use when you need to escape a single JSON Pointer path segment.
Details
- Returns a new escaped string
- Replaces
~(tilde) with~0and/(forward slash) with~1 - Returns the input unchanged if it contains no special characters
- Empty strings are valid and returned unchanged
Gotchas
The replacement order matters: ~ is replaced before / to prevent double-escaping.
Example (Escaping special characters)
import { JsonPointer } from "effect"
JsonPointer.escapeToken("a/b") // "a~1b"
JsonPointer.escapeToken("c~d") // "c~0d"
JsonPointer.escapeToken("path/to~key") // "path~1to~0key"export function function escapeToken(
token: string
): string
Escapes a JSON Pointer reference token according to RFC 6901 by encoding special characters so the token can be safely used as a segment in a JSON Pointer.
When to use
Use when you need to escape a single JSON Pointer path segment.
Details
- Returns a new escaped string
- Replaces
~ (tilde) with ~0 and / (forward slash) with ~1
- Returns the input unchanged if it contains no special characters
- Empty strings are valid and returned unchanged
Gotchas
The replacement order matters: ~ is replaced before / to prevent double-escaping.
Example (Escaping special characters)
import { JsonPointer } from "effect"
JsonPointer.escapeToken("a/b") // "a~1b"
JsonPointer.escapeToken("c~d") // "c~0d"
JsonPointer.escapeToken("path/to~key") // "path~1to~0key"
escapeToken(token: stringtoken: string): string {
return token: stringtoken.String.replace(searchValue: {
[Symbol.replace](string: string, replaceValue: string): string;
}, replaceValue: string): string (+3 overloads)
Passes a string and
{@linkcode
replaceValue
}
to the [Symbol.replace] method on
{@linkcode
searchValue
}
. This method is expected to implement its own replacement algorithm.
replace(/~/g, "~0").String.replace(searchValue: {
[Symbol.replace](string: string, replaceValue: string): string;
}, replaceValue: string): string (+3 overloads)
Passes a string and
{@linkcode
replaceValue
}
to the [Symbol.replace] method on
{@linkcode
searchValue
}
. This method is expected to implement its own replacement algorithm.
replace(/\//g, "~1")
}