diff --git a/packages/angular/src/schematics/ngrx/creator-files/__directory__/__fileName__.facade.spec.ts__tmpl__ b/packages/angular/src/schematics/ngrx/creator-files/__directory__/__fileName__.facade.spec.ts__tmpl__ index 994397aedd485..e914403b734e7 100644 --- a/packages/angular/src/schematics/ngrx/creator-files/__directory__/__fileName__.facade.spec.ts__tmpl__ +++ b/packages/angular/src/schematics/ngrx/creator-files/__directory__/__fileName__.facade.spec.ts__tmpl__ @@ -14,7 +14,7 @@ import { <%= className %>Facade } from './<%= fileName %>.facade'; import * as <%= className %>Selectors from './<%= fileName %>.selectors'; import * as <%= className %>Actions from './<%= fileName %>.actions'; import { - <%= className.toUpperCase() %>_FEATURE_KEY, + <%= constantName %>_FEATURE_KEY, State, initialState, reducer @@ -41,7 +41,7 @@ describe('<%= className %>Facade', () => { beforeEach(() => { @NgModule({ imports: [ - StoreModule.forFeature(<%= className.toUpperCase() %>_FEATURE_KEY, reducer), + StoreModule.forFeature(<%= constantName %>_FEATURE_KEY, reducer), EffectsModule.forFeature([<%= className %>Effects]) ], providers: [<%= className %>Facade] diff --git a/packages/angular/src/schematics/ngrx/creator-files/__directory__/__fileName__.reducer.ts__tmpl__ b/packages/angular/src/schematics/ngrx/creator-files/__directory__/__fileName__.reducer.ts__tmpl__ index 7174b7b44b3e1..a1b2552eee2fd 100644 --- a/packages/angular/src/schematics/ngrx/creator-files/__directory__/__fileName__.reducer.ts__tmpl__ +++ b/packages/angular/src/schematics/ngrx/creator-files/__directory__/__fileName__.reducer.ts__tmpl__ @@ -4,7 +4,7 @@ import { EntityState, EntityAdapter, createEntityAdapter } from '@ngrx/entity'; import * as <%= className %>Actions from './<%= fileName %>.actions'; import { <%= className %>Entity } from './<%= fileName %>.models'; -export const <%= className.toUpperCase() %>_FEATURE_KEY = '<%= propertyName %>'; +export const <%= constantName %>_FEATURE_KEY = '<%= propertyName %>'; export interface State extends EntityState<<%= className %>Entity> { selectedId ?: string | number; // which <%= className %> record has been selected @@ -13,7 +13,7 @@ export interface State extends EntityState<<%= className %>Entity> { } export interface <%= className %>PartialState { - readonly [<%= className.toUpperCase() %>_FEATURE_KEY]: State; + readonly [<%= constantName %>_FEATURE_KEY]: State; } export const <%= propertyName %>Adapter: EntityAdapter<<%= className %>Entity> = createEntityAdapter<<%= className %>Entity>(); diff --git a/packages/angular/src/schematics/ngrx/creator-files/__directory__/__fileName__.selectors.ts__tmpl__ b/packages/angular/src/schematics/ngrx/creator-files/__directory__/__fileName__.selectors.ts__tmpl__ index 7b4c67bb4ac33..df5ae3c2b0712 100644 --- a/packages/angular/src/schematics/ngrx/creator-files/__directory__/__fileName__.selectors.ts__tmpl__ +++ b/packages/angular/src/schematics/ngrx/creator-files/__directory__/__fileName__.selectors.ts__tmpl__ @@ -1,5 +1,5 @@ import { createFeatureSelector, createSelector } from '@ngrx/store'; -import { <%= className.toUpperCase() %>_FEATURE_KEY, State, <%= className %>PartialState, <%= propertyName %>Adapter } from './<%= fileName %>.reducer'; +import { <%= constantName %>_FEATURE_KEY, State, <%= className %>PartialState, <%= propertyName %>Adapter } from './<%= fileName %>.reducer'; // Lookup the '<%= className %>' feature state managed by NgRx export const get<%= className %>State = createFeatureSelector<<%= className %>PartialState, State>(<%= propertyName.toUpperCase() %>_FEATURE_KEY); diff --git a/packages/angular/src/schematics/ngrx/files/__directory__/__fileName__.reducer.ts__tmpl__ b/packages/angular/src/schematics/ngrx/files/__directory__/__fileName__.reducer.ts__tmpl__ index ef6bd3c2827c2..536ed8e061251 100644 --- a/packages/angular/src/schematics/ngrx/files/__directory__/__fileName__.reducer.ts__tmpl__ +++ b/packages/angular/src/schematics/ngrx/files/__directory__/__fileName__.reducer.ts__tmpl__ @@ -1,6 +1,6 @@ import { <%= className %>Action, <%= className %>ActionTypes } from './<%= fileName %>.actions'; -export const <%= className.toUpperCase() %>_FEATURE_KEY = '<%= propertyName %>'; +export const <%= constantName %>_FEATURE_KEY = '<%= propertyName %>'; /** * Interface for the '<%= className %>' data used in @@ -21,7 +21,7 @@ export interface <%= className %>State { }; export interface <%= className %>PartialState { - readonly [<%= className.toUpperCase() %>_FEATURE_KEY]: <%= className %>State; + readonly [<%= constantName %>_FEATURE_KEY]: <%= className %>State; } export const initialState: <%= className %>State = { diff --git a/packages/angular/src/schematics/ngrx/files/__directory__/__fileName__.selectors.ts__tmpl__ b/packages/angular/src/schematics/ngrx/files/__directory__/__fileName__.selectors.ts__tmpl__ index f04c67a64e30e..36d77490e9751 100644 --- a/packages/angular/src/schematics/ngrx/files/__directory__/__fileName__.selectors.ts__tmpl__ +++ b/packages/angular/src/schematics/ngrx/files/__directory__/__fileName__.selectors.ts__tmpl__ @@ -1,5 +1,5 @@ import { createFeatureSelector, createSelector } from '@ngrx/store'; -import { <%= className.toUpperCase() %>_FEATURE_KEY, <%= className %>State } from './<%= fileName %>.reducer'; +import { <%= constantName %>_FEATURE_KEY, <%= className %>State } from './<%= fileName %>.reducer'; // Lookup the '<%= className %>' feature state managed by NgRx const get<%= className %>State = createFeatureSelector<<%= className %>State>(<%= propertyName.toUpperCase() %>_FEATURE_KEY); diff --git a/packages/workspace/src/utils/name-utils.ts b/packages/workspace/src/utils/name-utils.ts index aefebb8d08d75..4777401fb09e8 100644 --- a/packages/workspace/src/utils/name-utils.ts +++ b/packages/workspace/src/utils/name-utils.ts @@ -9,25 +9,27 @@ export function names( name: string; className: string; propertyName: string; + constantName: string; fileName: string; } { return { name, className: toClassName(name), propertyName: toPropertyName(name), + constantName: toConstantName(name), fileName: toFileName(name), }; } /** - * hypenated to UpperCamelCase + * Hyphenated to UpperCamelCase */ export function toClassName(str: string): string { return toCapitalCase(toPropertyName(str)); } /** - * Hypenated to lowerCamelCase + * Hyphenated to lowerCamelCase */ export function toPropertyName(s: string): string { return s @@ -39,7 +41,14 @@ export function toPropertyName(s: string): string { } /** - * Upper camelCase to lowercase, hypenated + * Hyphenated to CONSTANT_CASE + */ +function toConstantName(s: string): string { + return s.replace(/(-|_|\.|\s)/g, '_').toUpperCase(); +} + +/** + * Upper camelCase to lowercase, hyphenated */ export function toFileName(s: string): string { return s @@ -48,6 +57,9 @@ export function toFileName(s: string): string { .replace(/[ _]/g, '-'); } +/** + * Capitalizes the first letter of a string + */ function toCapitalCase(s: string): string { return s.charAt(0).toUpperCase() + s.substr(1); }