Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Remove unused utils (#3239)

Olga Bulat02a4f68481f2
diff --git a/frontend/src/utils/local.ts b/frontend/src/utils/local.ts
deleted file mode 100644
index 8a19a0c69..000000000
--- a/frontend/src/utils/local.ts
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Small wrapper for localstorage to protect against SSR and permissions
- */
-
-import { warn } from "~/utils/console"
-
-const localStorageExists = () => process.client && window.localStorage !== null
-
-const tryUse = <R>(fn: () => R, def: R) => {
- try {
- return localStorageExists() ? fn() : def
- } catch (e) {
- warn("`localStorage` access denied", e)
- return def
- }
-}
-
-const local: typeof localStorage = {
- get length() {
- return tryUse(() => localStorage.length, 0)
- },
- getItem(key: string) {
- return tryUse(() => localStorage.getItem(key), null)
- },
- setItem(key: string, value: string) {
- tryUse(() => localStorage.setItem(key, value), undefined)
- },
- clear() {
- tryUse(() => localStorage.clear(), undefined)
- },
- removeItem(key) {
- tryUse(() => localStorage.removeItem(key), undefined)
- },
- key(index) {
- return tryUse(() => localStorage.key(index), null)
- },
-}
-
-export default local
diff --git a/frontend/src/utils/prop-validators.ts b/frontend/src/utils/prop-validators.ts
deleted file mode 100644
index e907fe549..000000000
--- a/frontend/src/utils/prop-validators.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { SupportedSearchType, supportedSearchTypes } from "~/constants/media"
-
-/**
- * Validates the search types that have supported API endpoints.
- * This means that ALL_MEDIA is invalid because it is basically
- * a combination of all other supported API media types.
- * Any future search type that is not fully supported (video, 3d)
- * will also be invalid.
- */
-export const isValidSearchType = (
- value: string
-): value is SupportedSearchType => {
- return supportedSearchTypes.includes(value as SupportedSearchType)
-}
diff --git a/frontend/src/utils/url-params.ts b/frontend/src/utils/url-params.ts
deleted file mode 100644
index 71de36fa2..000000000
--- a/frontend/src/utils/url-params.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * Gets the value of the query parameter from a URL. If the key contains
- * multiple values, they are joined using commas.
- *
- * @param key - the name of the parameter for which values are to be extracted
- * @param url - the URL containing query parameters
- */
-export const getParameterByName = (key: string, url: string): string => {
- const name = key.replace(/[[\]]/g, "\\$&")
- const regex = new RegExp(`(${name})=([^&]*)+&*`, "g")
-
- const parameterValues = []
- let regexResults = regex.exec(url)
-
- while (regexResults) {
- const value = decodeURIComponent(regexResults[2].replace(/\+/g, " "))
- parameterValues.push(value)
-
- regexResults = regex.exec(url)
- }
-
- return parameterValues.join(",")
-}
diff --git a/frontend/test/unit/specs/utils/get-parameter-by-name.spec.js b/frontend/test/unit/specs/utils/get-parameter-by-name.spec.js
deleted file mode 100644
index ed5da9278..000000000
--- a/frontend/test/unit/specs/utils/get-parameter-by-name.spec.js
+++ /dev/null
@@ -1,31 +0,0 @@
-import { getParameterByName } from "~/utils/url-params"
-
-describe("getParameterByName", () => {
- const queryStr = "?q=nature&provider=flickr&li=by&lt="
-
- it('finds "q" key', () => {
- expect(getParameterByName("q", queryStr)).toBe("nature")
- })
-
- it('finds "provider" key', () => {
- expect(getParameterByName("provider", queryStr)).toBe("flickr")
- })
-
- it('finds "li" key', () => {
- expect(getParameterByName("li", queryStr)).toBe("by")
- })
-
- it('finds "lt" to be empty', () => {
- expect(getParameterByName("lt", queryStr)).toBe("")
- })
-
- it('finds "lt"', () => {
- const query = `${queryStr}commercial`
- expect(getParameterByName("lt", query)).toBe("commercial")
- })
-
- it('finds multiple "lt" parameter values', () => {
- const query = `${queryStr}commercial&lt=modification`
- expect(getParameterByName("lt", query)).toBe("commercial,modification")
- })
-})