diff --git a/README.md b/README.md index 5df4d4c..d5a17b1 100644 --- a/README.md +++ b/README.md @@ -256,6 +256,7 @@ accepts an object with the filename as key and the svg data as key. | verbose | boolean | false | defines if the log should contain additional information. Can be useful for debugging | | generateType | boolean | true | defines if it's needed to generate type | | typeName | string | MyIconType | name of the type to be used when `generateType` is set to `true` | +| namePrefix | string | | prefix to be used for the name property included in the generated constant | #### Example usage @@ -302,6 +303,7 @@ Only the icons included in the consuming SPA also end up in the final bundle of | generateTypeObject | boolean | false | generate type object | | generateEnum | boolean | false | generate enum object | | prefix | string | myIcon | prefix for the generated svg constants | +| namePrefix | string | | prefix to be used for the name property included in the generated constant | | interfaceName | string | MyIcon | name for the generated interface | | fileName | string | my-icons | file name of the generated file | | enumName | string | MyIcons | name for the generated enum | @@ -396,6 +398,7 @@ end up there. | exportCompleteIconSet | boolean | false | Specifies if the complete icon set should be exported or not (can be very handy for showcases) | | completeIconSetName | string | completeIconSet | Name of the generated complete icon set (only effective if exportCompleteIconSet is set to true) | | prefix | string | myIcon | prefix for the generated svg constants | +| namePrefix | string | | prefix to be used for the name property included in the generated constant | | interfaceName | string | MyIcon | name for the generated interface | | modelFileName | string | my-icons | file name of the generated file | | enumName | string | MyIcons | name for the generated enum | diff --git a/src/lib/converters/shared.converter.ts b/src/lib/converters/shared.converter.ts index a3c7fe0..5d93e2d 100644 --- a/src/lib/converters/shared.converter.ts +++ b/src/lib/converters/shared.converter.ts @@ -16,7 +16,7 @@ export interface SvgDefinition { } export const filesProcessor = async (conversionOptions): Promise => { - const { prefix, delimiter, interfaceName, srcFiles, svgoConfig } = conversionOptions; + const { prefix, delimiter, interfaceName, srcFiles, svgoConfig, namePrefix } = conversionOptions; const filePaths = await getFilePathsFromRegex(srcFiles); if (!filePaths.length) { @@ -36,7 +36,7 @@ export const filesProcessor = async (conversionOptions): Promise { }); }); + describe('generateTypeName with prefix', () => { + it('should return the correct type name with delimiter SNAKE', () => { + const fileName = 'chevron-top'; + expect(generateTypeName(fileName, Delimiter.SNAKE, 'example-')).toEqual('example-chevron_top'); + }); + + it('should return the correct type name with delimiter CAMEL', () => { + const fileName = 'chevron-top'; + expect(generateTypeName(fileName, Delimiter.CAMEL, 'example-')).toEqual('example-chevronTop'); + }); + + it('should return the correct type name with delimiter KEBAB', () => { + const fileName = 'chevron_top'; + expect(generateTypeName(fileName, Delimiter.KEBAB, 'example-')).toEqual('example-chevron-top'); + }); + + it('should return the correct type name with delimiter UPPER', () => { + const fileName = 'chevron-top'; + expect(generateTypeName(fileName, Delimiter.UPPER, 'example-')).toEqual('example-CHEVRON_TOP'); + }); + }); + describe('generateVariableName', () => { it('should return the correct variable name', () => { const prefix = ''; diff --git a/src/lib/generators/code-snippet-generators.ts b/src/lib/generators/code-snippet-generators.ts index b90e3d4..57558c1 100644 --- a/src/lib/generators/code-snippet-generators.ts +++ b/src/lib/generators/code-snippet-generators.ts @@ -124,17 +124,17 @@ export const generateExportStatement = (fileName: string, generatedIconsFolderNa export const generateNamedImportStatement = (name: string, module: string): string => `import {${name}} from '${module}';\n`; -export const generateTypeName = (filenameWithoutEnding, delimiter: Delimiter): string => { +export const generateTypeName = (filenameWithoutEnding, delimiter: Delimiter, namePrefix?: string): string => { if (delimiter === Delimiter.CAMEL) { - return `${camelCase(filenameWithoutEnding)}`; + return `${namePrefix || ''}${camelCase(filenameWithoutEnding)}`; } if (delimiter === Delimiter.KEBAB) { - return `${kebabCase(filenameWithoutEnding)}`; + return `${namePrefix || ''}${kebabCase(filenameWithoutEnding)}`; } if (delimiter === Delimiter.UPPER) { - return `${snakeCase(filenameWithoutEnding).toUpperCase()}`; + return `${namePrefix || ''}${snakeCase(filenameWithoutEnding).toUpperCase()}`; } - return `${snakeCase(filenameWithoutEnding)}`; + return `${namePrefix || ''}${snakeCase(filenameWithoutEnding)}`; }; export const generateVariableName = (prefix: string, filenameWithoutEnding): string => { diff --git a/src/lib/options/conversion-options/constant-conversion-options.ts b/src/lib/options/conversion-options/constant-conversion-options.ts index 9242c71..183871d 100644 --- a/src/lib/options/conversion-options/constant-conversion-options.ts +++ b/src/lib/options/conversion-options/constant-conversion-options.ts @@ -17,5 +17,6 @@ export interface ConstantsConversionOptions { exportCompleteIconSet?: boolean; completeIconSetName: string; prefix?: string; + namePrefix?: string; interfaceName?: string; } diff --git a/src/lib/options/conversion-options/files-conversion-options.ts b/src/lib/options/conversion-options/files-conversion-options.ts index a6611f7..d6c610f 100644 --- a/src/lib/options/conversion-options/files-conversion-options.ts +++ b/src/lib/options/conversion-options/files-conversion-options.ts @@ -21,6 +21,7 @@ export interface FilesConversionOptions { exportCompleteIconSet?: boolean; completeIconSetName?: string; prefix?: string; + namePrefix?: string; interfaceName?: string; enumName?: string; modelFileName?: string; diff --git a/src/lib/options/conversion-options/object-conversion-options.ts b/src/lib/options/conversion-options/object-conversion-options.ts index c721654..62420c7 100644 --- a/src/lib/options/conversion-options/object-conversion-options.ts +++ b/src/lib/options/conversion-options/object-conversion-options.ts @@ -12,4 +12,5 @@ export interface ObjectConversionOptions { objectName?: string; typeName?: string; generateType?: boolean; + namePrefix?: string; }