From f4bfe9294b1e6cfb85ec694388a12967e4305134 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 13 Oct 2024 17:10:11 +0100 Subject: [PATCH] reuse getSortValue --- static/mobile/js/edits.js | 31 ------------------------------- static/mobile/js/utils.js | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 36 deletions(-) diff --git a/static/mobile/js/edits.js b/static/mobile/js/edits.js index be9101eea..5494fcb19 100644 --- a/static/mobile/js/edits.js +++ b/static/mobile/js/edits.js @@ -1,35 +1,4 @@ -const getSortValue = function(value) { - var sortValue = value; - function trim(value) { - return value.replace(/^\W+(?=\w)/, ''); - } - if ( - isEmpty(value) - || isNull(value) - || isUndefined(value) - ) { - sortValue = null; - } else if (isString(value)) { - // make lowercase and remove leading non-word characters - sortValue = trim(value.toLowerCase()); - // move leading articles to the end - // and remove leading non-word characters - ['a', 'an', 'the'].forEach(function(article) { - if (new RegExp('^' + article + ' ').test(sortValue)) { - sortValue = trim(sortValue.slice(article.length + 1)) - + ', ' + sortValue.slice(0, article.length); - return false; // break - } - }); - // remove thousand separators and pad numbers - sortValue = sortValue.replace(/(\d),(?=(\d{3}))/g, '$1') - .replace(/\d+/g, function(match) { - return match.padStart(64, '0') - }); - } - return sortValue; -}; const sortByKey = function(array, by) { return array.sort(function(a, b) { diff --git a/static/mobile/js/utils.js b/static/mobile/js/utils.js index 860db6988..a22dc75ae 100644 --- a/static/mobile/js/utils.js +++ b/static/mobile/js/utils.js @@ -161,11 +161,37 @@ const getVideoURL = function(id, resolution, part, track, streamId) { return prefix + '/' + getVideoURLName(id, resolution, part, track, streamId); }; -function getSortValue(value) { - var getSortValue = Ox.cache(function getSortValue(value) { - var sortValue = value; - return sortValue; -} +const getSortValue = function(value) { + var sortValue = value; + function trim(value) { + return value.replace(/^\W+(?=\w)/, ''); + } + if ( + isEmpty(value) + || isNull(value) + || isUndefined(value) + ) { + sortValue = null; + } else if (isString(value)) { + // make lowercase and remove leading non-word characters + sortValue = trim(value.toLowerCase()); + // move leading articles to the end + // and remove leading non-word characters + ['a', 'an', 'the'].forEach(function(article) { + if (new RegExp('^' + article + ' ').test(sortValue)) { + sortValue = trim(sortValue.slice(article.length + 1)) + + ', ' + sortValue.slice(0, article.length); + return false; // break + } + }); + // remove thousand separators and pad numbers + sortValue = sortValue.replace(/(\d),(?=(\d{3}))/g, '$1') + .replace(/\d+/g, function(match) { + return match.padStart(64, '0') + }); + } + return sortValue; +}; function sortBy(array, by, map) { return array.sort(function(a, b) {