From fcde1c918a86ccebf7d9b88a0b428cab3489ff82 Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Wed, 29 Nov 2017 20:11:37 +0000 Subject: [PATCH] Remove Ember.String.fmt --- packages/ember-runtime/lib/ext/string.js | 14 ------- packages/ember-runtime/lib/system/string.js | 42 ++----------------- .../tests/system/string/fmt_string_test.js | 36 ---------------- 3 files changed, 3 insertions(+), 89 deletions(-) delete mode 100644 packages/ember-runtime/tests/system/string/fmt_string_test.js diff --git a/packages/ember-runtime/lib/ext/string.js b/packages/ember-runtime/lib/ext/string.js index a9308cff3a3..1c840f31b32 100644 --- a/packages/ember-runtime/lib/ext/string.js +++ b/packages/ember-runtime/lib/ext/string.js @@ -4,7 +4,6 @@ import { ENV } from 'ember-environment'; import { - fmt, w, loc, camelize, @@ -18,19 +17,6 @@ import { const StringPrototype = String.prototype; if (ENV.EXTEND_PROTOTYPES.String) { - /** - See [Ember.String.fmt](/api/classes/Ember.String.html#method_fmt). - - @method fmt - @for @ember/string - @static - @private - @deprecated - */ - StringPrototype.fmt = function (...args) { - return fmt(this, args); - }; - /** See [Ember.String.w](/api/classes/Ember.String.html#method_w). diff --git a/packages/ember-runtime/lib/system/string.js b/packages/ember-runtime/lib/system/string.js index 131daddd970..e9c08ecf531 100644 --- a/packages/ember-runtime/lib/system/string.js +++ b/packages/ember-runtime/lib/system/string.js @@ -2,7 +2,6 @@ @module @ember/string */ import { Cache } from 'ember-metal'; -import { deprecate } from 'ember-debug'; import { inspect } from 'ember-utils'; import { isArray } from '../utils'; import { @@ -32,7 +31,7 @@ const CLASSIFY_CACHE = new Cache(1000, str => { .replace(STRING_CLASSIFY_REGEXP_2, replace2); } return parts.join('/') - .replace(STRING_CLASSIFY_REGEXP_3, (match /*, separator, chr */) => match.toUpperCase()); + .replace(STRING_CLASSIFY_REGEXP_3, (match /*, separator, chr */) => match.toUpperCase()); }); const STRING_UNDERSCORE_REGEXP_1 = (/([a-z\d])([A-Z]+)/g); @@ -61,7 +60,7 @@ function _fmt(str, formats) { } // first, replace any ORDERED replacements. - let idx = 0; // the current index for non-numerical replacements + let idx = 0; // the current index for non-numerical replacements return str.replace(/%@([0-9]+)?/g, (s, argIndex) => { argIndex = (argIndex) ? parseInt(argIndex, 10) - 1 : idx++; s = cachedFormats[argIndex]; @@ -69,15 +68,6 @@ function _fmt(str, formats) { }); } -function fmt(/* str, formats */) { - deprecate( - 'Ember.String.fmt is deprecated, use ES6 template strings instead.', - false, - { id: 'ember-string-utils.fmt', until: '3.0.0', url: 'http://babeljs.io/docs/learn-es2015/#template-strings' } - ); - return _fmt(...arguments); -} - function loc(str, formats) { if (!isArray(formats) || arguments.length > 2) { formats = Array.prototype.slice.call(arguments, 1); @@ -124,34 +114,9 @@ function capitalize(str) { @public */ export default { - /** - Apply formatting options to the string. This will look for occurrences - of "%@" in your string and substitute them with the arguments you pass into - this method. If you want to control the specific order of replacement, - you can add a number after the key as well to indicate which argument - you want to insert. - - Ordered insertions are most useful when building loc strings where values - you need to insert may appear in different orders. - - ```javascript - "Hello %@ %@".fmt('John', 'Doe'); // "Hello John Doe" - "Hello %@2, %@1".fmt('John', 'Doe'); // "Hello Doe, John" - ``` - - @method fmt - @param {String} str The string to format - @param {Array} formats An array of parameters to interpolate into string. - @return {String} formatted string - @public - @deprecated Use ES6 template strings instead: http://babeljs.io/docs/learn-es2015/#template-strings - */ - fmt, - /** Formats the passed string, but first looks up the string in the localized - strings hash. This is a convenient way to localize text. See - `Ember.String.fmt()` for more information on formatting. + strings hash. This is a convenient way to localize text. Note that it is traditional but not required to prefix localized string keys with an underscore or other character so you can easily identify @@ -308,7 +273,6 @@ export default { }; export { - fmt, loc, w, decamelize, diff --git a/packages/ember-runtime/tests/system/string/fmt_string_test.js b/packages/ember-runtime/tests/system/string/fmt_string_test.js deleted file mode 100644 index 86e7b141af4..00000000000 --- a/packages/ember-runtime/tests/system/string/fmt_string_test.js +++ /dev/null @@ -1,36 +0,0 @@ -import { ENV } from 'ember-environment'; -import { fmt } from '../../../system/string'; - -QUnit.module('EmberStringUtils.fmt'); - -if (!ENV.EXTEND_PROTOTYPES.String) { - QUnit.test('String.prototype.fmt is not modified without EXTEND_PROTOTYPES', function() { - ok('undefined' === typeof String.prototype.fmt, 'String.prototype helper disabled'); - }); -} - -function test(given, args, expected, description) { - QUnit.test(description, function() { - expectDeprecation('Ember.String.fmt is deprecated, use ES6 template strings instead.'); - equal(fmt(given, args), expected); - if (ENV.EXTEND_PROTOTYPES.String) { - equal(given.fmt(...args), expected); - } - }); -} - -test('Hello %@ %@', ['John', 'Doe'], 'Hello John Doe', `fmt('Hello %@ %@', ['John', 'Doe']) => 'Hello John Doe'`); -test('Hello %@2 %@1', ['John', 'Doe'], 'Hello Doe John', `fmt('Hello %@2 %@1', ['John', 'Doe']) => 'Hello Doe John'`); -test( - '%@08 %@07 %@06 %@05 %@04 %@03 %@02 %@01', - ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight'], - 'Eight Seven Six Five Four Three Two One', - `fmt('%@08 %@07 %@06 %@05 %@04 %@03 %@02 %@01', ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight']) => 'Eight Seven Six Five Four Three Two One'` -); -test('data: %@', [{ id: 3 }], 'data: {id: 3}', `fmt('data: %@', [{ id: 3 }]) => 'data: {id: 3}'`); - -QUnit.test('works with argument form', function() { - expectDeprecation('Ember.String.fmt is deprecated, use ES6 template strings instead.'); - equal(fmt('%@', 'John'), 'John'); - equal(fmt('%@ %@', ['John'], 'Doe'), '[John] Doe'); -});