New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@solana/options

Package Overview
Dependencies
Maintainers
1
Versions
1193
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solana/options - npm Package Compare versions

Comparing version 2.1.0-canary-20241211084732 to 2.1.0-canary-20250227211824

10

dist/types/index.d.ts

@@ -0,1 +1,11 @@

/**
* This package allows us to manage and serialize Rust-like Option types in JavaScript.
* It can be used standalone, but it is also exported as part of Kit
* [`@solana/kit`](https://github.com/anza-xyz/kit/tree/main/packages/kit).
*
* This package is also part of the [`@solana/codecs` package](https://github.com/anza-xyz/kit/tree/main/packages/codecs)
* which acts as an entry point for all codec packages as well as for their documentation.
*
* @packageDocumentation
*/
export * from './option';

@@ -2,0 +12,0 @@ export * from './option-codec';

223

dist/types/option-codec.d.ts
import { Codec, Decoder, Encoder, FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder, ReadonlyUint8Array, VariableSizeCodec, VariableSizeDecoder, VariableSizeEncoder } from '@solana/codecs-core';
import { FixedSizeNumberCodec, FixedSizeNumberDecoder, FixedSizeNumberEncoder, NumberCodec, NumberDecoder, NumberEncoder } from '@solana/codecs-numbers';
import { Option, OptionOrNullable } from './option';
/** Defines the config for Option codecs. */
/**
* Defines the configuration options for {@link Option} codecs.
*
* The `getOptionCodec` function behaves similarly to {@link getNullableCodec}
* but encodes `Option<T>` types instead of `T | null` types.
*
* This configuration controls how {@link None} values are encoded and how presence
* is determined when decoding.
*
* @typeParam TPrefix - A number codec, encoder, or decoder used as the presence prefix.
*
* @see {@link getOptionEncoder}
* @see {@link getOptionDecoder}
* @see {@link getOptionCodec}
*/
export type OptionCodecConfig<TPrefix extends NumberCodec | NumberDecoder | NumberEncoder> = {
/**
* Defines how the `None` value should be represented.
* Specifies how {@link None} values are represented in the encoded data.
*
* By default, no none value is used. This means a `None` value will be
* represented by the absence of the item.
* - By default, {@link None} values are omitted from encoding.
* - `'zeroes'`: The bytes allocated for the value are filled with zeroes. This requires a fixed-size codec for the item.
* - Custom byte array: {@link None} values are replaced with a predefined byte sequence. This results in a variable-size codec.
*
* When `'zeroes'` is provided, a `None` value will skip the bytes that would
* have been used for the item. Note that this returns a fixed-size codec
* and thus will only work if the item codec is of fixed size.
*
* When a custom byte array is provided, a `None` value will be represented
* by the provided byte array. Note that this returns a variable-size codec
* since the byte array representing `None` does not need to match the size
* of the item codec.
*
* @defaultValue No none value is used.
* @defaultValue No explicit `noneValue` is used; {@link None} values are omitted.
*/
noneValue?: ReadonlyUint8Array | 'zeroes';
/**
* The codec to use for the boolean prefix, if any.
* The presence prefix used to distinguish between {@link None} and present values.
*
* By default a `u8` number is used as a prefix to determine if the value is `None`.
* The value `0` is encoded for `None` and `1` if the value is present.
* This can be set to any number codec to customize the prefix.
* - By default, a `u8` prefix is used (`0 = None`, `1 = Some`).
* - Custom number codec: Allows defining a different number size for the prefix.
* - `null`: No prefix is used; `noneValue` (if provided) determines {@link None}.
* If no `noneValue` is set, {@link None} is identified by the absence of bytes.
*
* When `null` is provided, no prefix is used and the `noneValue` is used to
* determine if the value is `None`. If no `noneValue` is provided, then the
* absence of any bytes is used to determine if the value is `None`.
*
* @defaultValue `u8` prefix.

@@ -40,6 +43,39 @@ */

/**
* Creates a encoder for an optional value using the `Option<T>` type.
* Returns an encoder for optional values using the {@link Option} type.
*
* @param item - The encoder to use for the value that may be present.
* @param config - A set of config for the encoder.
* This encoder serializes an {@link OptionOrNullable} value using a configurable approach:
* - By default, a `u8` prefix is used (`0 = None`, `1 = Some`). This can be customized or disabled.
* - If `noneValue: 'zeroes'` is set, {@link None} values are encoded as zeroes.
* - If `noneValue` is a byte array, {@link None} values are replaced with the provided constant.
*
* Unlike {@link getNullableEncoder}, this encoder accepts both {@link Option} and {@link Nullable} values.
*
* For more details, see {@link getOptionCodec}.
*
* @typeParam TFrom - The type of the main value being encoded.
*
* @param item - The encoder for the value that may be present.
* @param config - Configuration options for encoding optional values.
* @returns A `FixedSizeEncoder` or `VariableSizeEncoder` for encoding option values.
*
* @example
* Encoding an optional string.
* ```ts
* const stringCodec = addCodecSizePrefix(getUtf8Codec(), getU32Codec());
* const encoder = getOptionEncoder(stringCodec);
*
* encoder.encode(some('Hi'));
* encoder.encode('Hi');
* // 0x01020000004869
* // | | └-- utf8 string content ("Hi").
* // | └-- u32 string prefix (2 characters).
* // └-- 1-byte prefix (Some).
*
* encoder.encode(none());
* encoder.encode(null);
* // 0x00
* // └-- 1-byte prefix (None).
* ```
*
* @see {@link getOptionCodec}
*/

@@ -60,6 +96,33 @@ export declare function getOptionEncoder<TFrom, TSize extends number>(item: FixedSizeEncoder<TFrom, TSize>, config: OptionCodecConfig<NumberEncoder> & {

/**
* Creates a decoder for an optional value using the `Option<T>` type.
* Returns a decoder for optional values using the {@link Option} type.
*
* @param item - The decoder to use for the value that may be present.
* @param config - A set of config for the decoder.
* This decoder deserializes an `Option<T>` value using a configurable approach:
* - By default, a `u8` prefix is used (`0 = None`, `1 = Some`). This can be customized or disabled.
* - If `noneValue: 'zeroes'` is set, `None` values are identified by zeroes.
* - If `noneValue` is a byte array, `None` values match the provided constant.
*
* Unlike {@link getNullableDecoder}, this decoder always outputs an {@link Option} type.
*
* For more details, see {@link getOptionCodec}.
*
* @typeParam TTo - The type of the main value being decoded.
*
* @param item - The decoder for the value that may be present.
* @param config - Configuration options for decoding optional values.
* @returns A `FixedSizeDecoder` or `VariableSizeDecoder` for decoding option values.
*
* @example
* Decoding an optional string with a size prefix.
* ```ts
* const stringCodec = addCodecSizePrefix(getUtf8Codec(), getU32Codec());
* const decoder = getOptionDecoder(stringCodec);
*
* decoder.decode(new Uint8Array([0x01, 0x02, 0x00, 0x00, 0x00, 0x48, 0x69]));
* // some('Hi')
*
* decoder.decode(new Uint8Array([0x00]));
* // none()
* ```
*
* @see {@link getOptionCodec}
*/

@@ -80,6 +143,104 @@ export declare function getOptionDecoder<TTo, TSize extends number>(item: FixedSizeDecoder<TTo, TSize>, config: OptionCodecConfig<NumberDecoder> & {

/**
* Creates a codec for an optional value using the `Option<T>` type.
* Returns a codec for encoding and decoding optional values using the {@link Option} type.
*
* @param item - The codec to use for the value that may be present.
* @param config - A set of config for the codec.
* This codec serializes and deserializes `Option<T>` values using a configurable approach:
* - By default, a `u8` prefix is used (`0 = None`, `1 = Some`).
* - If `noneValue: 'zeroes'` is set, `None` values are encoded/decoded as zeroes.
* - If `noneValue` is a byte array, `None` values are represented by the provided constant.
* - If `prefix: null` is set, the codec determines `None` values solely from `noneValue` or the presence of bytes.
*
* For more details on the configuration options, see {@link OptionCodecConfig}.
*
* Note that this behaves similarly to {@link getNullableCodec}, except it
* encodes {@link OptionOrNullable} values and decodes {@link Option} values.
*
* @typeParam TFrom - The type of the main value being encoded.
* @typeParam TTo - The type of the main value being decoded.
*
* @param item - The codec for the value that may be present.
* @param config - Configuration options for encoding and decoding option values.
* @returns A `FixedSizeCodec` or `VariableSizeCodec` for encoding and decoding option values.
*
* @example
* Encoding and decoding an optional string with a size prefix.
* ```ts
* const stringCodec = addCodecSizePrefix(getUtf8Codec(), getU32Codec());
* const codec = getOptionCodec(stringCodec);
*
* const someBytes = codec.encode(some('Hi'));
* // 0x01020000004869
* // | | └-- utf8 string content ("Hi").
* // | └-- u32 string prefix (2 characters).
* // └-- 1-byte prefix (Some).
*
* const noneBytes = codec.encode(none());
* // 0x00
* // └-- 1-byte prefix (None).
*
* codec.decode(someBytes); // some('Hi')
* codec.decode(noneBytes); // none()
* ```
*
* @example
* Encoding nullable values.
* ```ts
* const stringCodec = addCodecSizePrefix(getUtf8Codec(), getU32Codec());
* const codec = getOptionCodec(stringCodec);
*
* const someBytes = codec.encode('Hi'); // 0x01020000004869
* const noneBytes = codec.encode(null); // 0x00
*
* codec.decode(someBytes); // some('Hi')
* codec.decode(noneBytes); // none()
* ```
*
* @example
* Encoding and decoding an optional number with a fixed size.
* ```ts
* const codec = getOptionCodec(getU16Codec(), { noneValue: 'zeroes' });
*
* const someBytes = codec.encode(some(42)); // 0x012a00
* const noneBytes = codec.encode(none()); // 0x000000
*
* codec.decode(someBytes); // some(42)
* codec.decode(noneBytes); // none()
* ```
*
* @example
* Encoding and decoding {@link None} values with a custom byte sequence and no prefix.
* ```ts
* const codec = getOptionCodec(getU16Codec(), {
* noneValue: new Uint8Array([0xff, 0xff]),
* prefix: null,
* });
*
* const someBytes = codec.encode(some(42)); // 0x2a00
* const noneBytes = codec.encode(none()); // 0xffff
*
* codec.decode(someBytes); // some(42)
* codec.decode(noneBytes); // none()
* ```
*
* @example
* Identifying {@link None} values by the absence of bytes.
* ```ts
* const codec = getOptionCodec(getU16Codec(), { prefix: null });
*
* const someBytes = codec.encode(some(42)); // 0x2a00
* const noneBytes = codec.encode(none()); // new Uint8Array(0)
*
* codec.decode(someBytes); // some(42)
* codec.decode(noneBytes); // none()
* ```
*
* @remarks
* Separate {@link getOptionEncoder} and {@link getOptionDecoder} functions are available.
*
* ```ts
* const bytes = getOptionEncoder(getU32Encoder()).encode(some(42));
* const value = getOptionDecoder(getU32Decoder()).decode(bytes);
* ```
*
* @see {@link getOptionEncoder}
* @see {@link getOptionDecoder}
*/

@@ -86,0 +247,0 @@ export declare function getOptionCodec<TFrom, TTo extends TFrom, TSize extends number>(item: FixedSizeCodec<TFrom, TTo, TSize>, config: OptionCodecConfig<NumberCodec> & {

/**
* An implementation of the Rust Option type in JavaScript.
* It can be one of the following:
* - <code>{@link Some}<T></code>: Meaning there is a value of type T.
* - <code>{@link None}</code>: Meaning there is no value.
* An implementation of the Rust `Option<T>` type in JavaScript.
*
* In Rust, optional values are represented using `Option<T>`, which can be either:
* - `Some(T)`, indicating a present value.
* - `None`, indicating the absence of a value.
*
* In JavaScript, this is typically represented as `T | null`. However, this approach fails with nested options.
* For example, `Option<Option<T>>` in Rust would translate to `T | null | null` in JavaScript, which is equivalent to `T | null`.
* This means there is no way to differentiate between `Some(None)` and `None`, making nested options impossible.
*
* This `Option` type helps solve this by mirroring Rust’s `Option<T>` type.
*
* ```ts
* type Option<T> = Some<T> | None;
* type Some<T> = { __option: 'Some'; value: T };
* type None = { __option: 'None' };
* ```
*
* @typeParam T - The type of the contained value.
*
* @example
* Here's how you can create `Option` values.
*
* To improve developer experience, helper functions are available.
* TypeScript can infer the type of `T` or it can be explicitly provided.
*
* ```ts
* // Create an option with a value.
* some('Hello World');
* some<number | string>(123);
*
* // Create an empty option.
* none();
* none<number | string>();
* ```
*
* @see {@link Some}
* @see {@link None}
* @see {@link some}
* @see {@link none}
*/
export type Option<T> = None | Some<T>;
/**
* Defines a looser type that can be used when serializing an {@link Option}.
* This allows us to pass null or the Option value directly whilst still
* A flexible type that allows working with {@link Option} values or nullable values.
*
* It defines a looser type that can be used when encoding {@link Option | Options}.
* This allows us to pass `null` or the nested value directly whilst still
* supporting the Option type for use-cases that need more type safety.
*
* @typeParam T - The type of the contained value.
*
* @example
* Accepting both `Option<T>` and `T | null` as input.
* ```ts
* function double(value: OptionOrNullable<number>) {
* const option = isOption(value) ? value : wrapNullable(value);
* return isSome(option) ? option.value * 2 : 'No value';
* }
*
* double(42); // 84
* double(some(21)); // 42
* double(none()); // "No value"
* double(null); // "No value"
* ```
*
* @see {@link Option}
* @see {@link isOption}
* @see {@link wrapNullable}
*/
export type OptionOrNullable<T> = Option<T> | T | null;
/**
* Represents an option of type `T` that has a value.
* Represents an {@link Option} that contains a value.
*
* This type mirrors Rust’s `Some(T)`, indicating that a value is present.
*
* For more details, see {@link Option}.
*
* @typeParam T - The type of the contained value.
*
* @example
* Creating a `Some` value.
* ```ts
* const value = some(42);
* isSome(value); // true
* isNone(value); // false
* ```
*
* @see {@link Option}
* @see {@link some}
* @see {@link isSome}
*/

@@ -24,5 +98,19 @@ export type Some<T> = Readonly<{

/**
* Represents an option of type `T` that has no value.
* Represents an {@link Option} that contains no value.
*
* This type mirrors Rust’s `None`, indicating the absence of a value.
*
* For more details, see {@link Option}.
*
* @example
* Creating a `None` value.
* ```ts
* const empty = none();
* isNone(empty); // true
* isSome(empty); // false
* ```
*
* @see {@link Option}
* @see {@link none}
* @see {@link isNone}
*/

@@ -33,25 +121,112 @@ export type None = Readonly<{

/**
* Creates a new {@link Option} of type `T` that has a value.
* Creates a new {@link Option} that contains a value.
*
* This function explicitly wraps a value in an {@link Option} type.
*
* @typeParam T - The type of the contained value.
*
* @param value - The value to wrap in an {@link Option}.
* @returns An {@link Option} containing the provided value.
*
* @example
* Wrapping a value in an `Option`.
* ```ts
* const option = some('Hello');
* option.value; // "Hello"
* isOption(option); // true
* isSome(option); // true
* isNone(option); // false
* ```
*
* @see {@link Option}
* @see {@link Some}
*/
export declare const some: <T>(value: T) => Option<T>;
/**
* Creates a new {@link Option} of type `T` that has no value.
* Creates a new {@link Option} that contains no value.
*
* This function explicitly represents an absent value.
*
* @typeParam T - The type of the expected absent value.
*
* @returns An {@link Option} containing no value.
*
* @example
* Creating an empty `Option`.
* ```ts
* const empty = none<number>();
* isOption(empty); // true
* isSome(empty); // false
* isNone(empty); // true
* ```
*
* @see {@link Option}
* @see {@link None}
*/
export declare const none: <T>() => Option<T>;
/**
* Whether the given data is an {@link Option}.
* Checks whether the given value is an {@link Option}.
*
* This function determines whether an input follows the `Option<T>` structure.
*
* @typeParam T - The type of the contained value.
*
* @param input - The value to check.
* @returns `true` if the value is an {@link Option}, `false` otherwise.
*
* @example
* Checking for `Option` values.
* ```ts
* isOption(some(42)); // true
* isOption(none()); // true
* isOption(42); // false
* isOption(null); // false
* isOption("anything else"); // false
* ```
*
* @see {@link Option}
*/
export declare const isOption: <T = unknown>(input: unknown) => input is Option<T>;
/**
* Whether the given {@link Option} is a {@link Some}.
* Checks whether the given {@link Option} contains a value.
*
* This function acts as a type guard, ensuring the value is a {@link Some}.
*
* @typeParam T - The type of the contained value.
*
* @param option - The {@link Option} to check.
* @returns `true` if the option is a {@link Some}, `false` otherwise.
*
* @example
* Checking for `Some` values.
* ```ts
* isSome(some(42)); // true
* isSome(none()); // false
* ```
*
* @see {@link Option}
* @see {@link Some}
*/
export declare const isSome: <T>(option: Option<T>) => option is Some<T>;
/**
* Whether the given {@link Option} is a {@link None}.
* Checks whether the given {@link Option} contains no value.
*
* This function acts as a type guard, ensuring the value is a {@link None}.
*
* @typeParam T - The type of the expected value.
*
* @param option - The {@link Option} to check.
* @returns `true` if the option is a {@link None}, `false` otherwise.
*
* @example
* Checking for `None` values.
* ```ts
* isNone(some(42)); // false
* isNone(none()); // true
* ```
*
* @see {@link Option}
* @see {@link None}
*/
export declare const isNone: <T>(option: Option<T>) => option is None;
//# sourceMappingURL=option.d.ts.map
import { None, Some } from './option';
/**
* Lists all types that should not be recursively unwrapped.
* Defines types that should not be recursively unwrapped.
*
* @see {@link UnwrappedOption}
* These types are preserved as-is when using {@link unwrapOptionRecursively}.
*
* @see {@link unwrapOptionRecursively}
*/
type UnUnwrappables = Date | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | bigint | boolean | number | string | symbol | null | undefined;
/**
* A type that defines the recursive unwrapping of a type `T`
* such that all nested {@link Option} types are unwrapped.
* A type that recursively unwraps nested {@link Option} types.
*
* For each nested {@link Option} type, if the option is a {@link Some},
* it returns the type of its value, otherwise, it returns the provided
* fallback type `U` which defaults to `null`.
* This type resolves all nested {@link Option} values, ensuring
* that deeply wrapped values are properly extracted.
*
* - If `T` is an {@link Option}, it resolves to the contained value.
* - If `T` is a known primitive or immutable type, it remains unchanged.
* - If `T` is an object or array, it recursively unwraps any options found.
*
* The fallback type `U` (default: `null`) is used in place of `None` values.
*
* @typeParam T - The type to be unwrapped.
* @typeParam U - The fallback type for `None` values (defaults to `null`).
*
* @example
* Resolving nested `Option` types.
* ```ts
* UnwrappedOption<Some<Some<string>>>; // string
* UnwrappedOption<None>; // null
* ```
*
* @example
* Resolving options inside objects and arrays.
* ```ts
* UnwrappedOption<{ a: Some<number>; b: None }>; // { a: number; b: null }
* UnwrappedOption<[Some<number>, None]>; // [number, null]
* ```
*
* @see {@link unwrapOptionRecursively}
*/

@@ -20,8 +45,55 @@ export type UnwrappedOption<T, U = null> = T extends Some<infer TValue> ? UnwrappedOption<TValue, U> : T extends None ? U : T extends UnUnwrappables ? T : T extends object ? {

/**
* Recursively go through a type `T` such that all
* nested {@link Option} types are unwrapped.
* Recursively unwraps all nested {@link Option} types within a value.
*
* For each nested {@link Option} type, if the option is a {@link Some},
* it returns its value, otherwise, it returns the provided fallback value
* which defaults to `null`.
* This function traverses a given value and removes all instances
* of {@link Option}, replacing them with their contained values.
*
* - If an {@link Option} is encountered, its value is extracted.
* - If an array or object is encountered, its elements are traversed recursively.
* - If `None` is encountered, it is replaced with the fallback value (default: `null`).
*
* @typeParam T - The type of the input value.
* @typeParam U - The fallback type for `None` values (defaults to `null`).
*
* @param input - The value to unwrap.
* @param fallback - A function that provides a fallback value for `None` options.
* @returns The recursively unwrapped value.
*
* @example
* Recursively unwrapping nested options.
* ```ts
* unwrapOptionRecursively(some(some('Hello World'))); // "Hello World"
* unwrapOptionRecursively(some(none<string>())); // null
* ```
*
* @example
* Recursively unwrapping options inside objects and arrays.
* ```ts
* unwrapOptionRecursively({
* a: 'hello',
* b: none(),
* c: [{ c1: some(42) }, { c2: none() }],
* });
* // { a: "hello", b: null, c: [{ c1: 42 }, { c2: null }] }
* ```
*
* @example
* Using a fallback value for `None` options.
* ```ts
* unwrapOptionRecursively(
* {
* a: 'hello',
* b: none(),
* c: [{ c1: some(42) }, { c2: none() }],
* },
* () => 'Default',
* );
* // { a: "hello", b: "Default", c: [{ c1: 42 }, { c2: "Default" }] }
* ```
*
* @remarks
* This function does not mutate objects or arrays.
*
* @see {@link Option}
* @see {@link UnwrappedOption}
*/

@@ -28,0 +100,0 @@ export declare function unwrapOptionRecursively<T>(input: T): UnwrappedOption<T>;

import { Option } from './option';
/**
* Unwraps the value of an {@link Option} of type `T`
* or returns a fallback value that defaults to `null`.
* Unwraps the value of an {@link Option}, returning its contained value or a fallback.
*
* This function extracts the value `T` from an `Option<T>` type.
* - If the option is {@link Some}, it returns the contained value `T`.
* - If the option is {@link None}, it returns the fallback value `U`, which defaults to `null`.
*
* @typeParam T - The type of the contained value.
* @typeParam U - The type of the fallback value (defaults to `null`).
*
* @param option - The {@link Option} to unwrap.
* @param fallback - A function that provides a fallback value if the option is {@link None}.
* @returns The contained value if {@link Some}, otherwise the fallback value.
*
* @example
* Unwrapping an `Option` with no fallback.
* ```ts
* unwrapOption(some('Hello World')); // "Hello World"
* unwrapOption(none()); // null
* ```
*
* @example
* Providing a custom fallback value.
* ```ts
* unwrapOption(some('Hello World'), () => 'Default'); // "Hello World"
* unwrapOption(none(), () => 'Default'); // "Default"
* ```
*
* @see {@link Option}
* @see {@link Some}
* @see {@link None}
*/

@@ -10,4 +38,23 @@ export declare function unwrapOption<T>(option: Option<T>): T | null;

* Wraps a nullable value into an {@link Option}.
*
* - If the input value is `null`, this function returns {@link None}.
* - Otherwise, it wraps the value in {@link Some}.
*
* @typeParam T - The type of the contained value.
*
* @param nullable - The nullable value to wrap.
* @returns An {@link Option} wrapping the value.
*
* @example
* Wrapping nullable values.
* ```ts
* wrapNullable('Hello World'); // Option<string> (Some)
* wrapNullable<string>(null); // Option<string> (None)
* ```
*
* @see {@link Option}
* @see {@link Some}
* @see {@link None}
*/
export declare const wrapNullable: <T>(nullable: T | null) => Option<T>;
//# sourceMappingURL=unwrap-option.d.ts.map

16

package.json
{
"name": "@solana/options",
"version": "2.1.0-canary-20241211084732",
"version": "2.1.0-canary-20250227211824",
"description": "Managing and serializing Rust-like Option types in JavaScript",

@@ -47,6 +47,6 @@ "exports": {

"type": "git",
"url": "https://github.com/solana-labs/solana-web3.js"
"url": "https://github.com/anza-xyz/kit"
},
"bugs": {
"url": "http://github.com/solana-labs/solana-web3.js/issues"
"url": "https://github.com/anza-xyz/kit/issues"
},

@@ -58,7 +58,7 @@ "browserslist": [

"dependencies": {
"@solana/codecs-core": "2.1.0-canary-20241211084732",
"@solana/codecs-data-structures": "2.1.0-canary-20241211084732",
"@solana/codecs-numbers": "2.1.0-canary-20241211084732",
"@solana/codecs-strings": "2.1.0-canary-20241211084732",
"@solana/errors": "2.1.0-canary-20241211084732"
"@solana/codecs-core": "2.1.0-canary-20250227211824",
"@solana/codecs-data-structures": "2.1.0-canary-20250227211824",
"@solana/codecs-numbers": "2.1.0-canary-20250227211824",
"@solana/codecs-strings": "2.1.0-canary-20250227211824",
"@solana/errors": "2.1.0-canary-20250227211824"
},

@@ -65,0 +65,0 @@ "peerDependencies": {

@@ -8,11 +8,11 @@ [![npm][npm-image]][npm-url]

[code-style-prettier-url]: https://github.com/prettier/prettier
[npm-downloads-image]: https://img.shields.io/npm/dm/@solana/options/next.svg?style=flat
[npm-image]: https://img.shields.io/npm/v/@solana/options/next.svg?style=flat
[npm-url]: https://www.npmjs.com/package/@solana/options/v/next
[npm-downloads-image]: https://img.shields.io/npm/dm/@solana/options?style=flat
[npm-image]: https://img.shields.io/npm/v/@solana/options?style=flat
[npm-url]: https://www.npmjs.com/package/@solana/options
# @solana/options
This package allows us to manage and serialize Rust-like Option types in JavaScript. It can be used standalone, but it is also exported as part of the Solana JavaScript SDK [`@solana/web3.js@next`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/library).
This package allows us to manage and serialize Rust-like Option types in JavaScript. It can be used standalone, but it is also exported as part of Kit [`@solana/kit`](https://github.com/anza-xyz/kit/tree/main/packages/kit).
This package is also part of the [`@solana/codecs` package](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs) which acts as an entry point for all codec packages as well as for their documentation.
This package is also part of the [`@solana/codecs` package](https://github.com/anza-xyz/kit/tree/main/packages/codecs) which acts as an entry point for all codec packages as well as for their documentation.

@@ -114,3 +114,3 @@ ## Creating options

The `getOptionCodec` function behaves exactly the same as the [`getNullableCodec`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-data-structures#nullable-codec) except that it encodes `Option<T>` types instead of `T | null` types.
The `getOptionCodec` function behaves exactly the same as the [`getNullableCodec`](https://github.com/anza-xyz/kit/tree/main/packages/codecs-data-structures#nullable-codec) except that it encodes `Option<T>` types instead of `T | null` types.

@@ -233,2 +233,2 @@ Namely, it accepts a codec of type `T` and returns a codec of type `Option<T>`. Note that, when encoding, `T` or `null` may also be provided directly as input and will be interpreted as `Some(T)` or `None` respectively. However, when decoding, the output will always be an `Option<T>` type.

To read more about the available codecs and how to use them, check out the documentation of the main [`@solana/codecs` package](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs).
To read more about the available codecs and how to use them, check out the documentation of the main [`@solana/codecs` package](https://github.com/anza-xyz/kit/tree/main/packages/codecs).

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc