-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Narrowed usage to entity names in @codemod-utils/ember (#130)
* refactor: Reorganized files * breaking: Removed camelize() (unused) * chore: Updated tests to document correct usage * refactor: Simplified classify() and renamed it to pascalize() * refactor: Simplified doubleColonize() * feature: Created camelize() * refactor: Simplified pascalize() * chore: Simplified README * chore: Added changeset --------- Co-authored-by: ijlee2 <ijlee2@users.noreply.github.com>
- Loading branch information
Showing
30 changed files
with
254 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@codemod-utils/ember": major | ||
--- | ||
|
||
Narrowed usage to entity names, in order to remove dependency on ember-cli-string-utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { pascalize } from './pascalize.js'; | ||
|
||
/** | ||
* Converts an entity name to camel case. Used for naming the | ||
* function that is associated with the entity. | ||
* | ||
* @param entityName | ||
* | ||
* The name of an entity (made up of lowercase letters, hyphen, | ||
* and forward slash). | ||
* | ||
* @return | ||
* | ||
* The name in camel case. | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* const newValue = camelize('ui/form/generate-error-message'); | ||
* | ||
* // 'uiFormGenerateErrorMessage' | ||
* ``` | ||
*/ | ||
export function camelize(entityName: string): string { | ||
const pascalizedName = pascalize(entityName); | ||
|
||
return pascalizedName.charAt(0).toLowerCase() + pascalizedName.substring(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
function pascalize(value: string): string { | ||
return value | ||
.split('-') | ||
.map((token) => { | ||
return token.charAt(0).toUpperCase() + token.substring(1).toLowerCase(); | ||
}) | ||
.join(''); | ||
} | ||
|
||
/** | ||
* Converts an entity name to double colon (`::`) case. Used for | ||
* writing the angle bracket syntax or the signature for a component. | ||
* | ||
* @param entityName | ||
* | ||
* The name of an entity (made up of lowercase letters, hyphen, | ||
* and forward slash). | ||
* | ||
* @return | ||
* | ||
* The name in double colon case. | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* const newValue = doubleColonize('ui/form/input'); | ||
* | ||
* // 'Ui::Form::Input' | ||
* ``` | ||
*/ | ||
export function doubleColonize(entityName: string): string { | ||
return entityName.split('/').map(pascalize).join('::'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { doubleColonize } from './double-colonize.js'; | ||
|
||
/** | ||
* Converts an entity name to Pascal case. Used for naming the | ||
* class that is associated with the entity. | ||
* | ||
* @param entityName | ||
* | ||
* The name of an entity (made up of lowercase letters, hyphen, | ||
* and forward slash). | ||
* | ||
* @return | ||
* | ||
* The name in Pascal case. | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* const newValue = pascalize('ui/form/input'); | ||
* | ||
* // 'UiFormInput' | ||
* ``` | ||
*/ | ||
export function pascalize(entityName: string): string { | ||
const doubleColonizedName = doubleColonize(entityName); | ||
|
||
return doubleColonizedName.replaceAll('::', ''); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './entity-name/camelize.js'; | ||
export * from './entity-name/classify.js'; | ||
export * from './entity-name/double-colonize.js'; | ||
export * from './ember/entity-name/camelize.js'; | ||
export * from './ember/entity-name/double-colonize.js'; | ||
export * from './ember/entity-name/pascalize.js'; |
11 changes: 11 additions & 0 deletions
11
packages/ember/tests/ember/entity-name/camelize/base-case.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { assert, test } from '@codemod-utils/tests'; | ||
|
||
import { camelize } from '../../../../src/index.js'; | ||
|
||
test('utils | ember | entity-name | camelize > base case', function () { | ||
assert.strictEqual(camelize('hello'), 'hello'); | ||
|
||
assert.strictEqual(camelize('hello-world'), 'helloWorld'); | ||
|
||
assert.strictEqual(camelize('hello-world-123'), 'helloWorld123'); | ||
}); |
16 changes: 16 additions & 0 deletions
16
packages/ember/tests/ember/entity-name/camelize/nested.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { assert, test } from '@codemod-utils/tests'; | ||
|
||
import { camelize } from '../../../../src/index.js'; | ||
|
||
test('utils | ember | entity-name | camelize > nested', function () { | ||
assert.strictEqual(camelize('ui/form'), 'uiForm'); | ||
|
||
assert.strictEqual(camelize('ui/form/input'), 'uiFormInput'); | ||
|
||
assert.strictEqual(camelize('ui/form/submit-button'), 'uiFormSubmitButton'); | ||
|
||
assert.strictEqual( | ||
camelize('widgets/widget-3/tour-schedule/responsive-image'), | ||
'widgetsWidget3TourScheduleResponsiveImage', | ||
); | ||
}); |
21 changes: 21 additions & 0 deletions
21
packages/ember/tests/ember/entity-name/camelize/wrong-input.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { assert, test } from '@codemod-utils/tests'; | ||
|
||
import { camelize } from '../../../../src/index.js'; | ||
|
||
test('utils | ember | entity-name | camelize > wrong input', function () { | ||
assert.strictEqual(camelize(''), ''); | ||
|
||
assert.strictEqual(camelize('-'), ''); | ||
|
||
assert.strictEqual(camelize('/'), ''); | ||
|
||
assert.strictEqual(camelize('ui/'), 'ui'); | ||
|
||
assert.strictEqual(camelize('/ui'), 'ui'); | ||
|
||
assert.strictEqual(camelize('ui.form.input'), 'ui.form.input'); | ||
|
||
assert.strictEqual(camelize('ui_form_input'), 'ui_form_input'); | ||
|
||
assert.strictEqual(camelize('ui form input'), 'ui form input'); | ||
}); |
11 changes: 11 additions & 0 deletions
11
packages/ember/tests/ember/entity-name/double-colonize/base-case.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { assert, test } from '@codemod-utils/tests'; | ||
|
||
import { doubleColonize } from '../../../../src/index.js'; | ||
|
||
test('utils | ember | entity-name | double-colonize > base case', function () { | ||
assert.strictEqual(doubleColonize('hello'), 'Hello'); | ||
|
||
assert.strictEqual(doubleColonize('hello-world'), 'HelloWorld'); | ||
|
||
assert.strictEqual(doubleColonize('hello-world-123'), 'HelloWorld123'); | ||
}); |
16 changes: 16 additions & 0 deletions
16
packages/ember/tests/ember/entity-name/double-colonize/edge-case-empty-string.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { assert, test } from '@codemod-utils/tests'; | ||
|
||
import { doubleColonize } from '../../../../src/index.js'; | ||
|
||
test('utils | ember | entity-name | double-colonize > nested', function () { | ||
assert.strictEqual(doubleColonize('ui/form'), 'Ui::Form'); | ||
assert.strictEqual(doubleColonize('ui/form/input'), 'Ui::Form::Input'); | ||
assert.strictEqual( | ||
doubleColonize('ui/form/submit-button'), | ||
'Ui::Form::SubmitButton', | ||
); | ||
assert.strictEqual( | ||
doubleColonize('widgets/widget-3/tour-schedule/responsive-image'), | ||
'Widgets::Widget3::TourSchedule::ResponsiveImage', | ||
); | ||
}); |
21 changes: 21 additions & 0 deletions
21
packages/ember/tests/ember/entity-name/double-colonize/wrong-input.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { assert, test } from '@codemod-utils/tests'; | ||
|
||
import { doubleColonize } from '../../../../src/index.js'; | ||
|
||
test('utils | ember | entity-name | double-colonize > wrong input', function () { | ||
assert.strictEqual(doubleColonize(''), ''); | ||
|
||
assert.strictEqual(doubleColonize('-'), ''); | ||
|
||
assert.strictEqual(doubleColonize('/'), '::'); | ||
|
||
assert.strictEqual(doubleColonize('ui/'), 'Ui::'); | ||
|
||
assert.strictEqual(doubleColonize('/ui'), '::Ui'); | ||
|
||
assert.strictEqual(doubleColonize('ui.form.input'), 'Ui.form.input'); | ||
|
||
assert.strictEqual(doubleColonize('ui_form_input'), 'Ui_form_input'); | ||
|
||
assert.strictEqual(doubleColonize('ui form input'), 'Ui form input'); | ||
}); |
11 changes: 11 additions & 0 deletions
11
packages/ember/tests/ember/entity-name/pascalize/base-case.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { assert, test } from '@codemod-utils/tests'; | ||
|
||
import { pascalize } from '../../../../src/index.js'; | ||
|
||
test('utils | ember | entity-name | pascalize > base case', function () { | ||
assert.strictEqual(pascalize('hello'), 'Hello'); | ||
|
||
assert.strictEqual(pascalize('hello-world'), 'HelloWorld'); | ||
|
||
assert.strictEqual(pascalize('hello-world-123'), 'HelloWorld123'); | ||
}); |
16 changes: 16 additions & 0 deletions
16
packages/ember/tests/ember/entity-name/pascalize/nested.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { assert, test } from '@codemod-utils/tests'; | ||
|
||
import { pascalize } from '../../../../src/index.js'; | ||
|
||
test('utils | ember | entity-name | pascalize > nested', function () { | ||
assert.strictEqual(pascalize('ui/form'), 'UiForm'); | ||
|
||
assert.strictEqual(pascalize('ui/form/input'), 'UiFormInput'); | ||
|
||
assert.strictEqual(pascalize('ui/form/submit-button'), 'UiFormSubmitButton'); | ||
|
||
assert.strictEqual( | ||
pascalize('widgets/widget-3/tour-schedule/responsive-image'), | ||
'WidgetsWidget3TourScheduleResponsiveImage', | ||
); | ||
}); |
Oops, something went wrong.