* Creates a JSON pointer path, by joining one or more tokens to a base path. * * @param base - The base path (e.g., "schema.json#/definitions/person") * @param tokens - The token(s) to append (e.g., ["name", "first"]) * @returns
(base: string, tokens: string | string[])
| 249 | * @returns |
| 250 | */ |
| 251 | static join(base: string, tokens: string | string[]) { |
| 252 | // Ensure that the base path contains a hash |
| 253 | if (base.indexOf('#') === -1) { |
| 254 | base += '#'; |
| 255 | } |
| 256 | |
| 257 | // Append each token to the base path |
| 258 | tokens = Array.isArray(tokens) ? tokens : [tokens]; |
| 259 | for (let i = 0; i < tokens.length; i++) { |
| 260 | const token = tokens[i]!; |
| 261 | // Encode the token, according to RFC 6901 |
| 262 | base += '/' + encodeURIComponent(token.replace(tildes, '~0').replace(slashes, '~1')); |
| 263 | } |
| 264 | |
| 265 | return base; |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | /** |
no outgoing calls