EXCTUENT with the initialization of the Legacy

anchoring

Solana Explorer, a popular platform for access and management of the anchor blockchain, was an experience with an initial IDL inheritance in the SDK Typescript. The third parties of the beast relationship are “sub-feeding is not an object (” split “evaluation)”

This is what the name of Explorer.solana.com is the name of a Camelcase format, but has requested from some old IDLs. The problem lies in the way Typescript manages theSplit () method in case.

The problem:

When the domain name is converted to Catetella, the typographers are Afti to make the methods Split () an element like Sier. However, when explorer.solana.com is not a vaid string (i.e. it does no space), split () account of your array only one element. In this case,Under-Fined is registered instantaneous by your object.

The solution:

To solve this problem, you are different from the advertising of the appointments The domain name in Catelcase. A way to do this is by regular expression (regex) in your typewritten code.

Here is an updated example that the regex doors to make them:

`CRIPT type

import * as ts from 'tyscript';

// assuming the following IDL to West:

Const Exploseridl =

// This is an anchoring IDL of example.

// will be converted into Camelcase in this way: "Explorer.solana.com" -> "explorer.solana.com"

;

Functional ConvertctoCoccase (IDL: string): string

Const Parser = ts.createparser (IDL);

Const Branchfile = TS.CreateSourcefile ('Idl.ts', IDL, TS.Scriparget.es2015);

Let Camelcaseidl = '';

For (Const Token Off Parser.Gettokens (Sourcefile)) {

IF (TS. ISCANIANTIFIER (TOKEN) &&! Token.value.startswith ('_')) {

Camelcaseidl += token.name;

} Else If (Ts.strintaltal (token)) {

Const Regex = New Regexp (Token.value.replace (/([a-z]) | ([a-z])/g, ‘$ 1 $ 1’)}, ‘u’);

Let Match: regexpexecarray | zero;

While ((match = regex.exec (token.value))! == zero) {

Camelcaseidl += match [0] [0].

}

} Else If (Ts.is.

Camelcaseidl += ConvertctoCoccalecase (token.espression);

}

}

a return Camelcaseidl;

}

Console.log (Convertctocelcase (Exploreridl)));

`re

Updedex Intensive,Converttocamelcase ()if it is an identifier, simply add the name to their string IDL Camelase. If it is a literal of the string, it does not squeeze the Sami regex and then adds for the first.

Conclusion:

The original code can be resolved by regular expression in the Typescript to convert the domain name to the cover. This ardent approach that is correct is returned, eliminating the “sub-diet is not an object” differs.

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *