Skip to content

Commit 3c6f529

Browse files
locksstefanpenner
authored andcommitted
remove deprecated loc
1 parent bf9edcd commit 3c6f529

File tree

8 files changed

+195
-194
lines changed

8 files changed

+195
-194
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import {
3333
decamelize,
3434
underscore
3535
w,
36-
loc,
3736
} from '@ember/string'
3837
```
3938

addon/helpers/loc.ts

Lines changed: 0 additions & 46 deletions
This file was deleted.

addon/index.js

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
/**
2+
@module ember
3+
@submodule ember-runtime
4+
*/
5+
import Cache from './cache';
6+
7+
const STRING_DASHERIZE_REGEXP = (/[ _]/g);
8+
9+
const STRING_DASHERIZE_CACHE = new Cache(1000, key => decamelize(key).replace(STRING_DASHERIZE_REGEXP, '-'));
10+
11+
const STRING_CAMELIZE_REGEXP_1 = (/(-|_|\.|\s)+(.)?/g);
12+
const STRING_CAMELIZE_REGEXP_2 = (/(^|\/)([A-Z])/g);
13+
14+
const CAMELIZE_CACHE = new Cache(1000, key => key.replace(STRING_CAMELIZE_REGEXP_1, (match, separator, chr) => chr ? chr.toUpperCase() : '').replace(STRING_CAMELIZE_REGEXP_2, (match/*, separator, chr*/) => match.toLowerCase()));
15+
16+
const STRING_CLASSIFY_REGEXP_1 = (/^(-|_)+(.)?/);
17+
const STRING_CLASSIFY_REGEXP_2 = (/(.)(-|_|\.|\s)+(.)?/g);
18+
const STRING_CLASSIFY_REGEXP_3 = (/(^|\/|\.)([a-z])/g);
19+
20+
const CLASSIFY_CACHE = new Cache(1000, str => {
21+
let replace1 = (match, separator, chr) => chr ? (`_${chr.toUpperCase()}`) : '';
22+
let replace2 = (match, initialChar, separator, chr) => initialChar + (chr ? chr.toUpperCase() : '');
23+
let parts = str.split('/');
24+
25+
for (let i = 0; i < parts.length; i++) {
26+
parts[i] = parts[i]
27+
.replace(STRING_CLASSIFY_REGEXP_1, replace1)
28+
.replace(STRING_CLASSIFY_REGEXP_2, replace2);
29+
}
30+
31+
return parts
32+
.join('/')
33+
.replace(STRING_CLASSIFY_REGEXP_3, (match/*, separator, chr*/) => match.toUpperCase());
34+
});
35+
36+
const STRING_UNDERSCORE_REGEXP_1 = (/([a-z\d])([A-Z]+)/g);
37+
const STRING_UNDERSCORE_REGEXP_2 = (/-|\s+/g);
38+
39+
const UNDERSCORE_CACHE = new Cache(1000, str => str.replace(STRING_UNDERSCORE_REGEXP_1, '$1_$2').
40+
replace(STRING_UNDERSCORE_REGEXP_2, '_').toLowerCase());
41+
42+
const STRING_CAPITALIZE_REGEXP = (/(^|\/)([a-z\u00C0-\u024F])/g);
43+
44+
const CAPITALIZE_CACHE = new Cache(1000, str => str.replace(STRING_CAPITALIZE_REGEXP, (match/*, separator, chr*/) => match.toUpperCase()));
45+
46+
const STRING_DECAMELIZE_REGEXP = (/([a-z\d])([A-Z])/g);
47+
48+
const DECAMELIZE_CACHE = new Cache(1000, str => str.replace(STRING_DECAMELIZE_REGEXP, '$1_$2').toLowerCase());
49+
50+
/**
51+
Splits a string into separate units separated by spaces, eliminating any
52+
empty strings in the process. This is a convenience method for split that
53+
is mostly useful when applied to the `String.prototype`.
54+
55+
```javascript
56+
Ember.String.w("alpha beta gamma").forEach(function(key) {
57+
console.log(key);
58+
});
59+
60+
// > alpha
61+
// > beta
62+
// > gamma
63+
```
64+
65+
@method w
66+
@param {String} str The string to split
67+
@return {Array} array containing the split strings
68+
@public
69+
*/
70+
export function w(str) {
71+
return str.split(/\s+/);
72+
}
73+
74+
/**
75+
Converts a camelized string into all lower case separated by underscores.
76+
77+
```javascript
78+
'innerHTML'.decamelize(); // 'inner_html'
79+
'action_name'.decamelize(); // 'action_name'
80+
'css-class-name'.decamelize(); // 'css-class-name'
81+
'my favorite items'.decamelize(); // 'my favorite items'
82+
```
83+
84+
@method decamelize
85+
@param {String} str The string to decamelize.
86+
@return {String} the decamelized string.
87+
@public
88+
*/
89+
export function decamelize(str) {
90+
return DECAMELIZE_CACHE.get(str);
91+
}
92+
93+
/**
94+
Replaces underscores, spaces, or camelCase with dashes.
95+
96+
```javascript
97+
'innerHTML'.dasherize(); // 'inner-html'
98+
'action_name'.dasherize(); // 'action-name'
99+
'css-class-name'.dasherize(); // 'css-class-name'
100+
'my favorite items'.dasherize(); // 'my-favorite-items'
101+
'privateDocs/ownerInvoice'.dasherize(); // 'private-docs/owner-invoice'
102+
```
103+
104+
@method dasherize
105+
@param {String} str The string to dasherize.
106+
@return {String} the dasherized string.
107+
@public
108+
*/
109+
export function dasherize(str) {
110+
return STRING_DASHERIZE_CACHE.get(str);
111+
}
112+
113+
/**
114+
Returns the lowerCamelCase form of a string.
115+
116+
```javascript
117+
'innerHTML'.camelize(); // 'innerHTML'
118+
'action_name'.camelize(); // 'actionName'
119+
'css-class-name'.camelize(); // 'cssClassName'
120+
'my favorite items'.camelize(); // 'myFavoriteItems'
121+
'My Favorite Items'.camelize(); // 'myFavoriteItems'
122+
'private-docs/owner-invoice'.camelize(); // 'privateDocs/ownerInvoice'
123+
```
124+
125+
@method camelize
126+
@param {String} str The string to camelize.
127+
@return {String} the camelized string.
128+
@public
129+
*/
130+
export function camelize(str) {
131+
return CAMELIZE_CACHE.get(str);
132+
}
133+
134+
/**
135+
Returns the UpperCamelCase form of a string.
136+
137+
```javascript
138+
'innerHTML'.classify(); // 'InnerHTML'
139+
'action_name'.classify(); // 'ActionName'
140+
'css-class-name'.classify(); // 'CssClassName'
141+
'my favorite items'.classify(); // 'MyFavoriteItems'
142+
'private-docs/owner-invoice'.classify(); // 'PrivateDocs/OwnerInvoice'
143+
```
144+
145+
@method classify
146+
@param {String} str the string to classify
147+
@return {String} the classified string
148+
@public
149+
*/
150+
export function classify(str) {
151+
return CLASSIFY_CACHE.get(str);
152+
}
153+
154+
/**
155+
More general than decamelize. Returns the lower\_case\_and\_underscored
156+
form of a string.
157+
158+
```javascript
159+
'innerHTML'.underscore(); // 'inner_html'
160+
'action_name'.underscore(); // 'action_name'
161+
'css-class-name'.underscore(); // 'css_class_name'
162+
'my favorite items'.underscore(); // 'my_favorite_items'
163+
'privateDocs/ownerInvoice'.underscore(); // 'private_docs/owner_invoice'
164+
```
165+
166+
@method underscore
167+
@param {String} str The string to underscore.
168+
@return {String} the underscored string.
169+
@public
170+
*/
171+
export function underscore(str) {
172+
return UNDERSCORE_CACHE.get(str);
173+
}
174+
175+
/**
176+
Returns the Capitalized form of a string
177+
178+
```javascript
179+
'innerHTML'.capitalize() // 'InnerHTML'
180+
'action_name'.capitalize() // 'Action_name'
181+
'css-class-name'.capitalize() // 'Css-class-name'
182+
'my favorite items'.capitalize() // 'My favorite items'
183+
'privateDocs/ownerInvoice'.capitalize(); // 'PrivateDocs/ownerInvoice'
184+
```
185+
186+
@method capitalize
187+
@param {String} str The string to capitalize.
188+
@return {String} The capitalized string.
189+
@public
190+
*/
191+
export function capitalize(str) {
192+
return CAPITALIZE_CACHE.get(str);
193+
}

addon/index.ts

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
@module @ember/string
33
*/
44
import Cache from './cache';
5-
import { deprecate } from '@ember/application/deprecations';
6-
75

86
// STATE within a module is frowned upon, this exists
97
// to support Ember.STRINGS but shield ember internals from this legacy global
@@ -81,62 +79,6 @@ const DECAMELIZE_CACHE = new Cache<string, string>(1000, str =>
8179
str.replace(STRING_DECAMELIZE_REGEXP, '$1_$2').toLowerCase()
8280
);
8381

84-
function _fmt(str: string, formats: any[]) {
85-
// first, replace any ORDERED replacements.
86-
let idx = 0; // the current index for non-numerical replacements
87-
return str.replace(/%@([0-9]+)?/g, (_s: string, argIndex: string) => {
88-
let i = argIndex ? parseInt(argIndex, 10) - 1 : idx++;
89-
let r = i < formats.length ? formats[i] : undefined;
90-
return typeof r === 'string' ? r : r === null ? '(null)' : r === undefined ? '' : String(r);
91-
});
92-
}
93-
94-
/**
95-
Formats the passed string, but first looks up the string in the localized
96-
strings hash. This is a convenient way to localize text. See
97-
`fmt` for more information on formatting.
98-
99-
Note that it is traditional but not required to prefix localized string
100-
keys with an underscore or other character so you can easily identify
101-
localized strings.
102-
103-
```javascript
104-
import { setStrings, loc } from '@ember/string';
105-
106-
setStrings({
107-
'_Hello World': 'Bonjour le monde',
108-
'_Hello %@ %@': 'Bonjour %@ %@'
109-
});
110-
111-
loc("_Hello World"); // 'Bonjour le monde';
112-
loc("_Hello %@ %@", ["John", "Smith"]); // "Bonjour John Smith";
113-
```
114-
115-
@method loc
116-
@param {String} str The string to format
117-
@param {Array} formats Optional array of parameters to interpolate into string.
118-
@return {String} formatted string
119-
@public
120-
*/
121-
export function loc(str: string, formats: any[]): string {
122-
deprecate(
123-
'loc is deprecated, use an internationalization or localization addon instead.',
124-
false,
125-
{
126-
id: 'ember-string-loc',
127-
until: '2.0.0',
128-
// @ts-ignore requires https://github.com/DefinitelyTyped/DefinitelyTyped/pull/32538 to be merged
129-
url: 'http://emberjs.com/deprecations/v2.x#toc_ember-string-loc'
130-
}
131-
);
132-
if (!Array.isArray(formats) || arguments.length > 2) {
133-
formats = Array.prototype.slice.call(arguments, 1);
134-
}
135-
136-
str = STRINGS[str] || str;
137-
return _fmt(str, formats);
138-
}
139-
14082
/**
14183
Splits a string into separate units separated by spaces, eliminating any
14284
empty strings in the process. This is a convenience method for split that

ember-cli-build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = function(defaults) {
88
'ember-cli-babel': {
99
emberModulesAPIPolyfillBlacklist: {
1010
['@ember/string']: [
11-
'fmt', 'loc', 'w',
11+
'w',
1212
'getStrings', 'setStrings',
1313
'decamelize', 'dasherize', 'camelize',
1414
'classify', 'underscore', 'capitalize',

tests/integration/helpers/loc-test.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/typings/test.ts

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,9 @@
11
import {
22
camelize, capitalize, classify, dasherize,
3-
decamelize, fmt, getStrings, loc, setStrings,
3+
decamelize, getStrings, loc, setStrings,
44
underscore, w
55
} from "../../index";
66

7-
function testFmt() {
8-
fmt("Hello %@ %@", [ 'John', 'Doe' ]); // "Hello John Doe"
9-
fmt("Hello %@2, %@1", [ 'John', 'Doe' ]); // "Hello Doe, John"
10-
fmt("Hello %@ %@", 'John', 'Doe'); // "Hello John Doe"
11-
fmt('data: %@', [{ id: 3 }]);
12-
fmt('%@', 'John');
13-
}
14-
15-
function testLoc() {
16-
let oldStrings = getStrings();
17-
setStrings({
18-
'_Hello World': 'Bonjour le monde',
19-
'_Hello %@': 'Bonjour %@',
20-
'_Hello %@ %@': 'Bonjour %@ %@',
21-
'_Hello %@# %@#': 'Bonjour %@2 %@1'
22-
});
23-
24-
loc("_Hello World"); // 'Bonjour le monde';
25-
loc("_Hello %@ %@", ["John", "Smith"]); // "Bonjour John Smith";
26-
loc('_Hello %@', 'John');
27-
loc('_Hello %@ %@', ['John'], 'Doe');
28-
}
29-
307
function testW() {
318
w("alpha beta gamma").forEach(function(key) {
329
console.log(key);

0 commit comments

Comments
 (0)