Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wrappers to easily convert between ScVal and native types. #630

Merged
merged 22 commits into from
Jun 26, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Clarify docs on types
  • Loading branch information
Shaptic committed Jun 26, 2023
commit b9a44b2320d44933c1b593990c6a98c4bf6ac7cd
14 changes: 9 additions & 5 deletions src/scval.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ import { XdrLargeInt, ScInt, scValToBigInt } from './numbers/index';
* xdr.ScVal (recursively). note that there is no restriction on types
* matching anywhere (unlike arrays)
*
* You can also optionally specify a type which will force a particular
* interpretation of the given object. Note that this is a "single-level"
* interpretation. It's useful when specifying e.g. integer `ScVal`s (see
* {@link ScInt}) or if you want e.g. a string to be a symbol.
* When passing an integer-like native value, you can also optionally specify a
* type which will force a particular interpretation of that value.
*
* Note that not all type specifications are compatible with all `ScVal`s, e.g.
* `toScVal("string", {type: i256})` will throw.
*
* @param {any} val a native (or convertible) input value to wrap
* @param {any} val a native (or convertible) input value to wrap
* @param {object} [opts] an optional set of options to pass which allows you
* to specify a type when the native `val` is an integer-like (i.e.
* number|bigint) type
*
* @returns {xdr.ScVal} a wrapped, smart, XDR version of the input value
*
Expand All @@ -81,6 +82,9 @@ import { XdrLargeInt, ScInt, scValToBigInt } from './numbers/index';
* types, custom classes)
* - the type of the input object (or some inner value of said object) cannot
* be determined (via `typeof`)
*
* TODO: Allow users to force types that are not direct but can be translated,
* i.e. forcing a `Buffer` to be encoded as an ScSymbol or ScString.
*/
export function nativeToScVal(val, opts = {}) {
switch (typeof val) {
Expand Down