Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not /*! ?

Copy link
Contributor Author

@ShGKme ShGKme Jun 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** is problematic because it has a special meaning - a JSDoc comment.

/* is a general comment and works without any problems as far as I know.

It is a default comment syntax, so it works automatically with tooling.
For example, JetBrains IDEs add/fix/check copyright comments out of the box.
VSCode has many extensions, but some I checked also use a general comment by default.

/*! isn't some standard, requiring manual work. Like adding our own ESLint rule for that. And adapting to other languages. We don't use <!--! in HTML, for example.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes its more like most tools I know specially handle *! as legal comment and e.g. preserve it during minification.

* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/

const { recommendedLibrary } = require('@nextcloud/eslint-config')

module.exports = [...recommendedLibrary]
15 changes: 9 additions & 6 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/**
/*
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import StorageBuilder from './storagebuilder'
import ScopedStorage from './scopedstorage'

import ScopedStorage from './scopedstorage.ts'
import StorageBuilder from './storagebuilder.ts'

/**
* Get the storage builder for an app
*
* @param appId App ID to scope storage
*/
export function getBuilder(appId: string): StorageBuilder {
Expand All @@ -15,12 +17,13 @@ export function getBuilder(appId: string): StorageBuilder {

/**
* Clear values from storage
*
* @param storage The storage to clear
* @param pred Callback to check if value should be cleared
*/
function clearStorage(storage: Storage, pred?: (value: string) => boolean): void {
Object.keys(storage)
.filter(k => pred ? pred(k) : true)
.filter((k) => pred ? pred(k) : true)
.map(storage.removeItem.bind(storage))
}

Expand All @@ -32,7 +35,7 @@ export function clearAll(): void {
window.sessionStorage,
window.localStorage,
]
storages.map(s => clearStorage(s))
storages.map((s) => clearStorage(s))
}

/**
Expand All @@ -43,5 +46,5 @@ export function clearNonPersistent(): void {
window.sessionStorage,
window.localStorage,
]
storages.map(s => clearStorage(s, k => !k.startsWith(ScopedStorage.GLOBAL_SCOPE_PERSISTENT)))
storages.map((s) => clearStorage(s, (k) => !k.startsWith(ScopedStorage.GLOBAL_SCOPE_PERSISTENT)))
}
9 changes: 4 additions & 5 deletions lib/scopedstorage.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
/*
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import NextcloudStorage from './storage'

export default class ScopedStorage implements NextcloudStorage {
import type NextcloudStorage from './storage.ts'

export default class ScopedStorage implements NextcloudStorage {
public static GLOBAL_SCOPE_VOLATILE = 'nextcloud_vol'
public static GLOBAL_SCOPE_PERSISTENT = 'nextcloud_per'
private scope: string
Expand Down Expand Up @@ -34,8 +34,7 @@ export default class ScopedStorage implements NextcloudStorage {

clear(): void {
Object.keys(this.wrapped)
.filter(key => key.startsWith(this.scope))
.filter((key) => key.startsWith(this.scope))
.map(this.wrapped.removeItem.bind(this.wrapped))
}

}
11 changes: 6 additions & 5 deletions lib/storage.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/**
/*
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/

export default interface Storage {
setItem(key: string, value: string): void
getItem(key: string): string | null
removeItem(key: string): void
clear(): void
setItem(key: string, value: string): void
getItem(key: string): string | null
removeItem(key: string): void
clear(): void
}
10 changes: 5 additions & 5 deletions lib/storagebuilder.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/**
/*
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import Storage from './storage'
import ScopedStorage from './scopedstorage'

export default class StorageBuilder {
import type Storage from './storage.ts'

import ScopedStorage from './scopedstorage.ts'

export default class StorageBuilder {
private appId: string
private persisted = false
private clearedOnLogout = false
Expand All @@ -32,5 +33,4 @@ export default class StorageBuilder {
!this.clearedOnLogout,
)
}

}
Loading