@nextcloud/files 3.0.1-beta.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,55 @@
1
1
  # @nextcloud/files
2
+ [![npm last version](https://img.shields.io/npm/v/@nextcloud/files.svg?style=flat-square)](https://www.npmjs.com/package/@nextcloud/files) [![Code coverage](https://img.shields.io/codecov/c/github/nextcloud-libraries/nextcloud-files?style=flat-square)](https://app.codecov.io/gh/nextcloud-libraries/nextcloud-files) [![Project documentation](https://img.shields.io/badge/documentation-online-blue?style=flat-square)](https://nextcloud-libraries.github.io/nextcloud-files/)
2
3
 
3
4
  Nextcloud Files helpers for Nextcloud apps and libraries
5
+
6
+ ## Usage example
7
+
8
+ ### Using WebDAV to query favorite nodes
9
+
10
+ ```ts
11
+ import { davGetClient, davRootPath, getFavoriteNodes } from '@nextcloud/files'
12
+
13
+ const client = davGetClient()
14
+ // query favorites for the root folder (meaning all favorites)
15
+ const favorites = await getFavoriteNodes(client)
16
+ // which is the same as writing:
17
+ const favorites = await getFavoriteNodes(client, '/', davRootPath)
18
+ ```
19
+
20
+ ### Using WebDAV to list all nodes in directory
21
+
22
+ ```ts
23
+ import {
24
+ davGetClient,
25
+ davGetDefaultPropfind,
26
+ davResultToNode,
27
+ davRootPath,
28
+ davRemoteURL
29
+ } from '@nextcloud/files'
30
+
31
+ // Get the DAV client for the default remote
32
+ const client = davGetClient()
33
+ // which is the same as writing
34
+ const client = davGetClient(davRemoteURL)
35
+ // of cause you can also configure another WebDAV remote
36
+ const client = davGetClient('https://example.com/dav')
37
+
38
+ const path = '/my-folder/' // the directory you want to list
39
+
40
+ // Query the directory content using the webdav library
41
+ // `davRootPath` is the files root, for Nextcloud this is '/files/USERID', by default the current user is used
42
+ const results = client.getDirectoryContents(`${davRootPath}${path}`, {
43
+ details: true,
44
+ // Query all required properties for a Node
45
+ data: davGetDefaultPropfind()
46
+ })
47
+
48
+ // Convert the result to an array of Node
49
+ const nodes = results.data.map((result) => davResultToNode(r))
50
+ // If you specified a different root in the `getDirectoryContents` you must add this also on the `davResultToNode` call:
51
+ const nodes = results.data.map((result) => davResultToNode(r, myRoot))
52
+ // Same if you used a different remote URL:
53
+ const nodes = results.data.map((result) => davResultToNode(r, myRoot, myRemoteURL))
54
+
55
+ ```
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
3
+ *
4
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
5
+ * @author Ferdinand Thiessen <opensource@fthiessen.de>
6
+ *
7
+ * @license AGPL-3.0-or-later
8
+ *
9
+ * This program is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU Affero General Public License as
11
+ * published by the Free Software Foundation, either version 3 of the
12
+ * License, or (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ * GNU Affero General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU Affero General Public License
20
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
21
+ *
22
+ */
23
+ import type { FileStat, WebDAVClient } from 'webdav';
24
+ import type { Node } from '../files/node';
25
+ /**
26
+ * The DAV root path for the current user
27
+ */
28
+ export declare const davRootPath: string;
29
+ /**
30
+ * The DAV remote URL used as base URL for the WebDAV client
31
+ */
32
+ export declare const davRemoteURL: string;
33
+ /**
34
+ * Get a WebDAV client configured to include the Nextcloud request token
35
+ *
36
+ * @param remoteURL The DAV server remote URL
37
+ * @param headers Optional additional headers to set for every request
38
+ */
39
+ export declare const davGetClient: (remoteURL?: string, headers?: Record<string, string>) => WebDAVClient;
40
+ /**
41
+ * Use WebDAV to query for favorite Nodes
42
+ *
43
+ * @param davClient The WebDAV client to use for performing the request
44
+ * @param path Base path for the favorites, if unset all favorites are queried
45
+ * @param davRoot The root path for the DAV user (defaults to `davRootPath`)
46
+ * @example
47
+ * ```js
48
+ * import { davGetClient, davRootPath, getFavoriteNodes } from '@nextcloud/files'
49
+ *
50
+ * const client = davGetClient()
51
+ * // query favorites for the root
52
+ * const favorites = await getFavoriteNodes(client)
53
+ * // which is the same as writing:
54
+ * const favorites = await getFavoriteNodes(client, '/', davRootPath)
55
+ * ```
56
+ */
57
+ export declare const getFavoriteNodes: (davClient: WebDAVClient, path?: string, davRoot?: string) => Promise<Node[]>;
58
+ /**
59
+ * Covert DAV result `FileStat` to `Node`
60
+ *
61
+ * @param node The DAV result
62
+ * @param filesRoot The DAV files root path
63
+ * @param remoteURL The DAV server remote URL (same as on `davGetClient`)
64
+ */
65
+ export declare const davResultToNode: (node: FileStat, filesRoot?: string, remoteURL?: string) => Node;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Parse the webdav permission string to a permission enum
3
+ *
4
+ * @param permString The DAV permission string
5
+ */
6
+ export declare const davParsePermissions: (permString?: string) => number;
@@ -0,0 +1,57 @@
1
+ export type DavProperty = {
2
+ [key: string]: string;
3
+ };
4
+ export declare const defaultDavProperties: string[];
5
+ export declare const defaultDavNamespaces: {
6
+ d: string;
7
+ nc: string;
8
+ oc: string;
9
+ ocs: string;
10
+ };
11
+ /**
12
+ * Register custom DAV properties
13
+ *
14
+ * Can be used if your app introduces custom DAV properties, so e.g. the files app can make use of it.
15
+ *
16
+ * @param prop The property
17
+ * @param namespace The namespace of the property
18
+ */
19
+ export declare const registerDavProperty: (prop: string, namespace?: DavProperty) => boolean;
20
+ /**
21
+ * Get the registered dav properties
22
+ */
23
+ export declare const getDavProperties: () => string;
24
+ /**
25
+ * Get the registered dav namespaces
26
+ */
27
+ export declare const getDavNameSpaces: () => string;
28
+ /**
29
+ * Get the default PROPFIND request body
30
+ */
31
+ export declare const davGetDefaultPropfind: () => string;
32
+ /**
33
+ * Get the REPORT body to filter for favorite nodes
34
+ */
35
+ export declare const davGetFavoritesReport: () => string;
36
+ /**
37
+ * Get the SEARCH body to search for recently modified files
38
+ *
39
+ * @param lastModified Oldest timestamp to include (Unix timestamp)
40
+ * @example
41
+ * ```ts
42
+ * // SEARCH for recent files need a different DAV endpoint
43
+ * const client = davGetClient(generateRemoteUrl('dav'))
44
+ * // Timestamp of last week
45
+ * const lastWeek = Math.round(Date.now() / 1000) - (60 * 60 * 24 * 7)
46
+ * const contentsResponse = await client.getDirectoryContents(path, {
47
+ * details: true,
48
+ * data: davGetRecentSearch(lastWeek),
49
+ * headers: {
50
+ * method: 'SEARCH',
51
+ * 'Content-Type': 'application/xml; charset=utf-8',
52
+ * },
53
+ * deep: true,
54
+ * }) as ResponseDataDetailed<FileStat[]>
55
+ * ```
56
+ */
57
+ export declare const davGetRecentSearch: (lastModified: number) => string;
@@ -0,0 +1,99 @@
1
+ /**
2
+ * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
3
+ *
4
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
5
+ *
6
+ * @license AGPL-3.0-or-later
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU Affero General Public License as
10
+ * published by the Free Software Foundation, either version 3 of the
11
+ * License, or (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU Affero General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Affero General Public License
19
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+ import { Node } from './files/node';
23
+ import { View } from './navigation/view';
24
+ export declare enum DefaultType {
25
+ DEFAULT = "default",
26
+ HIDDEN = "hidden"
27
+ }
28
+ interface FileActionData {
29
+ /** Unique ID */
30
+ id: string;
31
+ /** Translatable string displayed in the menu */
32
+ displayName: (files: Node[], view: View) => string;
33
+ /** Translatable title for of the action */
34
+ title?: (files: Node[], view: View) => string;
35
+ /** Svg as inline string. <svg><path fill="..." /></svg> */
36
+ iconSvgInline: (files: Node[], view: View) => string;
37
+ /** Condition wether this action is shown or not */
38
+ enabled?: (files: Node[], view: View) => boolean;
39
+ /**
40
+ * Function executed on single file action
41
+ * @return true if the action was executed successfully,
42
+ * false otherwise and null if the action is silent/undefined.
43
+ * @throws Error if the action failed
44
+ */
45
+ exec: (file: Node, view: View, dir: string) => Promise<boolean | null>;
46
+ /**
47
+ * Function executed on multiple files action
48
+ * @return true if the action was executed successfully,
49
+ * false otherwise and null if the action is silent/undefined.
50
+ * @throws Error if the action failed
51
+ */
52
+ execBatch?: (files: Node[], view: View, dir: string) => Promise<(boolean | null)[]>;
53
+ /** This action order in the list */
54
+ order?: number;
55
+ /**
56
+ * This action's parent id in the list.
57
+ * If none found, will be displayed as a top-level action.
58
+ */
59
+ parent?: string;
60
+ /**
61
+ * Make this action the default.
62
+ * If multiple actions are default, the first one
63
+ * will be used. The other ones will be put as first
64
+ * entries in the actions menu iff DefaultType.Hidden is not used.
65
+ * A DefaultType.Hidden action will never be shown
66
+ * in the actions menu even if another action takes
67
+ * its place as default.
68
+ */
69
+ default?: DefaultType;
70
+ /**
71
+ * If true, the renderInline function will be called
72
+ */
73
+ inline?: (file: Node, view: View) => boolean;
74
+ /**
75
+ * If defined, the returned html element will be
76
+ * appended before the actions menu.
77
+ */
78
+ renderInline?: (file: Node, view: View) => Promise<HTMLElement | null>;
79
+ }
80
+ export declare class FileAction {
81
+ private _action;
82
+ constructor(action: FileActionData);
83
+ get id(): string;
84
+ get displayName(): (files: Node[], view: View) => string;
85
+ get title(): ((files: Node[], view: View) => string) | undefined;
86
+ get iconSvgInline(): (files: Node[], view: View) => string;
87
+ get enabled(): ((files: Node[], view: View) => boolean) | undefined;
88
+ get exec(): (file: Node, view: View, dir: string) => Promise<boolean | null>;
89
+ get execBatch(): ((files: Node[], view: View, dir: string) => Promise<(boolean | null)[]>) | undefined;
90
+ get order(): number | undefined;
91
+ get parent(): string | undefined;
92
+ get default(): DefaultType | undefined;
93
+ get inline(): ((file: Node, view: View) => boolean) | undefined;
94
+ get renderInline(): ((file: Node, view: View) => Promise<HTMLElement | null>) | undefined;
95
+ private validateAction;
96
+ }
97
+ export declare const registerFileAction: (action: FileAction) => void;
98
+ export declare const getFileActions: () => FileAction[];
99
+ export {};
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
3
+ *
4
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
5
+ *
6
+ * @license AGPL-3.0-or-later
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU Affero General Public License as
10
+ * published by the Free Software Foundation, either version 3 of the
11
+ * License, or (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU Affero General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Affero General Public License
19
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+ import { Folder } from './files/folder';
23
+ import { View } from './navigation/view';
24
+ export interface HeaderData {
25
+ /** Unique ID */
26
+ id: string;
27
+ /** Order */
28
+ order: number;
29
+ /** Condition wether this header is shown or not */
30
+ enabled?: (folder: Folder, view: View) => boolean;
31
+ /** Executed when file list is initialized */
32
+ render: (el: HTMLElement, folder: Folder, view: View) => void;
33
+ /** Executed when root folder changed */
34
+ updated(folder: Folder, view: View): any;
35
+ }
36
+ export declare class Header {
37
+ private _header;
38
+ constructor(header: HeaderData);
39
+ get id(): string;
40
+ get order(): number;
41
+ get enabled(): ((folder: Folder, view: View) => boolean) | undefined;
42
+ get render(): (el: HTMLElement, folder: Folder, view: View) => void;
43
+ get updated(): (folder: Folder, view: View) => any;
44
+ private validateHeader;
45
+ }
46
+ export declare const registerFileListHeaders: (header: Header) => void;
47
+ export declare const getFileListHeaders: () => Header[];
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
3
+ *
4
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
5
+ *
6
+ * @license AGPL-3.0-or-later
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU Affero General Public License as
10
+ * published by the Free Software Foundation, either version 3 of the
11
+ * License, or (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU Affero General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Affero General Public License
19
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+ import { FileType } from './fileType';
23
+ import { Node } from './node';
24
+ export declare class File extends Node {
25
+ get type(): FileType;
26
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
3
+ *
4
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
5
+ *
6
+ * @license AGPL-3.0-or-later
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU Affero General Public License as
10
+ * published by the Free Software Foundation, either version 3 of the
11
+ * License, or (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU Affero General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Affero General Public License
19
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+ export declare enum FileType {
23
+ Folder = "folder",
24
+ File = "file"
25
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
3
+ *
4
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
5
+ *
6
+ * @license AGPL-3.0-or-later
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU Affero General Public License as
10
+ * published by the Free Software Foundation, either version 3 of the
11
+ * License, or (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU Affero General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Affero General Public License
19
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+ import { FileType } from './fileType';
23
+ import { Node } from './node';
24
+ import { NodeData } from './nodeData';
25
+ export declare class Folder extends Node {
26
+ constructor(data: NodeData);
27
+ get type(): FileType;
28
+ get extension(): string | null;
29
+ get mime(): string;
30
+ }
@@ -0,0 +1,115 @@
1
+ import { Permission } from '../permissions';
2
+ import { FileType } from './fileType';
3
+ import { Attribute, NodeData } from './nodeData';
4
+ export declare enum NodeStatus {
5
+ /** This is a new node and it doesn't exists on the filesystem yet */
6
+ NEW = "new",
7
+ /** This node has failed and is unavailable */
8
+ FAILED = "failed",
9
+ /** This node is currently loading or have an operation in progress */
10
+ LOADING = "loading",
11
+ /** This node is locked and cannot be modified */
12
+ LOCKED = "locked"
13
+ }
14
+ export declare abstract class Node {
15
+ private _data;
16
+ private _attributes;
17
+ private _knownDavService;
18
+ constructor(data: NodeData, davService?: RegExp);
19
+ /**
20
+ * Get the source url to this object
21
+ */
22
+ get source(): string;
23
+ /**
24
+ * Get the encoded source url to this object for requests purposes
25
+ */
26
+ get encodedSource(): string;
27
+ /**
28
+ * Get this object name
29
+ */
30
+ get basename(): string;
31
+ /**
32
+ * Get this object's extension
33
+ */
34
+ get extension(): string | null;
35
+ /**
36
+ * Get the directory path leading to this object
37
+ * Will use the relative path to root if available
38
+ */
39
+ get dirname(): string;
40
+ /**
41
+ * Is it a file or a folder ?
42
+ */
43
+ abstract get type(): FileType;
44
+ /**
45
+ * Get the file mime
46
+ */
47
+ get mime(): string | undefined;
48
+ /**
49
+ * Get the file modification time
50
+ */
51
+ get mtime(): Date | undefined;
52
+ /**
53
+ * Get the file creation time
54
+ */
55
+ get crtime(): Date | undefined;
56
+ /**
57
+ * Get the file size
58
+ */
59
+ get size(): number | undefined;
60
+ /**
61
+ * Get the file attribute
62
+ */
63
+ get attributes(): Attribute;
64
+ /**
65
+ * Get the file permissions
66
+ */
67
+ get permissions(): Permission;
68
+ /**
69
+ * Get the file owner
70
+ */
71
+ get owner(): string | null;
72
+ /**
73
+ * Is this a dav-related ressource ?
74
+ */
75
+ get isDavRessource(): boolean;
76
+ /**
77
+ * Get the dav root of this object
78
+ */
79
+ get root(): string | null;
80
+ /**
81
+ * Get the absolute path of this object relative to the root
82
+ */
83
+ get path(): string;
84
+ /**
85
+ * Get the node id if defined.
86
+ * Will look for the fileid in attributes if undefined.
87
+ */
88
+ get fileid(): number | undefined;
89
+ /**
90
+ * Get the node status.
91
+ */
92
+ get status(): NodeStatus | undefined;
93
+ /**
94
+ * Set the node status.
95
+ */
96
+ set status(status: NodeStatus | undefined);
97
+ /**
98
+ * Move the node to a new destination
99
+ *
100
+ * @param {string} destination the new source.
101
+ * e.g. https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg
102
+ */
103
+ move(destination: string): void;
104
+ /**
105
+ * Rename the node
106
+ * This aliases the move method for easier usage
107
+ *
108
+ * @param basename The new name of the node
109
+ */
110
+ rename(basename: string): void;
111
+ /**
112
+ * Update the mtime if exists.
113
+ */
114
+ private updateMtime;
115
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
3
+ *
4
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
5
+ *
6
+ * @license AGPL-3.0-or-later
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU Affero General Public License as
10
+ * published by the Free Software Foundation, either version 3 of the
11
+ * License, or (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU Affero General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Affero General Public License
19
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+ import { Permission } from '../permissions';
23
+ import { NodeStatus } from './node';
24
+ export interface Attribute {
25
+ [key: string]: any;
26
+ }
27
+ export interface NodeData {
28
+ /** Unique ID */
29
+ id?: number;
30
+ /**
31
+ * URL to the ressource.
32
+ * e.g. https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg
33
+ * or https://domain.com/Photos/picture.jpg
34
+ */
35
+ source: string;
36
+ /** Last modified time */
37
+ mtime?: Date;
38
+ /** Creation time */
39
+ crtime?: Date;
40
+ /** The mime type Optional for folders only */
41
+ mime?: string;
42
+ /** The node size type */
43
+ size?: number;
44
+ /** The node permissions */
45
+ permissions?: Permission;
46
+ /** The owner UID of this node */
47
+ owner: string | null;
48
+ /** The node attributes */
49
+ attributes?: Attribute;
50
+ /**
51
+ * The absolute root of the home relative to the service.
52
+ * It is highly recommended to provide that information.
53
+ * e.g. /files/emma
54
+ */
55
+ root?: string;
56
+ /** The node status */
57
+ status?: NodeStatus;
58
+ }
59
+ /**
60
+ * Check if a node source is from a specific DAV service
61
+ *
62
+ * @param source The source to check
63
+ * @param davService Pattern to check if source is DAV ressource
64
+ */
65
+ export declare const isDavRessource: (source: string, davService: RegExp) => boolean;
66
+ /**
67
+ * Validate Node construct data
68
+ *
69
+ * @param data The node data
70
+ * @param davService Pattern to check if source is DAV ressource
71
+ */
72
+ export declare const validateData: (data: NodeData, davService: RegExp) => void;
@@ -23,7 +23,21 @@
23
23
  /**
24
24
  * Format a file size in a human-like format. e.g. 42GB
25
25
  *
26
+ * The default for Nextcloud is like Windows using binary sizes but showing decimal units,
27
+ * meaning 1024 bytes will show as 1KB instead of 1KiB or like on Apple 1.02 KB
28
+ *
26
29
  * @param size in bytes
27
30
  * @param skipSmallSizes avoid rendering tiny sizes and return '< 1 KB' instead
31
+ * @param binaryPrefixes True if size binary prefixes like `KiB` should be used as per IEC 80000-13
32
+ * @param base1000 Set to true to use base 1000 as per SI or used by Apple (default is base 1024 like Linux or Windows)
33
+ */
34
+ export declare function formatFileSize(size: number | string, skipSmallSizes?: boolean, binaryPrefixes?: boolean, base1000?: boolean): string;
35
+ /**
36
+ * Returns a file size in bytes from a humanly readable string
37
+ * Note: `b` and `B` are both parsed as bytes and not as bit or byte.
38
+ *
39
+ * @param {string} value file size in human-readable format
40
+ * @param {boolean} forceBinary for backwards compatibility this allows values to be base 2 (so 2KB means 2048 bytes instead of 2000 bytes)
41
+ * @return {number} or null if string could not be parsed
28
42
  */
29
- export declare function formatFileSize(size: number | string, skipSmallSizes?: boolean): string;
43
+ export declare function parseFileSize(value: string, forceBinary?: boolean): number | null;