diff --git a/package.json b/package.json index ce38dcb..d051e33 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,6 @@ "identity-obj-proxy": "3.0.0", "intersection-observer": "0.7.0", "js-cookie": "^2.2.1", - "lodash": "^4.17.21", "mini-css-extract-plugin": "2.5.2", "newrelic": "^6.13.0", "node-sass": "6.0.1", diff --git a/src/render.js b/src/render.js index 3ac3160..ac4d636 100644 --- a/src/render.js +++ b/src/render.js @@ -12,7 +12,8 @@ import { } from './universal/service/RenderService'; import Component from './universal/model/Component'; import logger from './universal/utils/logger'; -import omit from 'lodash/omit'; +import omit from './universal/utils/lodash/omit'; + import { getPreviewFile } from './universal/utils/previewHelper'; const appConfig = require('__APP_CONFIG__'); diff --git a/src/universal/model/Renderer.js b/src/universal/model/Renderer.js index bc98f3f..dd484e8 100644 --- a/src/universal/model/Renderer.js +++ b/src/universal/model/Renderer.js @@ -1,6 +1,6 @@ -import omit from 'lodash/omit'; import { isPreview, renderComponent, renderLinksAndScripts } from '../service/RenderService'; import { BLACKLIST_OUTPUT } from '../utils/constants'; +import omit from '../utils/lodash/omit'; export default class Renderer { constructor(component, context) { diff --git a/src/universal/partials/Welcome/PartialCards.js b/src/universal/partials/Welcome/PartialCards.js index b679102..8fb2946 100644 --- a/src/universal/partials/Welcome/PartialCards.js +++ b/src/universal/partials/Welcome/PartialCards.js @@ -1,9 +1,10 @@ import React from 'react'; -import groupBy from 'lodash/groupBy'; import ReactDOMServer from 'react-dom/server'; import { ServerStyleSheet } from 'styled-components'; import partials from './partials'; +import groupBy from '../../utils/lodash/groupBy'; + const STATUS_COLOR = { live: '#8dc63f', dev: '#FF6000', diff --git a/src/universal/utils/lodash/groupBy.js b/src/universal/utils/lodash/groupBy.js new file mode 100644 index 0000000..f29a300 --- /dev/null +++ b/src/universal/utils/lodash/groupBy.js @@ -0,0 +1,22 @@ +function groupBy(arr, predicate) { + return arr.reduce((obj, item) => { + // Check if the predicate is a function to run on the item or a property of it + const key = predicate + ? typeof predicate === 'function' + ? predicate(item) + : item[predicate] + : item; + + if (obj && !obj.hasOwnProperty(key)) { + obj[key] = []; + } + + // Push the value to the object + obj[key].push(item); + + // Return the object to the next item in the loop + return obj; + }, {}); +} + +export default groupBy; diff --git a/src/universal/utils/lodash/omit.js b/src/universal/utils/lodash/omit.js new file mode 100644 index 0000000..3894d9e --- /dev/null +++ b/src/universal/utils/lodash/omit.js @@ -0,0 +1,20 @@ +const keyControl = (keys, key) => { + for (const item in keys) { + if (Array.isArray(keys[item])) { + const arrayStatus = keyControl(keys[item], key); + if (!arrayStatus) { + return false; + } + } + if (keys[item] === key) { + return false; + } + } + return true; +}; + +function omit(obj, ...keys) { + return Object.fromEntries(Object.entries(obj).filter(([k]) => keyControl(keys, k))); +} + +export default omit;