Skip to content

Commit

Permalink
feat(type): generate the types with the correct delimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
nivekcode committed Dec 30, 2019
1 parent a8b840b commit c6d1ebc
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/lib/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ export enum Delimiter {
SNAKE = 'SNAKE'
}

const getType = (filenameWithoutEnding, typesDelimitor: string, delimiter: Delimiter): string => {
if (delimiter === Delimiter.CAMEL) {
return `'${camelCase(filenameWithoutEnding)}'${typesDelimitor}`;
}
if (delimiter === Delimiter.KEBAB) {
return `'${kebapCase(filenameWithoutEnding)}'${typesDelimitor}`;
}
return `'${snakeCase(filenameWithoutEnding)}'${typesDelimitor}`;
};

export const convert = async (convertionOptions: ConvertionOptions): Promise<void> => {
let svgConstants = '';

Expand Down Expand Up @@ -71,13 +61,9 @@ export const convert = async (convertionOptions: ConvertionOptions): Promise<voi
const rawSvg = await extractSvgContent(fileNameWithEnding, directoryPath);
const optimizedSvg = await svgo.optimize(rawSvg);
const variableName = getVariableName(convertionOptions, filenameWithoutEnding);
types += getType(filenameWithoutEnding, typesDelimitor, convertionOptions.delimiter);
svgConstants += getSvgConstant(
variableName,
convertionOptions.interfaceName,
snakeCase(filenameWithoutEnding),
optimizedSvg.data
);
const typeName = getTypeName(filenameWithoutEnding, convertionOptions.delimiter);
types += `'${typeName}'${typesDelimitor}`;
svgConstants += getSvgConstant(variableName, convertionOptions.interfaceName, typeName, optimizedSvg.data);
}
}
types = types.substring(0, types.length - typesDelimitor.length) + ';';
Expand All @@ -93,6 +79,16 @@ export const convert = async (convertionOptions: ConvertionOptions): Promise<voi
}
};

const getTypeName = (filenameWithoutEnding, delimiter: Delimiter): string => {
if (delimiter === Delimiter.CAMEL) {
return `${camelCase(filenameWithoutEnding)}`;
}
if (delimiter === Delimiter.KEBAB) {
return `${kebapCase(filenameWithoutEnding)}`;
}
return `${snakeCase(filenameWithoutEnding)}`;
};

const generateFileContent = (svgContstants: string, types: string, convertionOptions: ConvertionOptions): string => {
const fileContent = (svgContstants += types += getInterfaceDefinition(
convertionOptions.interfaceName,
Expand Down

0 comments on commit c6d1ebc

Please sign in to comment.