@azure-tools/codegen
Advanced tools
Comparing version 2.1.230 to 2.1.231
@@ -39,2 +39,4 @@ import { TextPossibilities } from './file-generator'; | ||
export declare function convert(num: number): Iterable<string>; | ||
export declare type formatter = ((identifier: string | string[], removeDuplicates?: boolean | undefined) => string); | ||
export declare function formatStyle(style: any, fallback: formatter): formatter; | ||
export declare function fixLeadingNumber(identifier: Array<string>): Array<string>; | ||
@@ -44,4 +46,8 @@ export declare function removeProhibitedPrefix(identifier: string, prohibitedPrefix: string, skipIdentifiers?: Array<string>): string; | ||
export declare function removeSequentialDuplicates(identifier: Iterable<string>): string[]; | ||
export declare function kebabCase(identifier: string | Array<string>, removeDuplicates?: boolean): string; | ||
export declare function snakeCase(identifier: string | Array<string>, removeDuplicates?: boolean): string; | ||
export declare function upperCase(identifier: string | Array<string>, removeDuplicates?: boolean): string; | ||
export declare function normalize(identifier: string | Array<string>, removeDuplicates?: boolean): Array<string>; | ||
export declare function pascalCase(identifier: string | Array<string>, removeDuplicates?: boolean): string; | ||
export declare function camelCase(identifier: string | Array<string>): string; | ||
export declare function camelCase(identifier: string | Array<string>, removeDuplicates?: boolean): string; | ||
export declare function getPascalIdentifier(name: string): string; | ||
@@ -48,0 +54,0 @@ export declare function escapeString(text: string | undefined): string; |
@@ -199,2 +199,14 @@ "use strict"; | ||
exports.convert = convert; | ||
function formatStyle(style, fallback) { | ||
switch (`${style}`.toLowerCase()) { | ||
case 'camelcase': | ||
return camelCase; | ||
case 'pascalcase': | ||
return pascalCase; | ||
case 'snakecase': | ||
return snakeCase; | ||
} | ||
return fallback; | ||
} | ||
exports.formatStyle = formatStyle; | ||
function fixLeadingNumber(identifier) { | ||
@@ -241,23 +253,31 @@ if (identifier.length > 0 && /^\d+/.exec(identifier[0])) { | ||
exports.removeSequentialDuplicates = removeSequentialDuplicates; | ||
function kebabCase(identifier, removeDuplicates = true) { | ||
return normalize(identifier, removeDuplicates).join('-'); | ||
} | ||
exports.kebabCase = kebabCase; | ||
function snakeCase(identifier, removeDuplicates = true) { | ||
return normalize(identifier, removeDuplicates).join('_'); | ||
} | ||
exports.snakeCase = snakeCase; | ||
function upperCase(identifier, removeDuplicates = true) { | ||
return normalize(identifier, removeDuplicates).join('_').toUpperCase(); | ||
} | ||
exports.upperCase = upperCase; | ||
function normalize(identifier, removeDuplicates = true) { | ||
if (!identifier || identifier.length === 0) { | ||
return ['']; | ||
} | ||
return removeDuplicates ? removeSequentialDuplicates(fixLeadingNumber(deconstruct(identifier))) : fixLeadingNumber(deconstruct(identifier)); | ||
} | ||
exports.normalize = normalize; | ||
function pascalCase(identifier, removeDuplicates = true) { | ||
return identifier === undefined ? '' : typeof identifier === 'string' ? | ||
pascalCase(fixLeadingNumber(deconstruct(identifier)), removeDuplicates) : | ||
(removeDuplicates ? [...removeSequentialDuplicates(identifier)] : identifier).map(each => each.capitalize()).join(''); | ||
return normalize(identifier, removeDuplicates).map(each => each.capitalize()).join(''); | ||
} | ||
exports.pascalCase = pascalCase; | ||
function camelCase(identifier) { | ||
if (typeof (identifier) === 'string') { | ||
return camelCase(fixLeadingNumber(deconstruct(identifier))); | ||
} | ||
switch (identifier.length) { | ||
case 0: | ||
return ''; | ||
case 1: | ||
return identifier[0].uncapitalize(); | ||
} | ||
return `${identifier[0].uncapitalize()}${pascalCase(identifier.slice(1))}`; | ||
function camelCase(identifier, removeDuplicates = true) { | ||
return normalize(identifier, removeDuplicates).map((each, index) => index ? each.capitalize() : each.uncapitalize()).join(''); | ||
} | ||
exports.camelCase = camelCase; | ||
function getPascalIdentifier(name) { | ||
return pascalCase(fixLeadingNumber(deconstruct(name))); | ||
return pascalCase(name); | ||
} | ||
@@ -264,0 +284,0 @@ exports.getPascalIdentifier = getPascalIdentifier; |
{ | ||
"name": "@azure-tools/codegen", | ||
"version": "2.1.230", | ||
"version": "2.1.231", | ||
"patchOffset": 100, | ||
@@ -5,0 +5,0 @@ "description": "Autorest Code generator common and base classes", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
194442
2468