11'use strict' ;
22
3- const _ = require ( 'lodash' ) ;
43const URL = require ( 'url' )
4+ const utils = require ( '../3p/utils' ) ;
55
66const { resourceHintAllowedTypes, addResourceHint, defaultResourceHintState} = require ( '../lib/resourceHints' ) ;
77
@@ -24,30 +24,32 @@ const fontProviders = {
2424 var collection = [ ] ,
2525 familyHash = { } ;
2626
27- _ . each ( fonts , function fontsIterator ( font ) {
27+ Object . keys ( fonts ) . forEach ( function fontsIterator ( key ) {
28+ const font = fonts [ key ] ;
2829 var split = font . split ( '_' ) ,
2930 familyKey = split [ 1 ] , // Eg: Open+Sans
3031 weights = split [ 2 ] ; // Eg: 400,700italic
3132
32- if ( _ . isEmpty ( familyKey ) ) {
33+ if ( utils . isEmpty ( familyKey ) ) {
3334 return ;
3435 }
3536
36- if ( _ . isUndefined ( weights ) ) {
37+ if ( utils . isUndefined ( weights ) ) {
3738 weights = '' ;
3839 }
3940
40- if ( ! _ . isArray ( familyHash [ familyKey ] ) ) {
41+ if ( ! utils . isArray ( familyHash [ familyKey ] ) ) {
4142 familyHash [ familyKey ] = [ ] ;
4243 }
4344
4445 weights = weights . split ( ',' ) ;
4546
4647 familyHash [ familyKey ] . push ( weights ) ;
47- familyHash [ familyKey ] = _ . uniq ( _ . flatten ( familyHash [ familyKey ] ) ) ;
48+ familyHash [ familyKey ] = [ ... new Set ( familyHash [ familyKey ] . flat ( ) ) ]
4849 } ) ;
4950
50- _ . each ( familyHash , function fontHashIterator ( weights , family ) {
51+ Object . keys ( familyHash ) . forEach ( function fontHashIterator ( family ) {
52+ const weights = familyHash [ family ] ;
5153 collection . push ( family + ':' + weights . join ( ',' ) ) ;
5254 } ) ;
5355
@@ -111,14 +113,14 @@ const fontProviders = {
111113module . exports = function ( format , themeSettings , handlebars , options ) {
112114
113115 const collectedFonts = { } ;
114- _ . each ( themeSettings , function ( value , key ) {
116+ Object . keys ( themeSettings ) . forEach ( function ( key ) {
115117 //check that -font is on end of string but not start of string
116118 const fontKeySuffix = '-font' ;
117119 if ( ! key . endsWith ( fontKeySuffix ) ) {
118120 return ;
119121 }
120122
121- const splits = value . split ( '_' ) ;
123+ const splits = themeSettings [ key ] . split ( '_' ) ;
122124 const provider = splits [ 0 ] ;
123125
124126 if ( typeof fontProviders [ provider ] === 'undefined' ) {
@@ -129,34 +131,36 @@ module.exports = function (format, themeSettings, handlebars, options) {
129131 collectedFonts [ provider ] = [ ] ;
130132 }
131133
132- collectedFonts [ provider ] . push ( value ) ;
134+ collectedFonts [ provider ] . push ( themeSettings [ key ] ) ;
133135 } ) ;
134136
135137 // Parse font strings based on provider
136- const parsedFonts = _ . mapValues ( collectedFonts , function ( value , key ) {
137- return fontProviders [ key ] . parser ( value ) ;
138+ const parsedFonts = { } ;
139+ Object . keys ( collectedFonts ) . forEach ( function ( key ) {
140+ parsedFonts [ key ] = fontProviders [ key ] . parser ( collectedFonts [ key ] ) ;
138141 } ) ;
139142
140143 // Format output based on requested format
141144 switch ( format ) {
142145 case 'linkElements' :
143-
144- const formattedFonts = _ . mapValues ( parsedFonts , function ( value , key ) {
145- fontProviders [ key ] . generateResourceHints ( options . globals , value , options . fontDisplay ) ;
146- return fontProviders [ key ] . buildLink ( value , options . fontDisplay ) ;
146+ const formattedFonts = { } ;
147+ Object . keys ( parsedFonts ) . forEach ( function ( key ) {
148+ fontProviders [ key ] . generateResourceHints ( options . globals , parsedFonts [ key ] , options . fontDisplay ) ;
149+ formattedFonts [ key ] = fontProviders [ key ] . buildLink ( parsedFonts [ key ] , options . fontDisplay ) ;
147150 } ) ;
148- return new handlebars . SafeString ( _ . values ( formattedFonts ) . join ( '' ) ) ;
151+ return new handlebars . SafeString ( Object . values ( formattedFonts ) . join ( '' ) ) ;
149152
150153 case 'webFontLoaderConfig' :
151154 // Build configs
152- const configs = _ . mapValues ( parsedFonts , function ( value , key ) {
153- return fontProviders [ key ] . buildFontLoaderConfig ( value ) ;
155+ const configs = { } ;
156+ Object . keys ( parsedFonts ) . forEach ( function ( key ) {
157+ configs [ key ] = fontProviders [ key ] . buildFontLoaderConfig ( parsedFonts [ key ] ) ;
154158 } ) ;
155159
156160 // Merge them
157161 const fontLoaderConfig = { } ;
158- _ . each ( configs , function ( config ) {
159- return Object . assign ( fontLoaderConfig , config ) ;
162+ Object . values ( configs ) . forEach ( ( config ) => {
163+ Object . assign ( fontLoaderConfig , config ) ;
160164 } ) ;
161165 return fontLoaderConfig ;
162166
0 commit comments