mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 20:27:28 +08:00
DEV: Remove unused BreakString class (#8942)
This commit is contained in:
parent
92bb7b9269
commit
99305511bc
|
@ -1,54 +1,3 @@
|
||||||
/* global BreakString:true */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* memoize.js
|
|
||||||
* by @philogb and @addyosmani
|
|
||||||
* with further optimizations by @mathias
|
|
||||||
* and @DmitryBaranovsk
|
|
||||||
* perf tests: http://bit.ly/q3zpG3
|
|
||||||
* Released under an MIT license.
|
|
||||||
*
|
|
||||||
* modified with cap by Sam
|
|
||||||
*/
|
|
||||||
function cappedMemoize(fn, max) {
|
|
||||||
fn.maxMemoize = max;
|
|
||||||
fn.memoizeLength = 0;
|
|
||||||
|
|
||||||
return function() {
|
|
||||||
const args = Array.prototype.slice.call(arguments);
|
|
||||||
let hash = "";
|
|
||||||
let i = args.length;
|
|
||||||
let currentArg = null;
|
|
||||||
while (i--) {
|
|
||||||
currentArg = args[i];
|
|
||||||
hash +=
|
|
||||||
currentArg === new Object(currentArg)
|
|
||||||
? JSON.stringify(currentArg)
|
|
||||||
: currentArg;
|
|
||||||
if (!fn.memoize) {
|
|
||||||
fn.memoize = {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hash in fn.memoize) {
|
|
||||||
return fn.memoize[hash];
|
|
||||||
} else {
|
|
||||||
fn.memoizeLength++;
|
|
||||||
if (fn.memoizeLength > max) {
|
|
||||||
fn.memoizeLength = 0;
|
|
||||||
fn.memoize = {};
|
|
||||||
}
|
|
||||||
const result = fn.apply(this, args);
|
|
||||||
fn.memoize[hash] = result;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const breakUp = cappedMemoize(function(str, hint) {
|
|
||||||
return new BreakString(str).break(hint);
|
|
||||||
}, 100);
|
|
||||||
export { breakUp };
|
|
||||||
|
|
||||||
export function shortDate(date) {
|
export function shortDate(date) {
|
||||||
return moment(date).format(I18n.t("dates.medium.date_year"));
|
return moment(date).format(I18n.t("dates.medium.date_year"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
//= require mousetrap-global-bind.js
|
//= require mousetrap-global-bind.js
|
||||||
//= require rsvp.js
|
//= require rsvp.js
|
||||||
//= require show-html.js
|
//= require show-html.js
|
||||||
//= require break_string
|
|
||||||
//= require buffered-proxy
|
//= require buffered-proxy
|
||||||
//= require jquery.autoellipsis-1.0.10
|
//= require jquery.autoellipsis-1.0.10
|
||||||
//= require virtual-dom
|
//= require virtual-dom
|
||||||
|
|
20
test/javascripts/lib/break-string-test.js.es6
Normal file
20
test/javascripts/lib/break-string-test.js.es6
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/* global BreakString:true */
|
||||||
|
|
||||||
|
QUnit.module("lib:breakString", {});
|
||||||
|
|
||||||
|
QUnit.test("breakString", assert => {
|
||||||
|
var b = function(s, hint) {
|
||||||
|
return new BreakString(s).break(hint);
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.equal(b("hello"), "hello");
|
||||||
|
assert.equal(b("helloworld"), "helloworld");
|
||||||
|
assert.equal(b("HeMans11"), "He<wbr>​Mans<wbr>​11");
|
||||||
|
assert.equal(b("he_man"), "he_<wbr>​man");
|
||||||
|
assert.equal(b("he11111"), "he<wbr>​11111");
|
||||||
|
assert.equal(b("HRCBob"), "HRC<wbr>​Bob");
|
||||||
|
assert.equal(
|
||||||
|
b("bobmarleytoo", "Bob Marley Too"),
|
||||||
|
"bob<wbr>​marley<wbr>​too"
|
||||||
|
);
|
||||||
|
});
|
|
@ -4,7 +4,6 @@ import {
|
||||||
relativeAge,
|
relativeAge,
|
||||||
autoUpdatingRelativeAge,
|
autoUpdatingRelativeAge,
|
||||||
updateRelativeAge,
|
updateRelativeAge,
|
||||||
breakUp,
|
|
||||||
number,
|
number,
|
||||||
longDate,
|
longDate,
|
||||||
durationTiny
|
durationTiny
|
||||||
|
@ -211,23 +210,6 @@ QUnit.test("updateRelativeAge", assert => {
|
||||||
assert.equal($elem.html(), "2 mins ago");
|
assert.equal($elem.html(), "2 mins ago");
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test("breakUp", assert => {
|
|
||||||
var b = function(s, hint) {
|
|
||||||
return breakUp(s, hint);
|
|
||||||
};
|
|
||||||
|
|
||||||
assert.equal(b("hello"), "hello");
|
|
||||||
assert.equal(b("helloworld"), "helloworld");
|
|
||||||
assert.equal(b("HeMans11"), "He<wbr>​Mans<wbr>​11");
|
|
||||||
assert.equal(b("he_man"), "he_<wbr>​man");
|
|
||||||
assert.equal(b("he11111"), "he<wbr>​11111");
|
|
||||||
assert.equal(b("HRCBob"), "HRC<wbr>​Bob");
|
|
||||||
assert.equal(
|
|
||||||
b("bobmarleytoo", "Bob Marley Too"),
|
|
||||||
"bob<wbr>​marley<wbr>​too"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
QUnit.test("number", assert => {
|
QUnit.test("number", assert => {
|
||||||
assert.equal(number(123), "123", "it returns a string version of the number");
|
assert.equal(number(123), "123", "it returns a string version of the number");
|
||||||
assert.equal(number("123"), "123", "it works with a string command");
|
assert.equal(number("123"), "123", "it works with a string command");
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
|
|
||||||
//= require helpers/assertions
|
//= require helpers/assertions
|
||||||
|
|
||||||
|
//= require break_string
|
||||||
//= require helpers/qunit-helpers
|
//= require helpers/qunit-helpers
|
||||||
//= require_tree ./fixtures
|
//= require_tree ./fixtures
|
||||||
//= require_tree ./lib
|
//= require_tree ./lib
|
||||||
|
|
Loading…
Reference in New Issue
Block a user