diff --git a/.eslintrc.js b/.eslintrc.js index cea14615959fef..de3e49ea36790d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -82,6 +82,7 @@ module.exports = { 'chunk', 'clamp', 'concat', + 'countBy', 'defaults', 'defaultTo', 'differenceWith', diff --git a/bin/plugin/commands/changelog.js b/bin/plugin/commands/changelog.js index bd5b7c1e611766..f4893a19d008e2 100644 --- a/bin/plugin/commands/changelog.js +++ b/bin/plugin/commands/changelog.js @@ -2,7 +2,6 @@ * External dependencies */ const { - countBy, groupBy, escapeRegExp, uniq, @@ -309,7 +308,17 @@ function getIssueFeature( issue ) { // 1. Prefer explicit mapping of label to feature. if ( featureCandidates.length ) { // Get occurances of the feature labels. - const featureCounts = countBy( featureCandidates ); + const featureCounts = featureCandidates.reduce( + /** + * @param {Record} acc Accumulator + * @param {string} feature Feature label + */ + ( acc, feature ) => ( { + ...acc, + [ feature ]: ( acc[ feature ] || 0 ) + 1, + } ), + {} + ); // Check which matching label occurs most often. const rankedFeatures = Object.keys( featureCounts ).sort( diff --git a/packages/editor/src/components/document-outline/index.js b/packages/editor/src/components/document-outline/index.js index bf8c4ba234c366..49d19e360edc85 100644 --- a/packages/editor/src/components/document-outline/index.js +++ b/packages/editor/src/components/document-outline/index.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { countBy, flatMap, get } from 'lodash'; - /** * WordPress dependencies */ @@ -50,7 +45,7 @@ const multipleH1Headings = [ * @return {Array} An array of heading blocks enhanced with the properties described above. */ const computeOutlineHeadings = ( blocks = [] ) => { - return flatMap( blocks, ( block = {} ) => { + return blocks.flatMap( ( block = {} ) => { if ( block.name === 'core/heading' ) { return { ...block, @@ -83,7 +78,13 @@ export const DocumentOutline = ( { // Not great but it's the simplest way to locate the title right now. const titleNode = document.querySelector( '.editor-post-title__input' ); const hasTitle = isTitleSupported && title && titleNode; - const countByLevel = countBy( headings, 'level' ); + const countByLevel = headings.reduce( + ( acc, heading ) => ( { + ...acc, + [ heading.level ]: ( acc[ heading.level ] || 0 ) + 1, + } ), + {} + ); const hasMultipleH1 = countByLevel[ 1 ] > 1; return ( @@ -155,7 +156,7 @@ export default compose( return { title: getEditedPostAttribute( 'title' ), blocks: getBlocks(), - isTitleSupported: get( postType, [ 'supports', 'title' ], false ), + isTitleSupported: postType?.supports?.title ?? false, }; } ) )( DocumentOutline );