Skip to content

Commit f00a448

Browse files
Remove @ember/string dependency
1 parent ed30a88 commit f00a448

File tree

13 files changed

+145
-17
lines changed

13 files changed

+145
-17
lines changed

addon/components/api/x-class/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Component from '@glimmer/component';
22
import { tracked } from '@glimmer/tracking';
33
import { or } from '@ember/object/computed';
4-
import { capitalize } from '@ember/string';
4+
import { capitalize } from '../../../utils/string';
55
import { memberFilter } from '../../../utils/computed';
66
import { addonDocsConfig } from 'ember-cli-addon-docs/-private/config';
77

addon/components/api/x-component/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Component from '@glimmer/component';
22
import { tracked } from '@glimmer/tracking';
33
import { action } from '@ember/object';
44
import { alias, or } from '@ember/object/computed';
5-
import { capitalize } from '@ember/string';
5+
import { capitalize } from '../../../utils/string';
66
import { memberFilter } from '../../../utils/computed';
77

88
export default class XComponent extends Component {

addon/components/docs-header/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Component from '@glimmer/component';
22
import { tracked } from '@glimmer/tracking';
3-
import { classify } from '@ember/string';
3+
import { classify } from '../../utils/string';
44
import { addonPrefix } from 'ember-cli-addon-docs/utils/computed';
55
import { inject as service } from '@ember/service';
66
import { reads } from '@ember/object/computed';

addon/components/docs-hero/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
addonPrefix,
44
unprefixedAddonName,
55
} from 'ember-cli-addon-docs/utils/computed';
6-
import { classify } from '@ember/string';
6+
import { classify } from '../../utils/string';
77
import { addonDocsConfig } from 'ember-cli-addon-docs/-private/config';
88

99
/**

addon/components/docs-viewer/x-nav/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { inject as service } from '@ember/service';
22
import Component from '@glimmer/component';
33
import { tracked } from '@glimmer/tracking';
44
import { localCopy } from 'tracked-toolbox';
5-
import { classify } from '@ember/string';
5+
import { classify } from '../../../utils/string';
66
import { addonLogo } from 'ember-cli-addon-docs/utils/computed';
77
import { addonDocsConfig } from 'ember-cli-addon-docs/-private/config';
88

addon/helpers/capitalize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { helper } from '@ember/component/helper';
2-
import { capitalize } from '@ember/string';
2+
import { capitalize } from '../utils/string';
33

44
export default helper(function capitalizeHelper(positional) {
55
return capitalize(positional[0]);

addon/models/component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { attr } from '@ember-data/model';
22
import { filterBy, or } from '@ember/object/computed';
3-
import { dasherize } from '@ember/string';
3+
import { dasherize } from '../utils/string';
44

55
import Class from './class';
66
import { memberUnion, hasMemberType } from '../utils/computed';

addon/utils/computed.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { computed, get } from '@ember/object';
2-
import { capitalize } from '@ember/string';
2+
import { capitalize } from './string';
33

44
/**
55
@function initialize

addon/utils/string.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Capitalizes the first letter of a string
3+
* @param {string} str - The string to capitalize
4+
* @returns {string} The capitalized string
5+
*/
6+
export function capitalize(str) {
7+
if (!str || typeof str !== 'string') {
8+
return str;
9+
}
10+
return str.charAt(0).toUpperCase() + str.slice(1);
11+
}
12+
13+
/**
14+
* Converts a string to kebab-case (dasherized)
15+
* @param {string} str - The string to dasherize
16+
* @returns {string} The dasherized string
17+
*/
18+
export function dasherize(str) {
19+
if (!str || typeof str !== 'string') {
20+
return str;
21+
}
22+
return str
23+
.replace(/([a-z\d])([A-Z])/g, '$1-$2') // Add dash between camelCase
24+
.replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1-$2') // Handle consecutive capitals
25+
.replace(/[ _]/g, '-') // Replace spaces and underscores with dashes
26+
.toLowerCase();
27+
}
28+
29+
/**
30+
* Converts a string to PascalCase (classified)
31+
* @param {string} str - The string to classify
32+
* @returns {string} The classified string
33+
*/
34+
export function classify(str) {
35+
if (!str || typeof str !== 'string') {
36+
return str;
37+
}
38+
39+
// If the string contains separators (spaces, dashes, underscores), split and classify
40+
if (/[\s_-]/.test(str)) {
41+
return str
42+
.split(/[\s_-]+/)
43+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
44+
.join('');
45+
}
46+
47+
// Otherwise, just capitalize the first letter (preserve camelCase like innerHTML -> InnerHTML)
48+
return str.charAt(0).toUpperCase() + str.slice(1);
49+
}

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@
107107
"@ember-data/serializer": "^5.8.0",
108108
"@ember-data/store": "^5.8.0",
109109
"@ember/optional-features": "^2.3.0",
110-
"@ember/string": "^3.1.1",
111110
"@ember/test-helpers": "^3.3.1",
112111
"@ember/test-waiters": "^3.1.0",
113112
"@embroider/test-setup": "^3.0.3",
@@ -164,7 +163,6 @@
164163
"@ember-data/model": ">= 3.0.0",
165164
"@ember-data/serializer": ">= 3.0.0",
166165
"@ember-data/store": ">= 3.0.0",
167-
"@ember/string": "^3.1.1 || ^4.0.0",
168166
"@ember/test-waiters": "^3.1.0 || ^4.0.0",
169167
"ember-data": ">= 3.0.0",
170168
"ember-inflector": ">= 4.0.0",

0 commit comments

Comments
 (0)