* Remove fromEntriesPolyfill

* Remove further instances of fromEntriesPolyfill
This commit is contained in:
Thomas Roberts 2022-03-04 14:42:16 +00:00 committed by GitHub
parent 9157930349
commit db1989aefb
4 changed files with 3 additions and 25 deletions

View File

@ -28,10 +28,7 @@ import type {
CartResponseCouponItem, CartResponseCouponItem,
CartResponseCoupons, CartResponseCoupons,
} from '@woocommerce/types'; } from '@woocommerce/types';
import { import { emptyHiddenAddressFields } from '@woocommerce/base-utils';
emptyHiddenAddressFields,
fromEntriesPolyfill,
} from '@woocommerce/base-utils';
/** /**
* Internal dependencies * Internal dependencies
@ -85,7 +82,7 @@ const defaultCartTotals: CartResponseTotals = {
const decodeValues = ( const decodeValues = (
object: Record< string, unknown > object: Record< string, unknown >
): Record< string, unknown > => ): Record< string, unknown > =>
fromEntriesPolyfill( Object.fromEntries(
Object.entries( object ).map( ( [ key, value ] ) => [ Object.entries( object ).map( ( [ key, value ] ) => [
key, key,
decodeEntities( value ), decodeEntities( value ),

View File

@ -1,8 +1,3 @@
/**
* Internal dependencies
*/
import { fromEntriesPolyfill } from './from-entries-polyfill';
/** /**
* Get an array of selected shipping rates keyed by Package ID. * Get an array of selected shipping rates keyed by Package ID.
* *
@ -10,7 +5,7 @@ import { fromEntriesPolyfill } from './from-entries-polyfill';
* @return {Object} Object containing the package IDs and selected rates in the format: { [packageId:string]: rateId:string } * @return {Object} Object containing the package IDs and selected rates in the format: { [packageId:string]: rateId:string }
*/ */
export const deriveSelectedShippingRates = ( shippingRates ) => export const deriveSelectedShippingRates = ( shippingRates ) =>
fromEntriesPolyfill( Object.fromEntries(
shippingRates.map( shippingRates.map(
( { package_id: packageId, shipping_rates: packageRates } ) => [ ( { package_id: packageId, shipping_rates: packageRates } ) => [
packageId, packageId,

View File

@ -1,13 +0,0 @@
/**
* A polyfill for Object.fromEntries function.
*
* @param {Array<[string, unknown]>} array Array to be turned back to object
* @return {Record< string, unknown >} the newly created object
*/
export const fromEntriesPolyfill = (
array: Array< [ string, unknown ] >
): Record< string, unknown > =>
array.reduce< Record< string, unknown > >( ( obj, [ key, val ] ) => {
obj[ key ] = val;
return obj;
}, {} );

View File

@ -6,5 +6,4 @@ export * from './render-frontend';
export * from './get-valid-block-attributes'; export * from './get-valid-block-attributes';
export * from './product-data'; export * from './product-data';
export * from './derive-selected-shipping-rates'; export * from './derive-selected-shipping-rates';
export * from './from-entries-polyfill';
export * from './get-icons-from-payment-methods'; export * from './get-icons-from-payment-methods';