Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2020-06-04 11:52:03 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2020-06-05 09:48:49 +0300
commiteaf4724acc3b4720239d789f6028526945b8bba0 (patch)
tree145d66dcfdd5f7bef247ddc2036167610a653dc2 /core/src
parenta5232d9805eb07c43d21aebcd11fea6dcde7e8b1 (diff)
Move humanFileSize and OC.getCanonicalLocale to npm packages
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'core/src')
-rw-r--r--core/src/OC/index.js6
-rw-r--r--core/src/OC/l10n.js10
-rw-r--r--core/src/OC/util.js5
-rw-r--r--core/src/Util/human-file-size.js51
4 files changed, 8 insertions, 64 deletions
diff --git a/core/src/OC/index.js b/core/src/OC/index.js
index 59abe046769..6a5850919cc 100644
--- a/core/src/OC/index.js
+++ b/core/src/OC/index.js
@@ -79,10 +79,12 @@ import {
} from './menu'
import { isUserAdmin } from './admin'
import L10N, {
- getCanonicalLocale,
getLanguage,
getLocale,
} from './l10n'
+import {
+ getCanonicalLocale,
+} from '@nextcloud/l10n'
import {
generateUrl,
@@ -223,7 +225,7 @@ export default {
getProtocol,
/**
- * L10n
+ * @deprecated 20.0.0 use `getCanonicalLocale` from https://www.npmjs.com/package/@nextcloud/l10n
*/
getCanonicalLocale,
getLocale,
diff --git a/core/src/OC/l10n.js b/core/src/OC/l10n.js
index a4920e9d271..8eeb978b6d9 100644
--- a/core/src/OC/l10n.js
+++ b/core/src/OC/l10n.js
@@ -324,16 +324,6 @@ const L10n = {
export default L10n
/**
- * Returns the user's locale as a BCP 47 compliant language tag
- *
- * @returns {String} locale string
- */
-export const getCanonicalLocale = () => {
- const locale = getLocale()
- return typeof locale === 'string' ? locale.replace(/_/g, '-') : locale
-}
-
-/**
* Returns the user's locale
*
* @returns {String} locale string
diff --git a/core/src/OC/util.js b/core/src/OC/util.js
index 67f00bf30d3..a8666808083 100644
--- a/core/src/OC/util.js
+++ b/core/src/OC/util.js
@@ -24,7 +24,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 +58,9 @@ export default {
History,
+ /**
+ * @deprecated use https://nextcloud.github.io/nextcloud-files/modules/_humanfilesize_.html#formatfilesize
+ */
humanFileSize,
/**
diff --git a/core/src/Util/human-file-size.js b/core/src/Util/human-file-size.js
deleted file mode 100644
index 7f9eb7ab61d..00000000000
--- a/core/src/Util/human-file-size.js
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * 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/>.
- */
-
-/**
- * Returns a human readable file size
- * @param {number} size Size in bytes
- * @param {boolean} skipSmallSizes return '< 1 kB' for small files
- * @returns {string}
- */
-export default function humanFileSize(size, skipSmallSizes) {
- const humanList = ['B', 'KB', 'MB', 'GB', 'TB']
- // Calculate Log with base 1024: size = 1024 ** order
- let order = size > 0 ? Math.floor(Math.log(size) / Math.log(1024)) : 0
- // Stay in range of the byte sizes that are defined
- order = Math.min(humanList.length - 1, order)
- const readableFormat = humanList[order]
- let relativeSize = (size / Math.pow(1024, order)).toFixed(1)
- if (skipSmallSizes === true && order === 0) {
- if (relativeSize !== '0.0') {
- return '< 1 KB'
- } else {
- return '0 KB'
- }
- }
- if (order < 2) {
- relativeSize = parseFloat(relativeSize).toFixed(0)
- } else if (relativeSize.substr(relativeSize.length - 2, 2) === '.0') {
- relativeSize = relativeSize.substr(0, relativeSize.length - 2)
- } else {
- relativeSize = parseFloat(relativeSize).toLocaleString(OC.getCanonicalLocale())
- }
- return relativeSize + ' ' + readableFormat
-}