Files
FrenoCorp/node_modules/@solana/codecs-strings/src/assertions.ts
Michael Freno 7c684a42cc FRE-600: Fix code review blockers
- Consolidated duplicate UndoManagers to single instance
- Fixed connection promise to only resolve on 'connected' status
- Fixed WebSocketProvider import (WebsocketProvider)
- Added proper doc.destroy() cleanup
- Renamed isPresenceInitialized property to avoid conflict

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-25 00:08:01 -04:00

32 lines
1.2 KiB
TypeScript

import { SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE, SolanaError } from '@solana/errors';
/**
* Asserts that a given string contains only characters from the specified alphabet.
*
* This function validates whether a string consists exclusively of characters
* from the provided `alphabet`. If the validation fails, it throws an error
* indicating the invalid base string.
*
* @param alphabet - The allowed set of characters for the base encoding.
* @param testValue - The string to validate against the given alphabet.
* @param givenValue - The original string provided by the user (defaults to `testValue`).
*
* @throws {SolanaError} If `testValue` contains characters not present in `alphabet`.
*
* @example
* Validating a base-8 encoded string.
* ```ts
* assertValidBaseString('01234567', '123047'); // Passes
* assertValidBaseString('01234567', '128'); // Throws error
* ```
*/
export function assertValidBaseString(alphabet: string, testValue: string, givenValue = testValue) {
if (!testValue.match(new RegExp(`^[${alphabet}]*$`))) {
throw new SolanaError(SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE, {
alphabet,
base: alphabet.length,
value: givenValue,
});
}
}