diff options
Diffstat (limited to 'core/src/OC/util.js')
-rw-r--r-- | core/src/OC/util.js | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/core/src/OC/util.js b/core/src/OC/util.js index f8f7c05e6e8..7f348704831 100644 --- a/core/src/OC/util.js +++ b/core/src/OC/util.js @@ -1,7 +1,8 @@ /** * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at> * - * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * @author Christoph Wurst <christoph@winzerhof-wurst.at> + * @author John Molakvoæ <skjnldsv@protonmail.com> * * @license GNU AGPL version 3 or any later version * @@ -16,7 +17,8 @@ * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * */ import $ from 'jquery' @@ -24,7 +26,7 @@ import moment from 'moment' import History from './util-history' import OC from './index' -import humanFileSize from '../Util/human-file-size' +import { formatFileSize as humanFileSize } from '@nextcloud/files' function chunkify(t) { // Adapted from http://my.opera.com/GreyWyvern/blog/show.dml/1671288 @@ -58,6 +60,9 @@ export default { History, + /** + * @deprecated use https://nextcloud.github.io/nextcloud-files/modules/_humanfilesize_.html#formatfilesize + */ humanFileSize, /** @@ -69,7 +74,7 @@ export default { * * */ - computerFileSize: function(string) { + computerFileSize(string) { if (typeof string !== 'string') { return null } @@ -78,17 +83,17 @@ export default { let bytes = null const bytesArray = { - 'b': 1, - 'k': 1024, - 'kb': 1024, - 'mb': 1024 * 1024, - 'm': 1024 * 1024, - 'gb': 1024 * 1024 * 1024, - 'g': 1024 * 1024 * 1024, - 'tb': 1024 * 1024 * 1024 * 1024, - 't': 1024 * 1024 * 1024 * 1024, - 'pb': 1024 * 1024 * 1024 * 1024 * 1024, - 'p': 1024 * 1024 * 1024 * 1024 * 1024, + b: 1, + k: 1024, + kb: 1024, + mb: 1024 * 1024, + m: 1024 * 1024, + gb: 1024 * 1024 * 1024, + g: 1024 * 1024 * 1024, + tb: 1024 * 1024 * 1024 * 1024, + t: 1024 * 1024 * 1024 * 1024, + pb: 1024 * 1024 * 1024 * 1024 * 1024, + p: 1024 * 1024 * 1024 * 1024 * 1024, } const matches = s.match(/^[\s+]?([0-9]*)(\.([0-9]+))?( +)?([kmgtp]?b?)$/i) @@ -113,7 +118,10 @@ export default { * @param {string} format date format, see momentjs docs * @returns {string} timestamp formatted as requested */ - formatDate: function(timestamp, format) { + formatDate(timestamp, format) { + if (window.TESTING === undefined) { + console.warn('OC.Util.formatDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment') + } format = format || 'LLL' return moment(timestamp).format(format) }, @@ -122,7 +130,10 @@ export default { * @param {string|number} timestamp timestamp * @returns {string} human readable difference from now */ - relativeModifiedDate: function(timestamp) { + relativeModifiedDate(timestamp) { + if (window.TESTING === undefined) { + console.warn('OC.Util.relativeModifiedDate is deprecated and will be removed in Nextcloud 21. See @nextcloud/moment') + } const diff = moment().diff(moment(timestamp)) if (diff >= 0 && diff < 45000) { return t('core', 'seconds ago') @@ -135,7 +146,7 @@ export default { * * @returns {bool} true if this is IE, false otherwise */ - isIE: function() { + isIE() { return $('html').hasClass('ie') }, @@ -144,7 +155,7 @@ export default { * * @returns {int} width of scrollbar */ - getScrollBarWidth: function() { + getScrollBarWidth() { if (this._scrollBarWidth) { return this._scrollBarWidth } @@ -184,7 +195,7 @@ export default { * @param {Date} date date * @returns {Date} date with stripped time */ - stripTime: function(date) { + stripTime(date) { // FIXME: likely to break when crossing DST // would be better to use a library like momentJS return new Date(date.getFullYear(), date.getMonth(), date.getDate()) @@ -197,7 +208,7 @@ export default { * @returns {number} -1 if b comes before a, 1 if a comes before b * or 0 if the strings are identical */ - naturalSortCompare: function(a, b) { + naturalSortCompare(a, b) { let x const aa = chunkify(a) const bb = chunkify(b) @@ -224,7 +235,7 @@ export default { * @param {function} callback function to call on success * @param {integer} interval in milliseconds */ - waitFor: function(callback, interval) { + waitFor(callback, interval) { const internalCallback = function() { if (callback() !== true) { setTimeout(internalCallback, interval) @@ -240,7 +251,7 @@ export default { * @param {string} value value of the cookie * @returns {boolean} true if the cookie with the given name has the given value */ - isCookieSetToValue: function(name, value) { + isCookieSetToValue(name, value) { const cookies = document.cookie.split(';') for (let i = 0; i < cookies.length; i++) { const cookie = cookies[i].split('=') |