-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(deps-dev): bump @ember/string from 3.1.1 to 4.0.0 (#394)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: MrChocolatine <[email protected]>
- Loading branch information
1 parent
674aa44
commit 277d2b8
Showing
6 changed files
with
168 additions
and
123 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
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,46 @@ | ||
/** | ||
* The content of this file was partially copied-pasted from: | ||
* https://github.com/emberjs/ember-string/blob/v4.0.0-%40ember/string/src/index.ts | ||
*/ | ||
|
||
const STRING_CLASSIFY_REGEXP_1 = /^(-|_)+(.)?/ | ||
const STRING_CLASSIFY_REGEXP_2 = /(.)(-|_|\.|\s)+(.)?/g | ||
const STRING_CLASSIFY_REGEXP_3 = /(^|\/|\.)([a-z])/g | ||
|
||
function CLASSIFY_CACHE(str: string) { | ||
const replace1 = (_match: string, _separator: string, chr: string) => | ||
chr ? `_${chr.toUpperCase()}` : '' | ||
|
||
const replace2 = (_match: string, initialChar: string, _separator: string, chr: string) => | ||
initialChar + (chr ? chr.toUpperCase() : '') | ||
|
||
const parts = str.split('/') | ||
|
||
for (let i = 0; i < parts.length; i++) { | ||
parts[i] = (parts[i] ?? '') | ||
.replace(STRING_CLASSIFY_REGEXP_1, replace1) | ||
.replace(STRING_CLASSIFY_REGEXP_2, replace2) | ||
} | ||
|
||
return parts | ||
.join('/') | ||
.replace(STRING_CLASSIFY_REGEXP_3, (match /*, separator, chr */) => match.toUpperCase()) | ||
} | ||
|
||
/** | ||
* Returns the UpperCamelCase form of a string. | ||
* | ||
* ```javascript | ||
* classify('innerHTML'); // 'InnerHTML' | ||
* classify('action_name'); // 'ActionName' | ||
* classify('css-class-name'); // 'CssClassName' | ||
* classify('my favorite items'); // 'MyFavoriteItems' | ||
* classify('private-docs/owner-invoice'); // 'PrivateDocs/OwnerInvoice' | ||
* ``` | ||
* | ||
* @param {string} str the string to classify | ||
* @return {string} the classified string | ||
*/ | ||
export function classify(str: string): string { | ||
return CLASSIFY_CACHE(str) | ||
} |
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
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,105 @@ | ||
/** | ||
* The content of this file was extracted (then adapted) from: | ||
* https://github.com/emberjs/ember-string/blob/v4.0.0-%40ember/string/tests/unit/classify_test.ts | ||
*/ | ||
|
||
import { classify } from 'ember-cli-embedded/utils/classify' | ||
import { module, test } from 'qunit' | ||
|
||
module('Unit | Utility | classify', function () { | ||
test('it works', function (assert) { | ||
assert.strictEqual( | ||
classify('my favorite items'), | ||
'MyFavoriteItems', | ||
'classify normal string', | ||
/* */ | ||
) | ||
|
||
assert.strictEqual( | ||
classify('css-class-name'), | ||
'CssClassName', | ||
'classify dasherized string', | ||
/* */ | ||
) | ||
|
||
assert.strictEqual( | ||
classify('action_name'), | ||
'ActionName', | ||
'classify underscored string', | ||
/* */ | ||
) | ||
|
||
assert.strictEqual( | ||
classify('privateDocs/ownerInvoice'), | ||
'PrivateDocs/OwnerInvoice', | ||
'classify namespaced camelized string', | ||
) | ||
|
||
assert.strictEqual( | ||
classify('private_docs/owner_invoice'), | ||
'PrivateDocs/OwnerInvoice', | ||
'classify namespaced underscored string', | ||
) | ||
|
||
assert.strictEqual( | ||
classify('private-docs/owner-invoice'), | ||
'PrivateDocs/OwnerInvoice', | ||
'classify namespaced dasherized string', | ||
) | ||
|
||
assert.strictEqual( | ||
classify('-view-registry'), | ||
'_ViewRegistry', | ||
'classify prefixed dasherized string', | ||
) | ||
|
||
assert.strictEqual( | ||
classify('components/-text-field'), | ||
'Components/_TextField', | ||
'classify namespaced prefixed dasherized string', | ||
) | ||
|
||
assert.strictEqual( | ||
classify('_Foo_Bar'), | ||
'_FooBar', | ||
'classify underscore-prefixed underscored string', | ||
) | ||
|
||
assert.strictEqual( | ||
classify('_Foo-Bar'), | ||
'_FooBar', | ||
'classify underscore-prefixed dasherized string', | ||
) | ||
|
||
assert.strictEqual( | ||
classify('_foo/_bar'), | ||
'_Foo/_Bar', | ||
'classify underscore-prefixed-namespaced underscore-prefixed string', | ||
) | ||
|
||
assert.strictEqual( | ||
classify('-foo/_bar'), | ||
'_Foo/_Bar', | ||
'classify dash-prefixed-namespaced underscore-prefixed string', | ||
) | ||
|
||
assert.strictEqual( | ||
classify('-foo/-bar'), | ||
'_Foo/_Bar', | ||
'classify dash-prefixed-namespaced dash-prefixed string', | ||
) | ||
|
||
assert.strictEqual( | ||
/* */ | ||
classify('InnerHTML'), | ||
'InnerHTML', | ||
'does nothing with classified string', | ||
) | ||
|
||
assert.strictEqual( | ||
classify('_FooBar'), | ||
'_FooBar', | ||
'does nothing with classified prefixed string', | ||
) | ||
}) | ||
}) |
Oops, something went wrong.