1- import { getAllAccounts , getAllInstructionsWithSubs , getAllPrograms , isNode , VALUE_NODES } from '@codama/nodes' ;
1+ import {
2+ getAllAccounts ,
3+ getAllInstructionsWithSubs ,
4+ getAllPrograms ,
5+ isNode ,
6+ VALUE_NODES ,
7+ pascalCase ,
8+ snakeCase ,
9+ } from '@codama/nodes' ;
210import { RenderMap } from '@codama/renderers-core' ;
311import {
412 extendVisitor ,
@@ -114,13 +122,13 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) {
114122
115123 // TODO: assuming name of codama generated sdk to be {program_name}_program_sdk for now need to change it
116124 const codamaSdkName = options . sdkName
117- ? toSnakeCase ( options . sdkName )
118- : `${ toSnakeCase ( programName ) } _program_sdk` ;
125+ ? snakeCase ( options . sdkName )
126+ : `${ snakeCase ( programName ) } _program_sdk` ;
119127
120128 const accountParserImports = new ImportMap ( ) ;
121129
122130 accounts . forEach ( acc => {
123- accountParserImports . add ( `${ codamaSdkName } ::accounts::${ fromCamelToPascalCase ( acc . name ) } ` ) ;
131+ accountParserImports . add ( `${ codamaSdkName } ::accounts::${ pascalCase ( acc . name ) } ` ) ;
124132 } ) ;
125133
126134 const instructionParserImports = new ImportMap ( ) ;
@@ -135,7 +143,7 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) {
135143 let ixImports = '' ;
136144
137145 instructions . forEach ( ix => {
138- const ixPascalName = fromCamelToPascalCase ( ix . name ) ;
146+ const ixPascalName = pascalCase ( ix . name ) ;
139147 const ixAccounts = `${ ixPascalName } as ${ ixPascalName } IxAccounts` ;
140148 if ( ix . hasArgs ) {
141149 // Adding alias for IxData
@@ -191,23 +199,3 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) {
191199 v => recordLinkablesOnFirstVisitVisitor ( v , linkables ) ,
192200 ) ;
193201}
194-
195- export const fromCamelToPascalCase = ( str : string ) => {
196- return str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 ) ;
197- } ;
198-
199- export const toPascalCase = ( str : string ) => {
200- return str
201- . replace ( / (?: ^ \w | [ A - Z ] | \b \w ) / g, ( word , index ) => {
202- return index === 0 ? word . toUpperCase ( ) : word . toLowerCase ( ) ;
203- } )
204- . replace ( / \s + / g, '' ) ;
205- } ;
206-
207- export const toSnakeCase = ( str : string ) => {
208- return str
209- . replace ( / (?: ^ \w | [ A - Z ] | \b \w ) / g, ( word , index ) => {
210- return index === 0 ? word . toLowerCase ( ) : `_${ word . toLowerCase ( ) } ` ;
211- } )
212- . replace ( / \s + / g, '' ) ;
213- } ;
0 commit comments