@@ -21,11 +21,6 @@ const getInnermostProperty = (propsList, property) => {
21
21
return null ;
22
22
} ;
23
23
24
- const getAnyTrueFromPropsList = ( propsList , checkedTag ) =>
25
- propsList . reduce ( ( accumulator , currentPropList ) =>
26
- currentPropList [ checkedTag ] ? true : accumulator
27
- ) ;
28
-
29
24
const getTitleFromPropsList = propsList => {
30
25
let innermostTitle = getInnermostProperty ( propsList , TAG_NAMES . TITLE ) ;
31
26
const innermostTemplate = getInnermostProperty ( propsList , HELMET_PROPS . TITLE_TEMPLATE ) ;
@@ -176,23 +171,64 @@ const getTagsFromPropsList = (tagName, primaryAttributes, propsList) => {
176
171
. reverse ( ) ;
177
172
} ;
178
173
179
- // helper to inspect for matching props on components
180
- export const checkIfPropsMatch = ( props , toMatch ) => {
181
- const pairs = Object . entries ( props ) ;
182
- for ( let i = 0 ; i < pairs . length ; i += 1 ) {
183
- const [ propName , propVal ] = pairs [ i ] ;
184
- if ( toMatch [ propName ] ) {
185
- // e.g. if rel exists in the list of allowed props
186
- const propWeAreCheckingOut = toMatch [ propName ] ; // e.g. [amphtml, alternate, etc]
187
- if ( propWeAreCheckingOut . includes ( propVal ) ) {
188
- return true ;
189
- }
174
+ const getAnyTrueFromPropsList = ( propsList , checkedTag ) =>
175
+ propsList . reduce ( ( accumulator , currentPropList ) =>
176
+ currentPropList [ checkedTag ] ? true : accumulator
177
+ ) ;
178
+
179
+ const reducePropsToState = propsList => ( {
180
+ baseTag : getBaseTagFromPropsList ( [ TAG_PROPERTIES . HREF ] , propsList ) ,
181
+ bodyAttributes : getAttributesFromPropsList ( ATTRIBUTE_NAMES . BODY , propsList ) ,
182
+ defer : getInnermostProperty ( propsList , HELMET_PROPS . DEFER ) ,
183
+ encode : getInnermostProperty ( propsList , HELMET_PROPS . ENCODE_SPECIAL_CHARACTERS ) ,
184
+ htmlAttributes : getAttributesFromPropsList ( ATTRIBUTE_NAMES . HTML , propsList ) ,
185
+ linkTags : getTagsFromPropsList (
186
+ TAG_NAMES . LINK ,
187
+ [ TAG_PROPERTIES . REL , TAG_PROPERTIES . HREF ] ,
188
+ propsList
189
+ ) ,
190
+ metaTags : getTagsFromPropsList (
191
+ TAG_NAMES . META ,
192
+ [
193
+ TAG_PROPERTIES . NAME ,
194
+ TAG_PROPERTIES . CHARSET ,
195
+ TAG_PROPERTIES . HTTPEQUIV ,
196
+ TAG_PROPERTIES . PROPERTY ,
197
+ TAG_PROPERTIES . ITEM_PROP ,
198
+ ] ,
199
+ propsList
200
+ ) ,
201
+ noscriptTags : getTagsFromPropsList ( TAG_NAMES . NOSCRIPT , [ TAG_PROPERTIES . INNER_HTML ] , propsList ) ,
202
+ onChangeClientState : getOnChangeClientState ( propsList ) ,
203
+ scriptTags : getTagsFromPropsList (
204
+ TAG_NAMES . SCRIPT ,
205
+ [ TAG_PROPERTIES . SRC , TAG_PROPERTIES . INNER_HTML ] ,
206
+ propsList
207
+ ) ,
208
+ styleTags : getTagsFromPropsList ( TAG_NAMES . STYLE , [ TAG_PROPERTIES . CSS_TEXT ] , propsList ) ,
209
+ title : getTitleFromPropsList ( propsList ) ,
210
+ titleAttributes : getAttributesFromPropsList ( ATTRIBUTE_NAMES . TITLE , propsList ) ,
211
+ prioritizeSeoTags :
212
+ propsList . prioritizeSeoTags &&
213
+ getAnyTrueFromPropsList ( propsList , HELMET_PROPS . PRIORITIZE_SEO_TAGS ) ,
214
+ } ) ;
215
+
216
+ export const flattenArray = possibleArray =>
217
+ Array . isArray ( possibleArray ) ? possibleArray . join ( '' ) : possibleArray ;
218
+
219
+ export { reducePropsToState } ;
220
+
221
+ const checkIfPropsMatch = ( props , toMatch ) => {
222
+ const keys = Object . keys ( props ) ;
223
+ for ( let i = 0 ; i < keys . length ; i += 1 ) {
224
+ // e.g. if rel exists in the list of allowed props [amphtml, alternate, etc]
225
+ if ( toMatch [ keys [ i ] ] && toMatch [ keys [ i ] ] . includes ( props [ keys [ i ] ] ) ) {
226
+ return true ;
190
227
}
191
228
}
192
229
return false ;
193
230
} ;
194
231
195
- // re-usable fn to prioritize tags by matching props
196
232
export const prioritizer = ( elementsList , propsToMatch ) => {
197
233
if ( Array . isArray ( elementsList ) ) {
198
234
return elementsList . reduce (
@@ -209,45 +245,3 @@ export const prioritizer = (elementsList, propsToMatch) => {
209
245
}
210
246
return { default : elementsList } ;
211
247
} ;
212
-
213
- const reducePropsToState = propsList => {
214
- return {
215
- baseTag : getBaseTagFromPropsList ( [ TAG_PROPERTIES . HREF ] , propsList ) ,
216
- bodyAttributes : getAttributesFromPropsList ( ATTRIBUTE_NAMES . BODY , propsList ) ,
217
- defer : getInnermostProperty ( propsList , HELMET_PROPS . DEFER ) ,
218
- encode : getInnermostProperty ( propsList , HELMET_PROPS . ENCODE_SPECIAL_CHARACTERS ) ,
219
- htmlAttributes : getAttributesFromPropsList ( ATTRIBUTE_NAMES . HTML , propsList ) ,
220
- linkTags : getTagsFromPropsList (
221
- TAG_NAMES . LINK ,
222
- [ TAG_PROPERTIES . REL , TAG_PROPERTIES . HREF ] ,
223
- propsList
224
- ) ,
225
- metaTags : getTagsFromPropsList (
226
- TAG_NAMES . META ,
227
- [
228
- TAG_PROPERTIES . NAME ,
229
- TAG_PROPERTIES . CHARSET ,
230
- TAG_PROPERTIES . HTTPEQUIV ,
231
- TAG_PROPERTIES . PROPERTY ,
232
- TAG_PROPERTIES . ITEM_PROP ,
233
- ] ,
234
- propsList
235
- ) ,
236
- noscriptTags : getTagsFromPropsList ( TAG_NAMES . NOSCRIPT , [ TAG_PROPERTIES . INNER_HTML ] , propsList ) ,
237
- onChangeClientState : getOnChangeClientState ( propsList ) ,
238
- scriptTags : getTagsFromPropsList (
239
- TAG_NAMES . SCRIPT ,
240
- [ TAG_PROPERTIES . SRC , TAG_PROPERTIES . INNER_HTML ] ,
241
- propsList
242
- ) ,
243
- styleTags : getTagsFromPropsList ( TAG_NAMES . STYLE , [ TAG_PROPERTIES . CSS_TEXT ] , propsList ) ,
244
- title : getTitleFromPropsList ( propsList ) ,
245
- titleAttributes : getAttributesFromPropsList ( ATTRIBUTE_NAMES . TITLE , propsList ) ,
246
- prioritizeSeoTags : getAnyTrueFromPropsList ( propsList , HELMET_PROPS . PRIORITIZE_SEO_TAGS ) ,
247
- } ;
248
- } ;
249
-
250
- export const flattenArray = possibleArray =>
251
- Array . isArray ( possibleArray ) ? possibleArray . join ( '' ) : possibleArray ;
252
-
253
- export { reducePropsToState } ;
0 commit comments