MCPcopy Create free account
hub / github.com/formkit/formkit / transformSource

Function transformSource

packages/cli/src/exportInput.ts:114–139  ·  view source on GitHub ↗

* Transforms the source code of the inputs to be used locally. * @param exportData - The code to export. * @returns

(exportData: string, type: string)

Source from the content-addressed store, hash-verified

112 * @returns
113 */
114function transformSource(exportData: string, type: string): string | never {
115 if (exportData) {
116 // Change the exports from relative to npm package based.
117 exportData = exportData.replace(
118 /(}\sfrom\s['"])\.\.\/(?:index(?:\.mjs)?)?(['"])?/g,
119 '$1@formkit/inputs$2'
120 )
121 const memoKey = token()
122 exportData = exportData.replace(
123 /(schemaMemoKey:\s?['"])[a-zA-Z0-9]+(['"])/g,
124 `$1${memoKey}$2`
125 )
126 // Inject the forceTypeProp in the definition.
127 exportData = exportData.replace(
128 /^ props: \[(.*)\],/gm,
129 ` props: [$1],
130 /**
131 * Forces node.props.type to be this explicit value.
132 */
133 forceTypeProp: '${type}',`
134 )
135 } else {
136 error('Unable to export the input file because it cannot be located.')
137 }
138 return exportData
139}
140
141/**
142 * Determine the language the user wants to export.

Callers 1

exportInputFunction · 0.85

Calls 2

tokenFunction · 0.90
errorFunction · 0.90

Tested by

no test coverage detected