diff --git a/lib/schematics/schematic.option.ts b/lib/schematics/schematic.option.ts index 51ff195f5..83bdfb53f 100644 --- a/lib/schematics/schematic.option.ts +++ b/lib/schematics/schematic.option.ts @@ -1,3 +1,5 @@ +import { dasherize } from '../utils/formatting'; + export class SchematicOption { constructor(private name: string, private value: boolean | string) {} @@ -11,15 +13,15 @@ export class SchematicOption { return `--${this.name}="${this.value}"`; } } else if (typeof this.value === 'boolean') { - const str = this.dasherize(this.name); + const str = dasherize(this.name); return this.value ? `--${str}` : `--no-${str}`; } else { - return `--${this.dasherize(this.name)}=${this.value}`; + return `--${dasherize(this.name)}=${this.value}`; } } private format() { - return this.dasherize(this.value as string) + return dasherize(this.value as string) .split('') .reduce((content, char) => { if (char === '(' || char === ')' || char === '[' || char === ']') { @@ -28,13 +30,4 @@ export class SchematicOption { return `${content}${char}`; }, ''); } - - private dasherize(str: string) { - const STRING_DASHERIZE_REGEXP = /[\s]/g; - const STRING_DECAMELIZE_REGEXP = /([a-z\d])([A-Z])/g; - return str - .replace(STRING_DECAMELIZE_REGEXP, '$1-$2') - .toLowerCase() - .replace(STRING_DASHERIZE_REGEXP, '-'); - } } diff --git a/lib/utils/formatting.ts b/lib/utils/formatting.ts new file mode 100644 index 000000000..fe2f9454b --- /dev/null +++ b/lib/utils/formatting.ts @@ -0,0 +1,8 @@ +export function dasherize(str: string) { + const STRING_DASHERIZE_REGEXP = /[\s]/g; + const STRING_DECAMELIZE_REGEXP = /([a-z\d])([A-Z])/g; + return str + .replace(STRING_DECAMELIZE_REGEXP, '$1-$2') + .toLowerCase() + .replace(STRING_DASHERIZE_REGEXP, '-'); +}