From efcd80fb4b69e0a77f2df7c3d7da1aa0ae88a3e9 Mon Sep 17 00:00:00 2001 From: behmaram Date: Sun, 10 Jan 2021 12:57:27 +0330 Subject: [PATCH] add: addToTags --- resources/js/Global/utils/common/addToTags.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 resources/js/Global/utils/common/addToTags.js diff --git a/resources/js/Global/utils/common/addToTags.js b/resources/js/Global/utils/common/addToTags.js new file mode 100644 index 0000000..4d5ee4a --- /dev/null +++ b/resources/js/Global/utils/common/addToTags.js @@ -0,0 +1,12 @@ +export const addToTags = (data, tagItems) => { + if (!data.tags || typeof data.tags !== 'object') { + data.tags = []; + } + for (const tagItem of tagItems) { + if (data[tagItem] && !data.tags.includes(data[tagItem])) { + data.tags.push(data[tagItem]); + } + } + + return data; +};