Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Remove lodash.set (#1336)
sarayourfriendbd84bdb36579
diff --git a/package.json b/package.jsonindex 1c60faba8..397323ef0 100644--- a/package.json+++ b/package.json@@ -84,7 +84,6 @@"lodash.clonedeep": "^4.5.0","lodash.debounce": "^4.0.8","lodash.isempty": "^4.4.0",- "lodash.set": "^4.3.2","lodash.sortby": "^4.7.0","lodash.throttle": "^4.1.1","node-html-parser": "^5.3.3",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 00078bc63..3c931c4ef 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -67,7 +67,6 @@ specifiers:lodash.clonedeep: ^4.5.0lodash.debounce: ^4.0.8lodash.isempty: ^4.4.0- lodash.set: ^4.3.2lodash.sortby: ^4.7.0lodash.throttle: ^4.1.1module-alias: ^2.2.2@@ -125,7 +124,6 @@ dependencies:lodash.clonedeep: 4.5.0lodash.debounce: 4.0.8lodash.isempty: 4.4.0- lodash.set: 4.3.2lodash.sortby: 4.7.0lodash.throttle: 4.1.1node-html-parser: 5.3.3@@ -12722,10 +12720,6 @@ packages:resolution: {integrity: sha512-GK3g5RPZWTRSeLSpgP8Xhra+pnjBC56q9FZYe1d5RN3TJ35dbkGy3YqBSMbyCrlbi+CM9Z3Jk5yTL7RCsqboyQ==}dev: false- /lodash.set/4.3.2:- resolution: {integrity: sha1-2HV7HagH3eJIFrDWqEvqGnYjCyM=}- dev: false-/lodash.sortby/4.7.0:resolution: {integrity: sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=}dev: falsediff --git a/src/locales/scripts/jed1x-json-to-json.js b/src/locales/scripts/jed1x-json-to-json.jsindex fceb24491..d621c6a25 100644--- a/src/locales/scripts/jed1x-json-to-json.js+++ b/src/locales/scripts/jed1x-json-to-json.js@@ -1,4 +1,4 @@-const set = require('lodash.set')+const { setToValue } = require('./utils')/*** Convert a Jed1x-Translate object to a nested JSON object.@@ -37,7 +37,7 @@ function jed1xJsonToJson(jed1xObject) {const cleanedKey = key.slice(0, key.indexOf(SPLIT_CHAR))if (value.length > 0) {const cleanedValue = value.length === 1 ? value[0] : value.join('|')- return set(result, cleanedKey, cleanedValue)+ return setToValue(result, cleanedKey, cleanedValue)}})return resultdiff --git a/src/locales/scripts/ngx-json-to-json.js b/src/locales/scripts/ngx-json-to-json.jsindex 6718c10b7..af4e9bf56 100644--- a/src/locales/scripts/ngx-json-to-json.js+++ b/src/locales/scripts/ngx-json-to-json.js@@ -1,4 +1,4 @@-const set = require('lodash.set')+const { setToValue } = require('./utils')/*** Convert an NGX-Translate object to a nested JSON object@@ -26,7 +26,7 @@ const set = require('lodash.set')function ngxJsonToJson(ngxObject) {const result = {}Object.entries(ngxObject).forEach(- ([key, value]) => value && set(result, key, value)+ ([key, value]) => value && setToValue(result, key, value))return result}diff --git a/src/locales/scripts/utils.js b/src/locales/scripts/utils.jsnew file mode 100644index 000000000..839ebcf32--- /dev/null+++ b/src/locales/scripts/utils.js@@ -0,0 +1,21 @@+/**+ * Mutates an object at the path with the value. If the path+ * does not exist, it is created by nesting objects along the+ * path segments.+ *+ * @see {@link https://stackoverflow.com/a/20240290|Stack Overflow}+ *+ * @param {any} obj - The object to mutate.+ * @param {string} path - The dot delimited path on the object to mutate.+ * @param {unknown} value - The value to set at the path.+ */+exports.setToValue = function setValue(obj, path, value) {+ var a = path.split('.')+ var o = obj+ while (a.length - 1) {+ var n = a.shift()+ if (!(n in o)) o[n] = {}+ o = o[n]+ }+ o[a[0]] = value+}